int pjsip_channel_cli_register(void) { channel_formatter = ao2_alloc(sizeof(struct ast_sip_cli_formatter_entry), NULL); if (!channel_formatter) { ast_log(LOG_ERROR, "Unable to allocate memory for channel_formatter\n"); return -1; } channel_formatter->name = "channel"; channel_formatter->print_header = cli_channel_print_header; channel_formatter->print_body = cli_channel_print_body; channel_formatter->get_container = cli_channel_get_container; channel_formatter->iterate = cli_channel_iterate; channel_formatter->retrieve_by_id = cli_channel_retrieve_by_id; channel_formatter->get_id = cli_channel_get_id; channelstats_formatter = ao2_alloc(sizeof(struct ast_sip_cli_formatter_entry), NULL); if (!channelstats_formatter) { ao2_ref(channel_formatter, -1); ast_log(LOG_ERROR, "Unable to allocate memory for channelstats_formatter\n"); return -1; } channelstats_formatter->name = "channelstat"; channelstats_formatter->print_header = cli_channelstats_print_header; channelstats_formatter->print_body = cli_channelstats_print_body; channelstats_formatter->get_container = cli_channelstats_get_container; channelstats_formatter->iterate = cli_channelstats_iterate; channelstats_formatter->retrieve_by_id = cli_channel_retrieve_by_id; channelstats_formatter->get_id = cli_channel_get_id; ast_sip_register_cli_formatter(channel_formatter); ast_sip_register_cli_formatter(channelstats_formatter); ast_cli_register_multiple(cli_commands, ARRAY_LEN(cli_commands)); return 0; }
/*! \brief Initialize sorcery with auth support */ int ast_sip_initialize_sorcery_auth(void) { struct ast_sorcery *sorcery = ast_sip_get_sorcery(); ast_sorcery_apply_default(sorcery, SIP_SORCERY_AUTH_TYPE, "config", "pjsip.conf,criteria=type=auth"); if (ast_sorcery_object_register(sorcery, SIP_SORCERY_AUTH_TYPE, auth_alloc, NULL, auth_apply)) { return -1; } ast_sorcery_object_field_register(sorcery, SIP_SORCERY_AUTH_TYPE, "type", "", OPT_NOOP_T, 0, 0); ast_sorcery_object_field_register(sorcery, SIP_SORCERY_AUTH_TYPE, "username", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_auth, auth_user)); ast_sorcery_object_field_register(sorcery, SIP_SORCERY_AUTH_TYPE, "password", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_auth, auth_pass)); ast_sorcery_object_field_register(sorcery, SIP_SORCERY_AUTH_TYPE, "md5_cred", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_auth, md5_creds)); ast_sorcery_object_field_register(sorcery, SIP_SORCERY_AUTH_TYPE, "realm", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_auth, realm)); ast_sorcery_object_field_register(sorcery, SIP_SORCERY_AUTH_TYPE, "nonce_lifetime", "32", OPT_UINT_T, 0, FLDSET(struct ast_sip_auth, nonce_lifetime)); ast_sorcery_object_field_register_custom(sorcery, SIP_SORCERY_AUTH_TYPE, "auth_type", "userpass", auth_type_handler, auth_type_to_str, NULL, 0, 0); ast_sip_register_endpoint_formatter(&endpoint_auth_formatter); cli_formatter = ao2_alloc(sizeof(struct ast_sip_cli_formatter_entry), NULL); if (!cli_formatter) { ast_log(LOG_ERROR, "Unable to allocate memory for cli formatter\n"); return -1; } cli_formatter->name = SIP_SORCERY_AUTH_TYPE; cli_formatter->print_header = cli_print_header; cli_formatter->print_body = cli_print_body; cli_formatter->get_container = cli_get_container; cli_formatter->iterate = cli_iterator; cli_formatter->get_id = ast_sorcery_object_get_id; cli_formatter->retrieve_by_id = cli_retrieve_by_id; ast_sip_register_cli_formatter(cli_formatter); ast_cli_register_multiple(cli_commands, ARRAY_LEN(cli_commands)); if (ast_manager_register_xml("PJSIPShowAuths", EVENT_FLAG_SYSTEM, ami_show_auths)) { return -1; } return 0; }
/*! \brief Initialize sorcery with location support */ int ast_sip_initialize_sorcery_location(void) { struct ast_sorcery *sorcery = ast_sip_get_sorcery(); int i; ast_sorcery_apply_default(sorcery, "contact", "astdb", "registrar"); ast_sorcery_apply_default(sorcery, "aor", "config", "pjsip.conf,criteria=type=aor"); if (ast_sorcery_object_register(sorcery, "contact", contact_alloc, NULL, contact_apply_handler) || ast_sorcery_object_register(sorcery, "aor", aor_alloc, NULL, NULL)) { return -1; } ast_sorcery_observer_add(sorcery, "aor", &aor_observer); ast_sorcery_object_field_register(sorcery, "contact", "type", "", OPT_NOOP_T, 0, 0); ast_sorcery_object_field_register(sorcery, "contact", "uri", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_contact, uri)); ast_sorcery_object_field_register(sorcery, "contact", "path", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_contact, path)); ast_sorcery_object_field_register_custom(sorcery, "contact", "expiration_time", "", expiration_str2struct, expiration_struct2str, NULL, 0, 0); ast_sorcery_object_field_register(sorcery, "contact", "qualify_frequency", 0, OPT_UINT_T, PARSE_IN_RANGE, FLDSET(struct ast_sip_contact, qualify_frequency), 0, 86400); ast_sorcery_object_field_register(sorcery, "contact", "qualify_timeout", "3.0", OPT_DOUBLE_T, 0, FLDSET(struct ast_sip_contact, qualify_timeout)); ast_sorcery_object_field_register(sorcery, "contact", "outbound_proxy", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_contact, outbound_proxy)); ast_sorcery_object_field_register(sorcery, "contact", "user_agent", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_contact, user_agent)); ast_sorcery_object_field_register(sorcery, "aor", "type", "", OPT_NOOP_T, 0, 0); ast_sorcery_object_field_register(sorcery, "aor", "minimum_expiration", "60", OPT_UINT_T, 0, FLDSET(struct ast_sip_aor, minimum_expiration)); ast_sorcery_object_field_register(sorcery, "aor", "maximum_expiration", "7200", OPT_UINT_T, 0, FLDSET(struct ast_sip_aor, maximum_expiration)); ast_sorcery_object_field_register(sorcery, "aor", "default_expiration", "3600", OPT_UINT_T, 0, FLDSET(struct ast_sip_aor, default_expiration)); ast_sorcery_object_field_register(sorcery, "aor", "qualify_frequency", 0, OPT_UINT_T, PARSE_IN_RANGE, FLDSET(struct ast_sip_aor, qualify_frequency), 0, 86400); ast_sorcery_object_field_register(sorcery, "aor", "qualify_timeout", "3.0", OPT_DOUBLE_T, 0, FLDSET(struct ast_sip_aor, qualify_timeout)); ast_sorcery_object_field_register(sorcery, "aor", "authenticate_qualify", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_aor, authenticate_qualify)); ast_sorcery_object_field_register(sorcery, "aor", "max_contacts", "0", OPT_UINT_T, 0, FLDSET(struct ast_sip_aor, max_contacts)); ast_sorcery_object_field_register(sorcery, "aor", "remove_existing", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_aor, remove_existing)); ast_sorcery_object_field_register_custom(sorcery, "aor", "contact", "", permanent_uri_handler, contacts_to_str, contacts_to_var_list, 0, 0); ast_sorcery_object_field_register(sorcery, "aor", "mailboxes", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_aor, mailboxes)); ast_sorcery_object_field_register(sorcery, "aor", "outbound_proxy", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_aor, outbound_proxy)); ast_sorcery_object_field_register(sorcery, "aor", "support_path", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_aor, support_path)); internal_sip_register_endpoint_formatter(&endpoint_aor_formatter); contact_formatter = ao2_alloc(sizeof(struct ast_sip_cli_formatter_entry), NULL); if (!contact_formatter) { ast_log(LOG_ERROR, "Unable to allocate memory for contact_formatter\n"); return -1; } contact_formatter->name = "contact"; contact_formatter->print_header = cli_contact_print_header; contact_formatter->print_body = cli_contact_print_body; contact_formatter->get_container = cli_contact_get_container; contact_formatter->iterate = cli_contact_iterate; contact_formatter->get_id = cli_contact_get_id; contact_formatter->retrieve_by_id = cli_contact_retrieve_by_id; aor_formatter = ao2_alloc(sizeof(struct ast_sip_cli_formatter_entry), NULL); if (!aor_formatter) { ast_log(LOG_ERROR, "Unable to allocate memory for aor_formatter\n"); return -1; } aor_formatter->name = "aor"; aor_formatter->print_header = cli_aor_print_header; aor_formatter->print_body = cli_aor_print_body; aor_formatter->get_container = cli_aor_get_container; aor_formatter->iterate = cli_aor_iterate; aor_formatter->get_id = cli_aor_get_id; aor_formatter->retrieve_by_id = cli_aor_retrieve_by_id; ast_sip_register_cli_formatter(contact_formatter); ast_sip_register_cli_formatter(aor_formatter); ast_cli_register_multiple(cli_commands, ARRAY_LEN(cli_commands)); /* * Reset StatsD gauges in case we didn't shut down cleanly. * Note that this must done here, as contacts will create the contact_status * object before PJSIP options handling is initialized. */ for (i = 0; i <= REMOVED; i++) { ast_statsd_log_full_va("PJSIP.contacts.states.%s", AST_STATSD_GAUGE, 0, 1.0, ast_sip_get_contact_status_label(i)); } return 0; }
int ast_sip_initialize_distributor(void) { unidentified_requests = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_RWLOCK, 0, DEFAULT_SUSPECTS_BUCKETS, suspects_hash, NULL, suspects_compare); if (!unidentified_requests) { return -1; } dialog_associations = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_RWLOCK, 0, DIALOG_ASSOCIATIONS_BUCKETS, dialog_associations_hash, NULL, dialog_associations_cmp); if (!dialog_associations) { ast_sip_destroy_distributor(); return -1; } if (distributor_pool_setup()) { ast_sip_destroy_distributor(); return -1; } prune_context = ast_sched_context_create(); if (!prune_context) { ast_sip_destroy_distributor(); return -1; } if (ast_sched_start_thread(prune_context)) { ast_sip_destroy_distributor(); return -1; } ast_sorcery_observer_add(ast_sip_get_sorcery(), "global", &global_observer); ast_sorcery_reload_object(ast_sip_get_sorcery(), "global"); if (create_artificial_endpoint() || create_artificial_auth()) { ast_sip_destroy_distributor(); return -1; } if (ast_sip_register_service(&distributor_mod)) { ast_sip_destroy_distributor(); return -1; } if (ast_sip_register_service(&endpoint_mod)) { ast_sip_destroy_distributor(); return -1; } if (ast_sip_register_service(&auth_mod)) { ast_sip_destroy_distributor(); return -1; } unid_formatter = ao2_alloc_options(sizeof(struct ast_sip_cli_formatter_entry), NULL, AO2_ALLOC_OPT_LOCK_NOLOCK); if (!unid_formatter) { ast_sip_destroy_distributor(); ast_log(LOG_ERROR, "Unable to allocate memory for unid_formatter\n"); return -1; } unid_formatter->name = "unidentified_request"; unid_formatter->print_header = cli_unid_print_header; unid_formatter->print_body = cli_unid_print_body; unid_formatter->get_container = cli_unid_get_container; unid_formatter->iterate = cli_unid_iterate; unid_formatter->get_id = cli_unid_get_id; unid_formatter->retrieve_by_id = cli_unid_retrieve_by_id; ast_sip_register_cli_formatter(unid_formatter); ast_cli_register_multiple(cli_commands, ARRAY_LEN(cli_commands)); return 0; }
/*! \brief Initialize sorcery with location support */ int ast_sip_initialize_sorcery_location(void) { struct ast_sorcery *sorcery = ast_sip_get_sorcery(); ast_sorcery_apply_default(sorcery, "contact", "astdb", "registrar"); ast_sorcery_apply_default(sorcery, "aor", "config", "pjsip.conf,criteria=type=aor"); if (ast_sorcery_object_register(sorcery, "contact", contact_alloc, NULL, NULL) || ast_sorcery_object_register(sorcery, "aor", aor_alloc, NULL, NULL)) { return -1; } ast_sorcery_object_field_register(sorcery, "contact", "type", "", OPT_NOOP_T, 0, 0); ast_sorcery_object_field_register(sorcery, "contact", "uri", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_contact, uri)); ast_sorcery_object_field_register(sorcery, "contact", "path", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_contact, path)); ast_sorcery_object_field_register_custom(sorcery, "contact", "expiration_time", "", expiration_str2struct, expiration_struct2str, NULL, 0, 0); ast_sorcery_object_field_register(sorcery, "contact", "qualify_frequency", 0, OPT_UINT_T, PARSE_IN_RANGE, FLDSET(struct ast_sip_contact, qualify_frequency), 0, 86400); ast_sorcery_object_field_register(sorcery, "contact", "outbound_proxy", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_contact, outbound_proxy)); ast_sorcery_object_field_register(sorcery, "contact", "user_agent", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_contact, user_agent)); ast_sorcery_object_field_register(sorcery, "aor", "type", "", OPT_NOOP_T, 0, 0); ast_sorcery_object_field_register(sorcery, "aor", "minimum_expiration", "60", OPT_UINT_T, 0, FLDSET(struct ast_sip_aor, minimum_expiration)); ast_sorcery_object_field_register(sorcery, "aor", "maximum_expiration", "7200", OPT_UINT_T, 0, FLDSET(struct ast_sip_aor, maximum_expiration)); ast_sorcery_object_field_register(sorcery, "aor", "default_expiration", "3600", OPT_UINT_T, 0, FLDSET(struct ast_sip_aor, default_expiration)); ast_sorcery_object_field_register(sorcery, "aor", "qualify_frequency", 0, OPT_UINT_T, PARSE_IN_RANGE, FLDSET(struct ast_sip_aor, qualify_frequency), 0, 86400); ast_sorcery_object_field_register(sorcery, "aor", "authenticate_qualify", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_aor, authenticate_qualify)); ast_sorcery_object_field_register(sorcery, "aor", "max_contacts", "0", OPT_UINT_T, 0, FLDSET(struct ast_sip_aor, max_contacts)); ast_sorcery_object_field_register(sorcery, "aor", "remove_existing", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_aor, remove_existing)); ast_sorcery_object_field_register_custom(sorcery, "aor", "contact", "", permanent_uri_handler, contacts_to_str, contacts_to_var_list, 0, 0); ast_sorcery_object_field_register(sorcery, "aor", "mailboxes", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_aor, mailboxes)); ast_sorcery_object_field_register(sorcery, "aor", "outbound_proxy", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_aor, outbound_proxy)); ast_sorcery_object_field_register(sorcery, "aor", "support_path", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_aor, support_path)); internal_sip_register_endpoint_formatter(&endpoint_aor_formatter); contact_formatter = ao2_alloc(sizeof(struct ast_sip_cli_formatter_entry), NULL); if (!contact_formatter) { ast_log(LOG_ERROR, "Unable to allocate memory for contact_formatter\n"); return -1; } contact_formatter->name = "contact"; contact_formatter->print_header = cli_contact_print_header; contact_formatter->print_body = cli_contact_print_body; contact_formatter->get_container = cli_contact_get_container; contact_formatter->iterate = cli_contact_iterate; contact_formatter->get_id = cli_contact_get_id; contact_formatter->retrieve_by_id = cli_contact_retrieve_by_id; aor_formatter = ao2_alloc(sizeof(struct ast_sip_cli_formatter_entry), NULL); if (!aor_formatter) { ast_log(LOG_ERROR, "Unable to allocate memory for aor_formatter\n"); return -1; } aor_formatter->name = "aor"; aor_formatter->print_header = cli_aor_print_header; aor_formatter->print_body = cli_aor_print_body; aor_formatter->get_container = cli_aor_get_container; aor_formatter->iterate = cli_aor_iterate; aor_formatter->get_id = cli_aor_get_id; aor_formatter->retrieve_by_id = cli_aor_retrieve_by_id; ast_sip_register_cli_formatter(contact_formatter); ast_sip_register_cli_formatter(aor_formatter); ast_cli_register_multiple(cli_commands, ARRAY_LEN(cli_commands)); return 0; }