muted.c File Reference

Mute Daemon. More...

#include "asterisk/autoconfig.h"
#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>

Include dependency graph for muted.c:

Go to the source code of this file.

Data Structures

struct  channel
struct  subchannel

Defines

#define ast_strlen_zero(a)   (!(*(a)))

Functions

static void add_channel (char *tech, char *location)
static void append_sub (struct channel *chan, char *name)
static void check_mute (void)
static int connect_asterisk (void)
static void delete_sub (struct channel *chan, char *name)
static struct channelfind_channel (char *channel)
static char * get_line (void)
static int getvol (void)
static void hangup_chan (char *channel)
static int load_config (void)
static int login_asterisk (void)
int main (int argc, char *argv[])
static void mute (void)
static int mutedlevel (int orig, int level)
static void offhook_chan (char *channel)
static int open_mixer (void)
static int setvol (int vol)
static void unmute (void)
static void usage (void)
static int wait_event (void)

Variables

static FILE * astf
static struct channelchannels
static char * config = "/etc/asterisk/muted.conf"
static int debug = 0
static char host [256] = ""
static int mixchan = SOUND_MIXER_VOLUME
static int mixfd
static int muted = 0
static int mutelevel = 20
static int mutevol = 0
static int needfork = 1
static int oldvol = 0
static char pass [256] = ""
static int smoothfade = 0
static int stepsize = 3
static char user [256] = ""


Detailed Description

Mute Daemon.

Author:
Mark Spencer <markster@digium.com>
Updated for Mac OSX CoreAudio
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.

Definition in file muted.c.


Define Documentation

#define ast_strlen_zero ( a   )     (!(*(a)))

Examples:
/tmp/asterisk-trunk/trunk/main/app.c.

Definition at line 73 of file muted.c.

Referenced by __analog_handle_event(), __analog_ss_thread(), __ast_bridge_technology_register(), __ast_bucket_scheme_register(), __ast_callerid_generate(), __ast_channel_alloc_ap(), __ast_channel_internal_alloc(), __ast_cli_generator(), __ast_cli_register(), __ast_datastore_alloc(), __ast_format_cache_get(), __ast_format_cache_get_debug(), __ast_http_load(), __ast_manager_event_multichan(), __ast_pbx_run(), __ast_request_and_dial(), __ast_sorcery_apply_config(), __ast_sorcery_wizard_register(), __astman_get_header(), __find_call(), __has_voicemail(), __init_manager(), __queues_show(), __set_address_from_contact(), __sip_alloc(), __sip_subscribe_mwi_do(), __ssl_setup(), _iax2_show_peers_one(), _macro_exec(), _sip_show_peer(), _sip_show_peers(), _sip_show_peers_one(), _skinny_show_devices(), _skinny_show_lines(), acf_curl_helper(), acf_if(), acf_isexten_exec(), acf_jabberreceive_read(), acf_jabberstatus_read(), acf_mailbox_exists(), acf_meetme_info(), acf_odbc_read(), acf_odbc_write(), acf_rand_exec(), acf_retrieve_docs(), acf_strptime(), acf_transaction_read(), acf_transaction_write(), acf_version_exec(), acf_vm_info(), acf_vmcount_exec(), aco_option_register_deprecated(), aco_process_var(), aco_set_defaults(), action_add_agi_cmd(), action_agent_logoff(), action_agents(), action_aocmessage(), action_atxfer(), action_blind_transfer(), action_bridge(), action_challenge(), action_command(), action_confbridgekick(), action_confbridgelist(), action_confbridgelistrooms(), action_confbridgesetsinglevideosrc(), action_confbridgestartrecord(), action_confbridgestoprecord(), action_coresettings(), action_coreshowchannels(), action_corestatus(), action_dahdidialoffhook(), action_dahdidndoff(), action_dahdidndon(), action_dahdishowchannels(), action_devicestatelist(), action_events(), action_extensionstate(), action_extensionstatelist(), action_getconfig(), action_getconfigjson(), action_getvar(), action_hangup(), action_listcategories(), action_lock_unlock_helper(), action_mailboxcount(), action_mailboxstatus(), action_meetmelist(), action_meetmelistrooms(), action_messagesend(), action_mute_unmute_helper(), action_originate(), action_ping(), action_presencestate(), action_presencestatelist(), action_redirect(), action_sendtext(), action_setvar(), action_status(), action_timeout(), action_transfer(), action_transferhangup(), action_updateconfig(), action_waitevent(), actual_load_config(), add_action_to_menu_entry(), add_calltoken_ignore(), add_cc_call_info_to_response(), add_diversion(), add_diversion_header(), add_extension(), add_format_information_cb(), add_header(), add_hints(), add_item(), add_menu_entry(), add_peer_mailboxes(), add_realm_authentication(), add_rpid(), add_sdp(), add_sip_domain(), add_text(), add_vm_recipients_from_string(), admin_exec(), adsi_exec(), adsi_input_format(), adsi_message(), advanced_options(), aes_helper(), agent_alert(), agent_function_read(), agent_handle_logoff_cmd(), agent_handle_show_specific(), agent_login_channel_config(), agent_login_exec(), agent_pvt_destructor(), agent_request_exec(), agent_show_requested(), agi_exec_full(), agi_handle_command(), alarmreceiver_exec(), alsa_new(), ami_register(), ami_show_endpoint(), ami_sip_qualify(), ami_unregister(), analog_call(), analog_ss_thread(), anonymous_identify(), answer_exec_enable(), aoc_create_ie_data(), aoc_create_ie_data_charging_rate(), aoc_parse_ie_charging_rate(), aoc_to_ami(), aocmessage_get_unit_entry(), app_exec(), append_mailbox(), append_mailbox_mapping(), append_transaction(), applicationmap_handler(), apply_general_options(), apply_option_timeout(), apply_options_full(), apply_outgoing(), apply_peer(), apps_handler(), aqm_exec(), ari_channels_handle_originate_with_id(), ari_channels_handle_snoop_channel(), ari_originate_dial(), assign_and_insert(), ast_add_extension2_lockopt(), ast_agi_register(), ast_aoc_s_add_rate_duration(), ast_aoc_s_add_rate_flat(), ast_aoc_s_add_rate_volume(), ast_aoc_set_association_number(), ast_aoc_set_currency_info(), ast_app_getdata(), ast_app_getdata_full(), ast_app_group_get_count(), ast_app_group_match_get_count(), ast_app_group_set_channel(), ast_app_group_split_group(), ast_app_run_macro(), ast_app_run_sub(), ast_append_acl(), ast_apply_acl(), ast_ari_applications_subscribe(), ast_ari_asterisk_get_global_var(), ast_ari_asterisk_set_global_var(), ast_ari_bridges_add_channel(), ast_ari_bridges_create_with_id(), ast_ari_channels_continue_in_dialplan(), ast_ari_channels_get_channel_var(), ast_ari_channels_hangup(), ast_ari_channels_mute(), ast_ari_channels_redirect(), ast_ari_channels_send_dtmf(), ast_ari_channels_set_channel_var(), ast_ari_channels_unmute(), ast_ari_config_validate_user(), ast_ari_events_user_event(), ast_ari_websocket_events_event_websocket(), ast_bridge_add_channel(), ast_bridge_channel_write_hold(), ast_bridge_features_enable(), ast_bridge_features_register(), ast_bridge_read_after_goto(), ast_bridge_set_after_go_on(), ast_bridge_setup_after_goto(), ast_bridge_snapshot_get_latest(), ast_bridge_timelimit(), ast_bridge_transfer_attended(), ast_bucket_alloc(), ast_bucket_file_alloc(), ast_bucket_file_retrieve(), ast_bucket_file_temporary_destroy(), ast_bucket_retrieve(), ast_build_timing(), ast_call_forward(), ast_cc_is_recall(), ast_cdr_format_var(), ast_cdr_getvar(), ast_cdr_serialize_variables(), ast_cel_backend_register(), ast_cel_fabricate_channel_from_event(), ast_channel_by_exten_cb(), ast_channel_by_name_cb(), ast_channel_by_uniqueid_cb(), ast_channel_connected_line_macro(), ast_channel_connected_line_sub(), ast_channel_get_by_name_prefix(), ast_channel_hash_cb(), ast_channel_internal_setup_topics(), ast_channel_publish_dial_forward(), ast_channel_publish_dial_internal(), ast_channel_redirecting_macro(), ast_channel_redirecting_sub(), ast_channel_snapshot_cep_equal(), ast_channel_snapshot_get_latest(), ast_channel_snapshot_get_latest_by_name(), ast_cli_complete(), ast_cli_perms_init(), ast_context_remove_extension_callerid2(), ast_control_tone(), ast_data_add_password(), ast_data_add_str(), ast_db_deltree(), ast_db_gettree(), ast_dial_append(), ast_dial_prerun(), ast_dns_resolve(), ast_dns_resolve_async(), ast_dns_resolve_recurring(), ast_dns_resolver_register(), ast_dns_resolver_set_result(), ast_dnsmgr_get_family(), ast_eivr_senddtmf(), ast_endpoint_add_channel(), ast_endpoint_create(), ast_endpoint_latest_snapshot(), ast_endpoint_set_max_channels(), ast_endpoint_set_state(), ast_endpoint_snapshot_create(), ast_explicit_goto(), ast_false(), ast_format_cache_set(), ast_format_cap_update_by_allow_disallow(), ast_frame_dump(), ast_get_chan_applicationmap(), ast_get_encoded_char(), ast_get_enum(), ast_get_group(), ast_get_indication_zone(), ast_get_namedgroups(), ast_get_time_t(), ast_get_timeval(), ast_http_create_response(), ast_http_get_json(), ast_http_get_post_vars(), ast_http_header_parse(), ast_http_send(), ast_iax2_new(), ast_include_new(), ast_is_valid_string(), ast_jb_read_conf(), ast_json_to_ast_variables(), ast_json_vpack(), ast_linear_stream(), ast_load_realtime_fields(), ast_makesocket(), ast_manager_build_bridge_state_string_prefix(), ast_manager_register2(), ast_media_get_description(), ast_media_get_format_cap(), ast_module_check(), ast_moh_files_next(), ast_monitor_change_fname(), ast_monitor_start(), ast_monitor_stop(), ast_msg_send(), ast_multi_channel_blob_add_channel(), ast_multi_channel_blob_get_channel(), ast_multi_channel_blob_get_channels(), ast_mwi_create(), ast_mwi_mailbox_alloc(), ast_mwi_mailbox_delete(), ast_mwi_mailbox_get(), ast_odbc_sanity_check(), ast_parse_arg(), ast_parse_digest(), ast_pbx_hangup_handler_push(), ast_pbx_outgoing_app(), ast_phoneprov_add_extension(), ast_phoneprov_provider_register(), ast_pickup_call(), ast_playtones_start(), ast_privacy_set(), ast_publish_device_state_full(), ast_queue_hold(), ast_readconfig(), ast_redirecting_reason_name(), ast_register_application2(), ast_register_indication(), ast_remotecontrol(), ast_rtp_engine_register2(), ast_rtp_glue_register2(), ast_rtp_instance_new(), ast_rtp_publish_rtcp_message(), ast_sdp_crypto_process(), ast_sendtext(), ast_set_cc_agent_dialstring(), ast_set_cc_callback_macro(), ast_set_cc_callback_sub(), ast_set_hangupsource(), ast_set_indication_country(), ast_sip_cli_traverse_objects(), ast_sip_create_ami_event(), ast_sip_create_dialog_uac(), ast_sip_create_subscription(), ast_sip_default_outbound_endpoint(), ast_sip_for_each_aor(), ast_sip_location_add_contact(), ast_sip_location_retrieve_contact_and_aor_from_list(), ast_sip_publication_add_datastore(), ast_sip_publish_client_add_datastore(), ast_sip_publish_client_alloc_datastore(), ast_sip_register_endpoint_identifier_with_name(), ast_sip_register_event_publisher_handler(), ast_sip_register_publish_handler(), ast_sip_register_subscription_handler(), ast_sip_session_add_datastore(), ast_sip_session_alloc_datastore(), ast_sip_session_create_outgoing(), ast_sip_session_send_request_with_cb(), ast_sip_subscription_add_datastore(), ast_sip_subscription_alloc_datastore(), ast_sorcery_alloc(), ast_sorcery_retrieve_by_id(), ast_speech_unregister(), ast_statsd_log_full(), ast_str_substitute_variables_full(), ast_stream_and_wait(), ast_taskprocessor_get(), AST_TEST_DEFINE(), ast_true(), ast_tzset(), ast_unreal_new_channels(), ast_uri_is_secure(), ast_var_channels_table(), ast_variable_delete(), ast_variable_update(), ast_websocket_uri_cb(), asterisk_publication_devicestate(), asterisk_publication_devicestate_refresh(), asterisk_publication_mailboxstate(), asterisk_publication_mwi_refresh(), asterisk_start_devicestate_publishing(), asterisk_start_mwi_publishing(), astman_send_list_complete_start(), astman_send_response_full(), asyncgoto_exec(), attempt_thread(), auth_apply(), auth_exec(), auth_http_callback(), authenticate(), authenticate_reply(), authenticate_verify(), autoanswer_complete(), autopause2int(), background_detect_exec(), base64_helper(), base_process_party_a(), begin_dial(), begin_dial_prerun(), bridge_agent_hold_push(), bridge_base_init(), bridge_builtin_set_limits(), bridge_check_monitor(), bridge_exec(), bridge_features_duration_callback(), bridge_parking_push(), bridge_personality_atxfer_push(), bridge_topics_init(), bridgewait_exec(), build_channels(), build_contact(), build_device(), build_gateway(), build_mapping(), build_nonce(), build_peer(), build_profile(), build_reply_digest(), build_user(), builtin_features_helper(), cache_get_callno_locked(), caldav_add_event(), caldav_load_calendar(), caldav_request(), caldav_write_event(), calendar_busy_exec(), calendar_event_read(), calendar_query_exec(), calendar_query_result_exec(), calendar_write_exec(), calendarstate(), caller_id_handler(), caller_id_outgoing_request(), callerid_feed(), callerid_genmsg(), cb_events(), cc_handle_publish_error(), cc_unique_append(), cdr_format_var_internal(), cdr_object_create_public_records(), cdr_object_get_by_name(), cdr_prop_write_callback(), cdr_read(), cdr_read_callback(), cdr_write_callback(), cel_channel_app_change(), cel_channel_linkedid_change(), cel_channel_state_change(), cel_dial_cb(), cel_linkedid_ref(), celgenuserevent_exec(), chan_misdn_log(), chan_pjsip_new(), chanavail_exec(), change_monitor_action(), change_redirecting_information(), channel_admin_exec(), channel_dial_cb(), channel_dialplan(), channel_do_masquerade(), channel_fill_empty_accountcode(), channel_fill_empty_peeraccount(), channel_hold_cb(), channel_newexten(), channel_read_pjsip(), channel_read_rtcp(), channel_read_rtp(), channel_req_accountcodes(), channel_spy(), chanspy_exec(), chararray_handler_fn(), check_access(), check_auth(), check_blacklist(), check_bridge_play_sound(), check_day(), check_dow(), check_match(), check_month(), check_new_cdr_needed(), check_password(), check_peer_ok(), check_retire_linkedid(), check_sip_domain(), check_timerange(), check_user_full(), cleaned_basedn(), clear_stats(), cli_alias_passthrough(), cli_complete_notify(), cli_console_dial(), cli_console_sendtext(), cli_odbc_read(), cli_odbc_write(), cli_qualify_contacts(), close_client(), commit_exec(), common_exec(), compare(), compile_script(), complete_agent(), complete_agent_logoff(), complete_ari_user(), complete_bridge_live(), complete_number(), complete_parking_lot(), conf_exec(), conf_find_bridge_profile(), conf_find_user_profile(), conf_run(), conf_set_menu_to_user(), confbridge_exec(), config_curl(), config_function_read(), config_ldap(), config_line(), config_module(), config_parse_variables(), config_text_file_load(), console_dial(), console_new(), console_print(), console_sendtext(), control_list_create(), controlplayback_exec(), controlplayback_manager(), copy_all_header(), copy_header(), copy_message(), copy_rules(), copy_variables(), copy_via_headers(), count_exec(), create_addr(), create_addr_from_peer(), create_channel_name(), create_dynamic_lot_full(), create_local_sdp(), create_mwi_subscriptions_for_endpoint(), create_out_of_dialog_request(), create_outgoing_sdp_stream(), create_queue_member(), create_sound_blob(), create_vmaccount(), crement_function_read(), crypto_get_attrib(), csv_log(), csv_quote(), custom_prepare(), custom_presence_callback(), dahdi_handle_event(), dahdi_new(), dahdi_read(), dahdiscan_exec(), data_filter_find(), data_result_create(), database_increment(), declined_handler(), delete_existing_cb(), deltree_exec(), destroy_endpoint(), destroy_mysql(), destroy_pgsql(), destroy_trans(), determine_sip_publish_type(), determine_starting_point(), device_state_alloc(), devstate_write(), dial_exec_full(), dial_handle_playtones(), dialgroup_read(), dialgroup_refreshdb(), dialgroup_write(), dialout(), dialplan_has_destination_cb(), dictate_exec(), digest_check_auth(), directory_exec(), disa_exec(), do_forward(), do_immediate_setup(), do_message(), do_monitor(), do_notify(), do_pause_or_unpause(), does_category_match(), does_method_match(), dump_cause(), dump_hint(), dumpchan_exec(), dundi_exec(), dundi_flags2str(), dundi_helper(), dundi_hint2str(), dundi_lookup_local(), dundi_query_read(), dundi_query_thread(), dundi_result_read(), dundi_show_mappings(), dundi_show_peer(), dundifunc_read(), dynamic_dtmf_hook_add(), enable_jack_hook(), endpoint_internal_create(), enum_callback(), enum_query_read(), enum_result_read(), env_write(), events_handler(), ewscal_load_calendar(), exchangecal_load_calendar(), exchangecal_write_event(), exec_exec(), execif_exec(), execute_state_callback(), expand_gosub_args(), export_ch(), extension_match_core(), extension_presence_state_helper(), extenspy_exec(), extract_uri(), extstate_read(), fast_originate(), feature_automixmonitor(), feature_automonitor(), feature_blind_transfer(), festival_exec(), fetch_icalendar(), fileexists_core(), filename_parse(), find_account(), find_aor(), find_app_by_name(), find_body_generator_accept(), find_channel_parking_lot_name(), find_cli(), find_conf_realtime(), find_engine(), find_header(), find_line_by_name(), find_or_create(), find_queue_by_name_rt(), find_realtime_gw(), find_sdp(), find_sip_method(), find_table(), findmeexec(), forkcdr_exec(), format_ami_endpoint_transport(), forward_message(), forwards_create(), func_channel_read(), func_channel_write_real(), func_channels_read(), func_check_sipdomain(), func_confbridge_helper(), func_confbridge_info(), func_header_read(), func_mixmonitor_read(), func_read_header(), func_write_header(), function_amiclient(), function_db_delete(), function_db_exists(), function_db_read(), function_db_write(), function_enum(), function_eval(), function_eval2(), function_fieldnum_helper(), function_realtime_read(), function_realtime_readdestroy(), function_realtime_store(), function_realtime_write(), function_txtcidname(), generate_parked_user(), generic_fax_exec(), generic_recall(), get_also_info(), get_destination(), get_domain(), get_in_brackets_const(), get_in_brackets_full(), get_name_and_number(), get_name_from_variable(), get_or_create_subscription(), get_outbound_endpoint(), get_pai(), get_queue_member_status(), get_range(), get_rdnis(), get_realm(), get_refer_info(), get_rpid(), get_sip_pvt_from_replaces(), get_subscription(), get_timerange(), get_transfer_context(), get_transport_str2enum(), gosub_exec(), gosubif_exec(), goto_exten(), grab_transfer(), group_count_function_read(), group_function_read(), group_function_write(), group_list_function_read(), group_match_count_function_read(), group_show_channels(), h264_generate_sdp_fmtp(), h264_getjoint(), handle_aor(), handle_attended_transfer(), handle_blind_transfer(), handle_bridge_enter(), handle_call_forward(), handle_cc_notify(), handle_cc_subscribe(), handle_cli_cdr_mysql_status(), handle_cli_check_permissions(), handle_cli_confbridge_show_bridge_profile(), handle_cli_confbridge_show_user_profile(), handle_cli_confbridge_start_record(), handle_cli_config_reload(), handle_cli_database_show(), handle_cli_database_showkey(), handle_cli_devstate_change(), handle_cli_dialplan_save(), handle_cli_dynamic_level_test(), handle_cli_file_convert(), handle_cli_iax2_show_cache(), handle_cli_iax2_show_peer(), handle_cli_iax2_show_users(), handle_cli_presencestate_change(), handle_cli_realtime_mysql_status(), handle_cli_realtime_pgsql_status(), handle_command_response(), handle_controlstreamfile(), handle_debug(), handle_debug_dialplan(), handle_dial_message(), handle_dial_page(), handle_endpoint(), handle_getvariable(), handle_incoming(), handle_incoming_request(), handle_logger_remove_channel(), handle_manager_bridge_tech_suspend(), handle_options(), handle_orig(), handle_pjsip_list_ciphers(), handle_playtones(), handle_queue_add_member(), handle_queue_pause_member(), handle_queue_remove_member(), handle_queue_rule_show(), handle_registrations(), handle_request_bye(), handle_request_info(), handle_request_invite(), handle_request_invite_st(), handle_request_notify(), handle_request_options(), handle_request_publish(), handle_request_refer(), handle_request_subscribe(), handle_request_update(), handle_response(), handle_response_invite(), handle_response_notify(), handle_response_publish(), handle_response_refer(), handle_response_register(), handle_saydatetime(), handle_show_dialplan(), handle_soft_key_event_message(), handle_speechrecognize(), handle_stimulus_message(), handle_subscribe(), handle_updates(), handle_verbose(), handle_voicemail_show_users(), has_voicemail(), hashtab_compare_extens(), hep_queue_cb(), hint_hash(), hint_read(), hook_off(), hook_on(), hook_re_enable(), http_body_discard_chunk_trailer_headers(), http_request_headers_get(), iax2_call(), iax2_datetime(), iax2_devicestate(), iax2_prov_app(), iax2_request(), iax_firmware_append(), iax_firmware_get_version(), iax_provflags2str(), ical_load_calendar(), icalendar_add_event(), ices_exec(), iconv_read(), iftime(), import_helper(), inboxcount2(), init_acf_query(), init_jack_data(), initialize_cc_max_requests(), initreqprep(), insert_penaltychange(), inspect_module(), internal_aco_type_find(), internal_dnsmgr_lookup(), internal_process_ast_config(), ip_identify_match_handler(), is_argument(), is_new_rec_file(), is_prefix(), is_preload(), is_valid_dialstatus(), is_valid_tone_zone(), isAnsweringMachine(), isexten_function_read(), jack_exec(), jb_choose_impl(), jb_framedata_init(), jb_helper(), jingle_action_hook(), jingle_alloc(), jingle_interpret_content(), jingle_interpret_description(), jingle_interpret_google_transport(), jingle_interpret_ice_udp_transport(), jingle_new(), jingle_outgoing_hook(), jingle_request(), jingle_send_error_response(), join_conference_bridge(), key_dial_page(), key_history(), key_main_page(), kill_dead_queues(), launch_asyncagi(), launch_monitor_thread(), launch_netscript(), ldap_reconnect(), ldap_table_config_add_attribute(), leave_voicemail(), line_identify(), load_column_config(), load_config(), load_endpoint(), load_indications(), load_module(), load_moh_classes(), load_mysql_config(), load_odbc_config(), load_realtime_rules(), load_values_config(), local_ast_moh_start(), log_events(), log_exec(), logger_print_normal(), loopback_parse(), lua_get_variable(), lua_get_variable_value(), main(), make_components(), make_dir(), make_email_file(), make_filename(), make_fn(), make_logchannel(), man_do_variable_value(), manager_add_queue_member(), manager_bridge_destroy(), manager_bridge_info(), manager_bridge_kick(), manager_bridge_tech_list(), manager_bridges_list(), manager_data_get(), manager_dbdel(), manager_dbdeltree(), manager_dbget(), manager_dbput(), manager_dialplan_extension_add(), manager_dialplan_extension_remove(), manager_fax_session(), manager_fax_sessions(), manager_fax_stats(), manager_iax2_show_peer_list(), manager_iax2_show_peers(), manager_iax2_show_registry(), manager_jabber_send(), manager_list_voicemail_users(), manager_mixmonitor(), manager_modulecheck(), manager_moduleload(), manager_mute_mixmonitor(), manager_mutestream(), manager_notify(), manager_optimize_away(), manager_park(), manager_parking_lot_list(), manager_parking_status(), manager_pause_queue_member(), manager_play_dtmf(), manager_queue_log_custom(), manager_queue_member_penalty(), manager_queue_member_ringinuse(), manager_queue_rule_show(), manager_queues_status(), manager_queues_summary(), manager_remove_queue_member(), manager_show_dialplan(), manager_show_dialplan_helper(), manager_show_registry(), manager_sip_peer_status(), manager_sip_qualify_peer(), manager_sip_show_peer(), manager_sip_show_peers(), manager_sipnotify(), manager_skinny_show_device(), manager_skinny_show_line(), manager_stop_mixmonitor(), manager_voicemail_refresh(), mark_dead_and_unfound(), mark_parsed_methods(), match_req_to_dialog(), matchcid(), math(), mbl_load_adapter(), mbl_load_device(), mbl_sendsms_exec(), mbl_status_exec(), md5(), media_index_update(), meetmemute(), message_playback_callback_fn(), message_range_and_existence_check(), message_received_handler(), message_template_find(), message_template_parse_filebody(), messagecount(), messaging_app_unsubscribe_endpoint(), metermaidstate(), mgcp_call(), mgcp_hangup(), mgcp_new(), mgcp_prune_realtime_gateway(), mgcp_request(), mgcp_ss(), mgcpsock_read(), milliwatt_exec(), minivm_accmess_exec(), minivm_account_func_read(), minivm_counter_func_read(), minivm_counter_func_write(), minivm_delete_exec(), minivm_greet_exec(), minivm_mwi_exec(), minivm_notify_exec(), minivm_record_exec(), misdn_answer(), misdn_call(), misdn_cfg_update_ptp(), misdn_check_l2l1(), misdn_facility_exec(), misdn_new(), misdn_overlap_dial_task(), misdn_request(), misdn_set_opt_exec(), mixmonitor_exec(), mixmonitor_save_prep(), mixmonitor_thread(), mkintf(), modify_mysql(), monitor_dial(), morsecode_exec(), mp3_exec(), msg_send_exec(), msg_set_var_full(), msg_to_endpoint(), mssql_connect(), multicast_rtp_request(), mwi_folder_map(), mwi_mailbox_delete(), mwi_mailbox_get(), mwi_mailbox_update(), mwi_new_subscribe(), mwi_on_aor(), mwi_state_create_message(), mwi_subscription_established(), mwi_to_event(), mwi_validate_for_aor(), my_load_module(), mysql_log(), mysql_reconnect(), named_acl_find_realtime(), named_groups_handler(), nbs_alloc(), new_outgoing(), new_realtime_sqlite3_db(), newpvt(), next_node_name(), notify_endpoint(), notify_message(), notify_new_message(), notify_uri(), odbc_log(), on_endpoint(), onedigit_goto(), onNewCallCreated(), onOutgoingCall(), ooh323_indicate(), ooh323_new(), ooh323_onReceivedSetup(), options_on_rx_request(), orig_app(), orig_exten(), originate_exec(), osp_auth(), osp_convert_inout(), osp_convert_outin(), osp_get_varfloat(), osp_get_varint(), osp_lookup(), osp_report_qos(), ospauth_exec(), ospfinished_exec(), osplookup_exec(), ospnext_exec(), oss_call(), oss_new(), page_exec(), park_and_announce_app_exec(), park_announce_update_cb(), park_app_parse_data(), park_common_setup(), parked_call_app_exec(), parking_blind_transfer_park(), parking_channel_set_roles(), parking_duration_callback(), parking_lot_cfg_create_extensions(), parking_lot_cfg_remove_extensions(), parking_park_call(), parse(), parse_allowed_methods(), parse_bookmark(), parse_config(), parse_cookies(), parse_data(), parse_dial_string(), parse_minse(), parse_moved_contact(), parse_oli(), parse_playtone(), parse_register_contact(), parse_request(), parse_session_expires(), parse_sip_options(), parse_tag(), parse_tone_uri(), parse_uri_full(), parse_via(), participant_idle_mode_setup(), path_get_string(), path_outgoing_request(), payload_helper_app(), pbx_builtin_answer(), pbx_builtin_background(), pbx_builtin_execiftime(), pbx_builtin_gotoif(), pbx_builtin_gotoiftime(), pbx_builtin_hangup(), pbx_builtin_importvar(), pbx_builtin_incomplete(), pbx_builtin_saycharacters_case(), pbx_builtin_saynumber(), pbx_builtin_setamaflags(), pbx_builtin_setvar(), pbx_builtin_setvar_multiple(), pbx_builtin_waitexten(), pbx_checkcondition(), pbx_extension_helper(), pbx_find_extension(), pbx_load_config(), pbx_load_users(), pbx_outgoing_attempt(), pbx_outgoing_exec(), pbx_parseable_goto(), pbx_set_overrideswitch(), pbx_substitute_variables_helper_full(), peek_read(), peer_ipcmp_cb_full(), permanent_uri_handler(), persistent_endpoint_find_or_create(), persistent_endpoint_update_state(), pgsql_reconnect(), phone_call(), phone_new(), pickup_exec(), pickupchan_exec(), pidf_supplement_body(), pjsip_acf_channel_read(), pjsip_acf_dial_contacts_read(), pjsip_aor_function_read(), pjsip_contact_function_read(), pjsip_endpoint_function_read(), pjsip_log_test_addr(), play_file(), play_mailbox_owner(), play_message(), play_message_by_id_helper(), play_message_callerid(), play_message_category(), play_message_datetime(), play_moh_exec(), play_record_review(), play_sound_helper(), playback_create(), playback_exec(), poll_subscribed_mailboxes(), populate_cache(), port_str2int(), post_cdr(), pp_each_extension_helper(), pp_each_user_helper(), pqm_exec(), prep_email_sub_vars(), presence_read(), presence_state_cached(), presence_write(), print_ext(), print_frame(), privacy_exec(), proc_422_rsp(), process_category(), process_dahdi(), process_description_file(), process_echocancel(), process_ice_attributes(), process_message(), process_message_callback(), process_my_load_module(), process_sdp(), process_sdp_a_ice(), process_sdp_o(), process_text_line(), process_token(), proxy_from_config(), publish_acl_change(), publish_device_state_to_stasis(), publish_mwi_to_stasis(), publish_qualify_peer_done(), publish_queue_member_pause(), publish_request_initial(), ql_exec(), qualify_and_schedule_all_cb(), qualify_contact(), queue_exec(), queue_function_exists(), queue_function_mem_read(), queue_function_mem_write(), queue_function_memberpenalty_read(), queue_function_memberpenalty_write(), queue_function_qac_dep(), queue_function_queuegetchannel(), queue_function_queuememberlist(), queue_function_queuewaitingcount(), queue_function_var(), queue_mwi_event(), queue_reload_request(), queues_data_provider_get(), quote(), rcv_mac_addr(), rcvfax_exec(), read_config(), read_exec(), readexten_exec(), really_quit(), realtime_common(), realtime_curl(), realtime_directory(), realtime_exec(), realtime_is_object_matching(), realtime_ldap_entry_to_var(), realtime_ldap_result_to_vars(), realtime_ldap_status(), realtime_multi_curl(), realtime_multi_mysql(), realtime_multi_odbc(), realtime_multi_pgsql(), realtime_mysql(), realtime_odbc(), realtime_peer_by_addr(), realtime_pgsql(), realtime_sqlite3_destroy(), realtime_sqlite3_helper(), realtime_sqlite3_load(), realtime_sqlite3_require(), realtime_sqlite3_store(), realtime_sqlite3_update(), realtime_sqlite3_update2(), realtime_update_peer(), realtimefield_read(), reason_code_to_str(), receive_ademco_event(), receive_message(), receivefax_exec(), record_exec(), recording_publish(), recordthread(), refer_outgoing_request(), regex_filter_handler(), register_exten(), register_peer_exten(), register_verify(), registrar_delete_contact(), registrar_on_rx_request(), registry_rerequest(), reload_config(), reload_followme(), reload_queue_members(), reload_queues(), reload_single_member(), remove_from_queue(), remove_members_and_mark_unfound(), replace(), reply_digest(), report_receive_fax_status(), report_send_fax_status(), reqprep(), request(), requirecalltoken_mark_auto(), resetcdr_exec(), resource_event_handler(), resource_list_apply_handler(), respprep(), retrydial_exec(), ring_entry(), rollback_exec(), rotate_file(), rqm_exec(), rt_handle_member_record(), rtcp_do_debug_ip(), rtcp_message_handler(), rtp_do_debug_ip(), run_externnotify(), saycountedadj_exec(), saycountednoun_exec(), sayunixtime_exec(), scan(), scan_dir(), search_directory(), search_directory_sub(), select_item_pause(), send_message(), send_refresh_cb(), send_unsolicited_mwi_notify(), send_unsolicited_mwi_notify_to_contact(), senddtmf_exec(), sendfax_exec(), sendimage_exec(), sendmail(), sendpage(), sendurl_exec(), separate_mailbox(), session_outgoing_nat_hook(), session_register_app(), set(), set_bridge_features_on_config(), set_callforwards(), set_config(), set_id_from_hdr(), set_insecure_flags(), set_local_info(), set_member_paused(), set_member_value(), set_outbound_authentication_credentials(), set_rec_filename(), set_sound(), set_touch_variable(), set_var_handler(), setsubstate(), setup_dahdi_int(), setup_mixmonitor(), setup_mixmonitor_ds(), setup_park_common_datastore(), setup_privacy_args(), setup_profile_caller(), setup_profile_paged(), setup_stunaddr(), sha1(), shared_read(), shared_write(), shell_helper(), shift_pop(), should_queue_connected_line_update(), show_main_page(), show_sound_info_cb(), sip_acf_channel_read(), sip_addheader(), sip_call(), sip_cc_agent_respond(), sip_cc_monitor_suspend(), sip_cc_monitor_unsuspend(), sip_dialog_create_contact(), sip_dialog_create_from(), sip_endpoint_apply_handler(), sip_get_cc_information(), sip_get_tpselector_from_endpoint(), sip_msg_send(), sip_new(), sip_outbound_publish_apply(), sip_outbound_publish_client_alloc(), sip_outbound_registration_apply(), sip_outbound_registration_regc_alloc(), sip_parse_host(), sip_parse_register_line(), sip_poke_peer(), sip_prepare_socket(), sip_publish_client_service_queue(), sip_reason_code_to_str(), sip_removeheader(), sip_report_chal_sent(), sip_report_failed_challenge_response(), sip_report_security_event(), sip_request_call(), sip_send_mwi_to_peer(), sip_show_channel(), sip_show_registry(), sip_show_settings(), sip_show_user(), sip_sipredirect(), sip_subscribe_mwi(), sip_uri_cmp(), sip_uri_headers_cmp(), sip_uri_params_cmp(), sipinfo_send(), skel_exec(), skinny_new(), skinny_register(), skinny_request(), sla_build_station(), sla_build_trunk(), sla_check_device(), sla_queue_event_conf(), sla_station_destructor(), sla_station_exec(), sla_trunk_destructor(), sla_trunk_exec(), smdi_md_q_cmp_fn(), smdi_msg_find(), smdi_msg_read(), smdi_msg_retrieve_read(), sms_exec(), sndfax_exec(), socket_process_helper(), softhangup_exec(), sorcery_astdb_open(), sorcery_config_open(), sorcery_function_read(), sorcery_realtime_open(), spawn_mp3(), speech_background(), split_ext(), srv_query_read(), srv_result_read(), stackpeek_read(), start_automixmonitor(), start_automonitor(), start_mixmonitor_callback(), start_monitor_action(), start_monitor_exec(), stasis_app_control_dial(), stasis_app_control_moh_start(), stasis_app_control_record(), stasis_app_control_snoop(), stasis_app_device_state_delete(), stasis_app_device_state_update(), stasis_app_device_states_to_json(), stasis_app_recording_if_exists_parse(), stasis_app_recording_termination_parse(), static_callback(), stop_automixmonitor(), stop_automonitor(), stop_mixmonitor_full(), stop_monitor_action(), store_config(), stringfield_handler_fn(), strings_to_mask(), strreplace(), substituted(), sysinfo_helper(), system_exec_helper(), system_registry_to_ami(), talk_detect_fn_write(), test_msg_has_destination_cb(), testclient_exec(), testserver_exec(), transfer(), transfer_exec(), transmit_cfwdstate(), transmit_fake_auth_response(), transmit_info_with_aoc(), transmit_invite(), transmit_modify_request(), transmit_modify_with_sdp(), transmit_notify_request(), transmit_notify_request_with_callerid(), transmit_register(), transmit_request_with_auth(), transport_apply(), transport_localnet_handler(), transport_tls_cipher_handler(), transport_tls_method_handler(), try_calling(), try_firmware(), try_suggested_sip_codec(), tryexec_exec(), unalloc_sub(), unbound_config_preapply(), unicast_rtp_request(), unistim_call(), unistim_new(), unistim_request(), unregister_exten(), unshift_push(), update_connectedline(), update_from(), update_odbc(), update_realtime_member_field(), update_realtime_members(), update_registry(), upqm_exec(), uri_parse_and_default(), uridecode(), uriencode(), user_event_hook_cb(), userevent_exec(), username_identify(), users_data_provider_get(), ustmtext(), valid_exit(), validate_user_cb(), verbose_exec(), vm_authenticate(), vm_box_exists(), vm_exec(), vm_execmain(), vm_mailbox_snapshot_create(), vm_msg_forward(), vm_msg_move(), vm_msg_play(), vm_msg_remove(), vm_newuser(), vm_options(), vm_playmsgexec(), vm_sayname(), vmauthenticate(), vmsayname_exec(), vmu_tm(), volume_write(), wait_for_answer(), wait_for_hangup(), wait_for_winner(), waituntil_exec(), websocket_client_handshake(), wizard_apply_handler(), word_match(), write_metadata(), xml_translate(), xmpp_client_config_post_apply(), xmpp_client_send_message(), xmpp_client_set_presence(), xmpp_config_prelink(), xmpp_join_exec(), xmpp_leave_exec(), xmpp_pak_message(), xmpp_pak_presence(), xmpp_pubsub_iq_create(), xmpp_send_cb(), xmpp_send_exec(), xmpp_sendgroup_exec(), xmpp_status_exec(), and zapateller_exec().


Function Documentation

static void add_channel ( char *  tech,
char *  location 
) [static]

Definition at line 102 of file muted.c.

References channels, free, channel::location, malloc, channel::next, strdup, and channel::tech.

Referenced by load_config().

00103 {
00104    struct channel *chan;
00105    chan = malloc(sizeof(struct channel));
00106    if (chan) {
00107       memset(chan, 0, sizeof(struct channel));
00108       if (!(chan->tech = strdup(tech))) {
00109          free(chan);
00110          return;
00111       }
00112       if (!(chan->location = strdup(location))) {
00113          free(chan->tech);
00114          free(chan);
00115          return;
00116       }
00117       chan->next = channels;
00118       channels = chan;
00119    }
00120    
00121 }

static void append_sub ( struct channel chan,
char *  name 
) [static]

Definition at line 585 of file muted.c.

References free, malloc, subchannel::name, subchannel::next, strdup, sub, and channel::subs.

Referenced by offhook_chan().

00586 {
00587    struct subchannel *sub;
00588    sub = chan->subs;
00589    while(sub) {
00590       if (!strcasecmp(sub->name, name)) 
00591          return;
00592       sub = sub->next;
00593    }
00594    sub = malloc(sizeof(struct subchannel));
00595    if (sub) {
00596       memset(sub, 0, sizeof(struct subchannel));
00597       if (!(sub->name = strdup(name))) {
00598          free(sub);
00599          return;
00600       }
00601       sub->next = chan->subs;
00602       chan->subs = sub;
00603    }
00604 }

static void check_mute ( void   )  [static]

Definition at line 547 of file muted.c.

References channels, mute, muted, channel::next, channel::subs, and unmute().

Referenced by hangup_chan(), and offhook_chan().

00548 {
00549    int offhook = 0;
00550    struct channel *chan;
00551    chan = channels;
00552    while(chan) {
00553       if (chan->subs) {
00554          offhook++;
00555          break;
00556       }
00557       chan = chan->next;
00558    }
00559    if (offhook && !muted)
00560       mute();
00561    else if (!offhook && muted)
00562       unmute();
00563 }

static int connect_asterisk ( void   )  [static]

Connect to the asterisk manager interface

Definition at line 225 of file muted.c.

References astf, errno, gethostbyname, host, and hp.

Referenced by main().

00226 {
00227    int sock;
00228    struct hostent *hp;
00229    char *ports;
00230    int port = 5038;
00231    struct sockaddr_in sin;
00232 
00233    ports = strchr(host, ':');
00234    if (ports) {
00235       *ports = '\0';
00236       ports++;
00237       if ((sscanf(ports, "%5d", &port) != 1) || (port < 1) || (port > 65535)) {
00238          fprintf(stderr, "'%s' is not a valid port number in the hostname\n", ports);
00239          return -1;
00240       }
00241    }
00242    hp = gethostbyname(host);
00243    if (!hp) {
00244       fprintf(stderr, "Can't find host '%s'\n", host);
00245       return -1;
00246    }
00247    sock = socket(AF_INET, SOCK_STREAM, 0);
00248    if (sock < 0) {
00249       fprintf(stderr, "Failed to create socket: %s\n", strerror(errno));
00250       return -1;
00251    }
00252    sin.sin_family = AF_INET;
00253    sin.sin_port = htons(port);
00254    memcpy(&sin.sin_addr, hp->h_addr, sizeof(sin.sin_addr));
00255    if (connect(sock, (struct sockaddr *)&sin, sizeof(sin))) {
00256       fprintf(stderr, "Failed to connect to '%s' port '%d': %s\n", host, port, strerror(errno));
00257       close(sock);
00258       return -1;
00259    }
00260    astf = fdopen(sock, "r+");
00261    if (!astf) {
00262       fprintf(stderr, "fdopen failed: %s\n", strerror(errno));
00263       close(sock);
00264       return -1;
00265    }
00266    return 0;
00267 }

static void delete_sub ( struct channel chan,
char *  name 
) [static]

Definition at line 565 of file muted.c.

References free, subchannel::name, subchannel::next, NULL, sub, and channel::subs.

Referenced by hangup_chan().

00566 {
00567    struct subchannel *sub, *prev;
00568    prev = NULL;
00569    sub = chan->subs;
00570    while(sub) {
00571       if (!strcasecmp(sub->name, name)) {
00572          if (prev)
00573             prev->next = sub->next;
00574          else
00575             chan->subs = sub->next;
00576          free(sub->name);
00577          free(sub);
00578          return;
00579       }
00580       prev = sub;
00581       sub = sub->next;
00582    }
00583 }

static struct channel* find_channel ( char *  channel  )  [static, read]

Definition at line 326 of file muted.c.

References channels, debug, channel::location, channel::next, NULL, channel::tech, and tmp().

00327 {
00328    char tmp[256] = "";
00329    char *s, *t;
00330    struct channel *chan;
00331    strncpy(tmp, channel, sizeof(tmp) - 1);
00332    s = strchr(tmp, '/');
00333    if (s) {
00334       *s = '\0';
00335       s++;
00336       t = strrchr(s, '-');
00337       if (t) {
00338          *t = '\0';
00339       }
00340       if (debug)
00341          printf("Searching for '%s' tech, '%s' location\n", tmp, s);
00342       chan = channels;
00343       while(chan) {
00344          if (!strcasecmp(chan->tech, tmp) && !strcasecmp(chan->location, s)) {
00345             if (debug)
00346                printf("Found '%s'/'%s'\n", chan->tech, chan->location);
00347             break;
00348          }
00349          chan = chan->next;
00350       }
00351    } else
00352       chan = NULL;
00353    return chan;
00354 }

static char* get_line ( void   )  [static]

Definition at line 269 of file muted.c.

References astf, buf, and NULL.

Referenced by login_asterisk(), and wait_event().

00270 {
00271    static char buf[1024];
00272    if (fgets(buf, sizeof(buf), astf)) {
00273       while(strlen(buf) && (buf[strlen(buf) - 1] < 33))
00274          buf[strlen(buf) - 1] = '\0';
00275       return buf;
00276    } else
00277       return NULL;
00278 }

static int getvol ( void   )  [static]

Definition at line 357 of file muted.c.

References channels, errno, mixchan, mixfd, and NULL.

Referenced by mute(), and unmute().

00358 {
00359    int vol;
00360 
00361    if (ioctl(mixfd, MIXER_READ(mixchan), &vol)) {
00362 #else
00363 static float getvol(void)
00364 {
00365    float volumeL, volumeR, vol;
00366    OSStatus err;
00367    AudioDeviceID device;
00368    UInt32 size;
00369    UInt32 channels[2];
00370    AudioObjectPropertyAddress OutputAddr = { kAudioHardwarePropertyDefaultOutputDevice, kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyElementMaster };
00371    AudioObjectPropertyAddress ChannelAddr = { kAudioDevicePropertyPreferredChannelsForStereo, kAudioDevicePropertyScopeOutput, kAudioObjectPropertyElementWildcard };
00372    AudioObjectPropertyAddress VolumeAddr = { kAudioDevicePropertyVolumeScalar, kAudioDevicePropertyScopeOutput, };
00373 
00374    size = sizeof(device);
00375    err = AudioObjectGetPropertyData(kAudioObjectSystemObject, &OutputAddr, 0, NULL, &size, &device);
00376    size = sizeof(channels);
00377    if (!err) {
00378       err = AudioObjectGetPropertyData(device, &ChannelAddr, 0, NULL, &size, &channels);
00379    }
00380    size = sizeof(vol);
00381    if (!err) {
00382       VolumeAddr.mElement = channels[0];
00383       err = AudioObjectGetPropertyData(device, &VolumeAddr, 0, NULL, &size, &volumeL);
00384    }
00385    if (!err) {
00386       VolumeAddr.mElement = channels[1];
00387       err = AudioObjectGetPropertyData(device, &VolumeAddr, 0, NULL, &size, &volumeR);
00388    }
00389    if (!err)
00390       vol = (volumeL < volumeR) ? volumeR : volumeL;
00391    else {
00392 #endif
00393       fprintf(stderr, "Unable to read mixer volume: %s\n", strerror(errno));
00394       return -1;
00395    }
00396    return vol;
00397 }

static void hangup_chan ( char *  channel  )  [static]

Definition at line 606 of file muted.c.

References check_mute(), debug, delete_sub(), and find_channel().

00607 {
00608    struct channel *chan;
00609    if (debug)
00610       printf("Hangup '%s'\n", channel);
00611    chan = find_channel(channel);
00612    if (chan)
00613       delete_sub(chan, channel);
00614    check_mute();
00615 }

static int load_config ( void   )  [static]

Definition at line 123 of file muted.c.

References add_channel(), buf, channels, config, errno, f, host, mutelevel, pass, and smoothfade.

00124 {
00125    FILE *f;
00126    char buf[1024];
00127    char *val;
00128    char *val2;
00129    int lineno=0;
00130    int x;
00131    f = fopen(config, "r");
00132    if (!f) {
00133       fprintf(stderr, "Unable to open config file '%s': %s\n", config, strerror(errno));
00134       return -1;
00135    }
00136    while(!feof(f)) {
00137       if (!fgets(buf, sizeof(buf), f)) {
00138          continue;
00139       }
00140       if (!feof(f)) {
00141          lineno++;
00142          val = strchr(buf, '#');
00143          if (val) *val = '\0';
00144          while(strlen(buf) && (buf[strlen(buf) - 1] < 33))
00145             buf[strlen(buf) - 1] = '\0';
00146          if (!strlen(buf))
00147             continue;
00148          val = buf;
00149          while(*val) {
00150             if (*val < 33)
00151                break;
00152             val++;
00153          }
00154          if (*val) {
00155             *val = '\0';
00156             val++;
00157             while(*val && (*val < 33)) val++;
00158          }
00159          if (!strcasecmp(buf, "host")) {
00160             if (val && strlen(val))
00161                strncpy(host, val, sizeof(host) - 1);
00162             else
00163                fprintf(stderr, "host needs an argument (the host) at line %d\n", lineno);
00164          } else if (!strcasecmp(buf, "user")) {
00165             if (val && strlen(val))
00166                strncpy(user, val, sizeof(user) - 1);
00167             else
00168                fprintf(stderr, "user needs an argument (the user) at line %d\n", lineno);
00169          } else if (!strcasecmp(buf, "pass")) {
00170             if (val && strlen(val))
00171                strncpy(pass, val, sizeof(pass) - 1);
00172             else
00173                fprintf(stderr, "pass needs an argument (the password) at line %d\n", lineno);
00174          } else if (!strcasecmp(buf, "smoothfade")) {
00175             smoothfade = 1;
00176          } else if (!strcasecmp(buf, "mutelevel")) {
00177             if (val && (sscanf(val, "%3d", &x) == 1) && (x > -1) && (x < 101)) {
00178                mutelevel = x;
00179             } else 
00180                fprintf(stderr, "mutelevel must be a number from 0 (most muted) to 100 (no mute) at line %d\n", lineno);
00181          } else if (!strcasecmp(buf, "channel")) {
00182             if (val && strlen(val)) {
00183                val2 = strchr(val, '/');
00184                if (val2) {
00185                   *val2 = '\0';
00186                   val2++;
00187                   add_channel(val, val2);
00188                } else
00189                   fprintf(stderr, "channel needs to be of the format Tech/Location at line %d\n", lineno);
00190             } else
00191                fprintf(stderr, "channel needs an argument (the channel) at line %d\n", lineno);
00192          } else {
00193             fprintf(stderr, "ignoring unknown keyword '%s'\n", buf);
00194          }
00195       }
00196    }
00197    fclose(f);
00198    if (!strlen(host))
00199       fprintf(stderr, "no 'host' specification in config file\n");
00200    else if (!strlen(user))
00201       fprintf(stderr, "no 'user' specification in config file\n");
00202    else if (!channels) 
00203       fprintf(stderr, "no 'channel' specifications in config file\n");
00204    else
00205       return 0;
00206    return -1;
00207 }

static int login_asterisk ( void   )  [static]

Login to the asterisk manager interface

Definition at line 281 of file muted.c.

References astf, get_line(), and pass.

Referenced by main().

00282 {
00283    char *welcome;
00284    char *resp;
00285    if (!(welcome = get_line())) {
00286       fprintf(stderr, "disconnected (1)\n");
00287       return -1;
00288    }
00289    fprintf(astf, 
00290       "Action: Login\r\n"
00291       "Username: %s\r\n"
00292       "Secret: %s\r\n\r\n", user, pass);
00293    if (!(welcome = get_line())) {
00294       fprintf(stderr, "disconnected (2)\n");
00295       return -1;
00296    }
00297    if (strcasecmp(welcome, "Response: Success")) {
00298       fprintf(stderr, "login failed ('%s')\n", welcome);
00299       return -1;
00300    }
00301    /* Eat the rest of the event */
00302    while((resp = get_line()) && strlen(resp));
00303    if (!resp) {
00304       fprintf(stderr, "disconnected (3)\n");
00305       return -1;
00306    }
00307    fprintf(astf, 
00308       "Action: Status\r\n\r\n");
00309    if (!(welcome = get_line())) {
00310       fprintf(stderr, "disconnected (4)\n");
00311       return -1;
00312    }
00313    if (strcasecmp(welcome, "Response: Success")) {
00314       fprintf(stderr, "status failed ('%s')\n", welcome);
00315       return -1;
00316    }
00317    /* Eat the rest of the event */
00318    while((resp = get_line()) && strlen(resp));
00319    if (!resp) {
00320       fprintf(stderr, "disconnected (5)\n");
00321       return -1;
00322    }
00323    return 0;
00324 }

int main ( int  argc,
char *  argv[] 
)

Definition at line 682 of file muted.c.

References astf, connect_asterisk(), debug, errno, load_config(), login_asterisk(), mixfd, needfork, NULL, open_mixer(), usage, and wait_event().

00683 {
00684    int x;
00685    while((x = getopt(argc, argv, "fhd")) > 0) {
00686       switch(x) {
00687       case 'd':
00688          debug = 1;
00689          needfork = 0;
00690          break;
00691       case 'f':
00692          needfork = 0;
00693          break;
00694       case 'h':
00695          /* Fall through */
00696       default:
00697          usage();
00698          exit(1);
00699       }
00700    }
00701    if (load_config())
00702       exit(1);
00703 #ifndef __Darwin__
00704    if (open_mixer())
00705       exit(1);
00706 #endif
00707    if (connect_asterisk()) {
00708 #ifndef __Darwin__
00709       close(mixfd);
00710 #endif
00711       exit(1);
00712    }
00713    if (login_asterisk()) {
00714 #ifndef __Darwin__      
00715       close(mixfd);
00716 #endif
00717       fclose(astf);
00718       exit(1);
00719    }
00720 #ifdef HAVE_WORKING_FORK
00721    if (needfork) {
00722 #ifndef HAVE_SBIN_LAUNCHD
00723       if (daemon(0,0) < 0) {
00724          fprintf(stderr, "daemon() failed: %s\n", strerror(errno));
00725          exit(1);
00726       }
00727 #else
00728       const char *found = NULL, *paths[] = {
00729          "/Library/LaunchAgents/org.asterisk.muted.plist",
00730          "/Library/LaunchDaemons/org.asterisk.muted.plist",
00731          "contrib/init.d/org.asterisk.muted.plist",
00732          "<path-to-asterisk-source>/contrib/init.d/org.asterisk.muted.plist" };
00733       char userpath[256];
00734       struct stat unused;
00735       struct passwd *pwd = getpwuid(getuid());
00736       int i;
00737 
00738       snprintf(userpath, sizeof(userpath), "%s%s", pwd->pw_dir, paths[0]);
00739       if (!stat(userpath, &unused)) {
00740          found = userpath;
00741       }
00742 
00743       if (!found) {
00744          for (i = 0; i < 3; i++) {
00745             if (!stat(paths[i], &unused)) {
00746                found = paths[i];
00747                break;
00748             }
00749          }
00750       }
00751 
00752       fprintf(stderr, "Mac OS X detected.  Use 'launchctl load -w %s' to launch.\n", found ? found : paths[3]);
00753       exit(1);
00754 #endif /* !defined(HAVE_SBIN_LAUNCHD */
00755    }
00756 #endif
00757    for(;;) {
00758       if (wait_event()) {
00759          fclose(astf);
00760          while(connect_asterisk()) {
00761             sleep(5);
00762          }
00763          if (login_asterisk()) {
00764             fclose(astf);
00765             exit(1);
00766          }
00767       }
00768    }
00769    exit(0);
00770 }

static void mute ( void   )  [static]

Definition at line 468 of file muted.c.

References debug, getvol(), muted, mutedlevel(), mutelevel, setvol(), smoothfade, and stepsize.

00469 {
00470 #ifndef __Darwin__
00471    int vol;
00472    int start;
00473    int x;
00474 #else
00475    float vol;
00476    float start = 1.0;
00477    float x;
00478 #endif
00479    vol = getvol();
00480    oldvol = vol;
00481    if (smoothfade)
00482 #ifdef __Darwin__ 
00483       start = mutelevel;
00484 #else
00485       start = 100;
00486    else
00487       start = mutelevel;
00488 #endif
00489    for (x=start;x>=mutelevel;x-=stepsize) {
00490       mutevol = mutedlevel(vol, x);
00491       setvol(mutevol);
00492       /* Wait 0.01 sec */
00493       usleep(10000);
00494    }
00495    mutevol = mutedlevel(vol, mutelevel);
00496    setvol(mutevol);
00497    if (debug)
00498 #ifdef __Darwin__
00499       printf("Mute from '%f' to '%f'!\n", oldvol, mutevol);
00500 #else
00501       printf("Mute from '%04x' to '%04x'!\n", oldvol, mutevol);
00502 #endif
00503    muted = 1;
00504 }

static int mutedlevel ( int  orig,
int  level 
) [static]

Definition at line 450 of file muted.c.

Referenced by mute(), and unmute().

00451 {
00452    int l = orig >> 8;
00453    int r = orig & 0xff;
00454    l = (float)(level) * (float)(l) / 100.0;
00455    r = (float)(level) * (float)(r) / 100.0;
00456 
00457    return (l << 8) | r;
00458 #else
00459 static float mutedlevel(float orig, float level)
00460 {
00461    float master = orig;
00462    master = level * master / 100.0;
00463    return master;
00464 #endif
00465    
00466 }

static void offhook_chan ( char *  channel  )  [static]

Definition at line 617 of file muted.c.

References append_sub(), check_mute(), debug, and find_channel().

Referenced by wait_event().

00618 {
00619    struct channel *chan;
00620    if (debug)
00621       printf("Offhook '%s'\n", channel);
00622    chan = find_channel(channel);
00623    if (chan)
00624       append_sub(chan, channel);
00625    check_mute();
00626 }

static int open_mixer ( void   )  [static]

Definition at line 213 of file muted.c.

References errno, and mixfd.

Referenced by main().

00214 {
00215    mixfd = open("/dev/mixer", O_RDWR);
00216    if (mixfd < 0) {
00217       fprintf(stderr, "Unable to open /dev/mixer: %s\n", strerror(errno));
00218       return -1;
00219    }
00220    return 0;
00221 }

static int setvol ( int  vol  )  [static]

Definition at line 400 of file muted.c.

References channels, errno, mixchan, mixfd, and NULL.

Referenced by mute(), and unmute().

00404 {
00405 #ifndef __Darwin__
00406    if (ioctl(mixfd, MIXER_WRITE(mixchan), &vol)) {
00407 #else 
00408    float volumeL = vol;
00409    float volumeR = vol;
00410    OSStatus err;
00411    AudioDeviceID device;
00412    UInt32 size;
00413    UInt32 channels[2];
00414    AudioObjectPropertyAddress OutputAddr = { kAudioHardwarePropertyDefaultOutputDevice, kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyElementMaster };
00415    AudioObjectPropertyAddress ChannelAddr = { kAudioDevicePropertyPreferredChannelsForStereo, kAudioDevicePropertyScopeOutput, kAudioObjectPropertyElementWildcard };
00416    AudioObjectPropertyAddress VolumeAddr = { kAudioDevicePropertyVolumeScalar, kAudioDevicePropertyScopeOutput, };
00417 
00418    size = sizeof(device);
00419    err = AudioObjectGetPropertyData(kAudioObjectSystemObject, &OutputAddr, 0, NULL, &size, &device);
00420    size = sizeof(channels);
00421    err = AudioObjectGetPropertyData(device, &ChannelAddr, 0, NULL, &size, &channels);
00422    size = sizeof(vol);
00423    if (!err) {
00424       VolumeAddr.mElement = channels[0];
00425       err = AudioObjectSetPropertyData(device, &VolumeAddr, 0, NULL, size, &volumeL);
00426    }
00427    if (!err) {
00428       VolumeAddr.mElement = channels[1];
00429       err = AudioObjectSetPropertyData(device, &VolumeAddr, 0, NULL, size, &volumeR);
00430    }
00431    if (err) {
00432 #endif
00433 
00434       fprintf(stderr, "Unable to write mixer volume: %s\n", strerror(errno));
00435       return -1;
00436 
00437    }
00438    return 0;
00439 }

static void unmute ( void   )  [static]

Definition at line 506 of file muted.c.

References debug, getvol(), muted, mutedlevel(), mutelevel, setvol(), smoothfade, and stepsize.

Referenced by check_mute().

00507 {
00508 #ifdef __Darwin__
00509    float vol;
00510    float start;
00511    float x;
00512 #else
00513    int vol;
00514    int start;
00515    int x;
00516 #endif
00517    vol = getvol();
00518    if (debug)
00519 #ifdef __Darwin__
00520       printf("Unmute from '%f' (should be '%f') to '%f'!\n", vol, mutevol, oldvol);
00521    mutevol = vol;
00522    if (vol == mutevol) {
00523 #else
00524       printf("Unmute from '%04x' (should be '%04x') to '%04x'!\n", vol, mutevol, oldvol);
00525    if ((int)vol == mutevol) {
00526 #endif
00527       if (smoothfade)
00528          start = mutelevel;
00529       else
00530 #ifdef __Darwin__
00531          start = 1.0;
00532 #else
00533          start = 100;
00534 #endif
00535       for (x=start;x<100;x+=stepsize) {
00536          mutevol = mutedlevel(oldvol, x);
00537          setvol(mutevol);
00538          /* Wait 0.01 sec */
00539          usleep(10000);
00540       }
00541       setvol(oldvol);
00542    } else
00543       printf("Whoops, it's already been changed!\n");
00544    muted = 0;
00545 }

static void usage ( void   )  [static]

Definition at line 675 of file muted.c.

00676 {
00677    printf("Usage: muted [-f] [-d]\n"
00678           "        -f : Do not fork\n"
00679           "        -d : Debug (implies -f)\n");
00680 }

static int wait_event ( void   )  [static]

Definition at line 628 of file muted.c.

References get_line(), hangup_chan(), and offhook_chan().

Referenced by main().

00629 {
00630    char *resp;
00631    char event[120]="";
00632    char channel[120]="";
00633    char oldname[120]="";
00634    char newname[120]="";
00635 
00636    resp = get_line();
00637    if (!resp) {
00638       fprintf(stderr, "disconnected (6)\n");
00639       return -1;
00640    }
00641    if (!strncasecmp(resp, "Event: ", strlen("Event: "))) {
00642       strncpy(event, resp + strlen("Event: "), sizeof(event) - 1);
00643       /* Consume the rest of the non-event */
00644       while((resp = get_line()) && strlen(resp)) {
00645          if (!strncasecmp(resp, "Channel: ", strlen("Channel: ")))
00646             strncpy(channel, resp + strlen("Channel: "), sizeof(channel) - 1);
00647          if (!strncasecmp(resp, "Newname: ", strlen("Newname: ")))
00648             strncpy(newname, resp + strlen("Newname: "), sizeof(newname) - 1);
00649          if (!strncasecmp(resp, "Oldname: ", strlen("Oldname: ")))
00650             strncpy(oldname, resp + strlen("Oldname: "), sizeof(oldname) - 1);
00651       }
00652       if (strlen(channel)) {
00653          if (!strcasecmp(event, "Hangup")) 
00654             hangup_chan(channel);
00655          else
00656             offhook_chan(channel);
00657       }
00658       if (strlen(newname) && strlen(oldname)) {
00659          if (!strcasecmp(event, "Rename")) {
00660             hangup_chan(oldname);
00661             offhook_chan(newname);
00662          }
00663       }
00664    } else {
00665       /* Consume the rest of the non-event */
00666       while((resp = get_line()) && strlen(resp));
00667    }
00668    if (!resp) {
00669       fprintf(stderr, "disconnected (7)\n");
00670       return -1;
00671    }
00672    return 0;
00673 }


Variable Documentation

FILE* astf [static]

Definition at line 209 of file muted.c.

Referenced by connect_asterisk(), get_line(), login_asterisk(), and main().

struct channel * channels [static]

char* config = "/etc/asterisk/muted.conf" [static]

Definition at line 75 of file muted.c.

int debug = 0 [static]

Definition at line 84 of file muted.c.

char host[256] = "" [static]

int mixchan = SOUND_MIXER_VOLUME [static]

Definition at line 87 of file muted.c.

Referenced by getvol(), and setvol().

int mixfd [static]

Definition at line 211 of file muted.c.

Referenced by getvol(), main(), open_mixer(), and setvol().

int muted = 0 [static]

int mutelevel = 20 [static]

Definition at line 81 of file muted.c.

Referenced by load_config(), mute(), and unmute().

int mutevol = 0 [static]

Definition at line 443 of file muted.c.

int needfork = 1 [static]

Definition at line 83 of file muted.c.

Referenced by main().

int oldvol = 0 [static]

Definition at line 442 of file muted.c.

char pass[256] = "" [static]

Definition at line 79 of file muted.c.

int smoothfade = 0 [static]

Definition at line 80 of file muted.c.

Referenced by load_config(), mute(), and unmute().

int stepsize = 3 [static]

Definition at line 85 of file muted.c.

Referenced by mute(), and unmute().

char user[256] = "" [static]

Definition at line 78 of file muted.c.


Generated on Thu Apr 16 06:32:03 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6