conduit/src/main.rs

167 lines
7.1 KiB
Rust
Raw Normal View History

#![warn(rust_2018_idioms)]
pub mod appservice_server;
pub mod client_server;
2020-08-14 12:34:15 +03:00
pub mod server_server;
2020-06-12 14:18:25 +03:00
mod database;
mod error;
2020-04-04 12:53:37 +03:00
mod pdu;
2020-08-14 12:34:15 +03:00
mod push_rules;
2020-02-16 00:42:21 +03:00
mod ruma_wrapper;
2020-03-29 14:48:44 +03:00
mod utils;
2020-02-16 00:42:21 +03:00
pub use database::Database;
pub use error::{ConduitLogger, Error, Result};
use log::LevelFilter;
2020-04-04 12:53:37 +03:00
pub use pdu::PduEvent;
pub use rocket::State;
2020-06-09 16:13:17 +03:00
pub use ruma_wrapper::{ConduitResult, Ruma, RumaResponse};
2020-12-19 18:00:11 +03:00
use rocket::{catch, catchers, fairing::AdHoc, routes, Request};
2020-04-29 09:48:56 +03:00
fn setup_rocket() -> rocket::Rocket {
// Force log level off, so we can use our own logger
std::env::set_var("ROCKET_LOG_LEVEL", "off");
2020-02-16 00:42:21 +03:00
rocket::ignite()
2020-02-19 00:07:57 +03:00
.mount(
"/",
routes![
2020-04-11 10:30:11 +03:00
client_server::get_supported_versions_route,
client_server::get_register_available_route,
2020-04-11 10:30:11 +03:00
client_server::register_route,
2020-07-31 15:40:28 +03:00
client_server::get_login_types_route,
2020-04-11 10:30:11 +03:00
client_server::login_route,
2020-07-27 18:38:00 +03:00
client_server::whoami_route,
client_server::logout_route,
2020-07-05 09:35:19 +03:00
client_server::logout_all_route,
client_server::change_password_route,
client_server::deactivate_route,
2020-04-19 15:14:47 +03:00
client_server::get_capabilities_route,
2020-04-11 10:30:11 +03:00
client_server::get_pushrules_all_route,
client_server::set_pushrule_route,
client_server::set_pushrule_enabled_route,
client_server::get_room_event_route,
2020-04-11 10:30:11 +03:00
client_server::get_filter_route,
client_server::create_filter_route,
client_server::set_global_account_data_route,
client_server::get_global_account_data_route,
client_server::set_displayname_route,
client_server::get_displayname_route,
client_server::set_avatar_url_route,
client_server::get_avatar_url_route,
client_server::get_profile_route,
client_server::set_presence_route,
client_server::upload_keys_route,
2020-05-17 20:56:40 +03:00
client_server::get_keys_route,
client_server::claim_keys_route,
2020-06-16 13:11:38 +03:00
client_server::create_backup_route,
client_server::update_backup_route,
client_server::delete_backup_route,
2020-06-16 13:11:38 +03:00
client_server::get_latest_backup_route,
client_server::get_backup_route,
client_server::add_backup_key_sessions_route,
2020-06-16 13:11:38 +03:00
client_server::add_backup_keys_route,
client_server::delete_backup_key_session_route,
client_server::delete_backup_key_sessions_route,
client_server::delete_backup_keys_route,
client_server::get_backup_key_session_route,
client_server::get_backup_key_sessions_route,
2020-06-16 13:11:38 +03:00
client_server::get_backup_keys_route,
2020-04-11 10:30:11 +03:00
client_server::set_read_marker_route,
2020-12-19 18:00:11 +03:00
client_server::set_receipt_route,
2020-04-12 22:12:50 +03:00
client_server::create_typing_event_route,
2020-04-11 10:30:11 +03:00
client_server::create_room_route,
2020-05-26 00:24:13 +03:00
client_server::redact_event_route,
client_server::create_alias_route,
client_server::delete_alias_route,
2020-04-11 10:30:11 +03:00
client_server::get_alias_route,
client_server::join_room_by_id_route,
client_server::join_room_by_id_or_alias_route,
client_server::joined_members_route,
2020-04-19 15:14:47 +03:00
client_server::leave_room_route,
2020-04-28 20:56:34 +03:00
client_server::forget_room_route,
client_server::joined_rooms_route,
2020-06-04 16:02:27 +03:00
client_server::kick_user_route,
client_server::ban_user_route,
client_server::unban_user_route,
client_server::invite_user_route,
2020-05-26 00:24:13 +03:00
client_server::set_room_visibility_route,
client_server::get_room_visibility_route,
2020-05-19 17:28:03 +03:00
client_server::get_public_rooms_route,
2020-04-11 10:30:11 +03:00
client_server::get_public_rooms_filtered_route,
client_server::search_users_route,
2020-04-19 15:14:47 +03:00
client_server::get_member_events_route,
2020-04-11 10:30:11 +03:00
client_server::get_protocols_route,
2020-08-13 00:32:39 +03:00
client_server::send_message_event_route,
client_server::send_state_event_for_key_route,
client_server::send_state_event_for_empty_key_route,
2020-05-18 10:22:07 +03:00
client_server::get_state_events_route,
client_server::get_state_events_for_key_route,
client_server::get_state_events_for_empty_key_route,
client_server::sync_events_route,
2020-06-04 14:58:55 +03:00
client_server::get_context_route,
2020-04-28 20:56:34 +03:00
client_server::get_message_events_route,
2020-08-18 13:15:27 +03:00
client_server::search_events_route,
client_server::turn_server_route,
client_server::send_event_to_device_route,
client_server::get_media_config_route,
2020-05-18 18:53:34 +03:00
client_server::create_content_route,
client_server::get_content_route,
client_server::get_content_thumbnail_route,
client_server::get_devices_route,
client_server::get_device_route,
client_server::update_device_route,
client_server::delete_device_route,
client_server::delete_devices_route,
client_server::get_tags_route,
client_server::update_tag_route,
client_server::delete_tag_route,
2020-04-11 10:30:11 +03:00
client_server::options_route,
2020-06-16 13:11:38 +03:00
client_server::upload_signing_keys_route,
client_server::upload_signatures_route,
2020-07-29 18:37:26 +03:00
client_server::get_key_changes_route,
2020-07-30 19:14:47 +03:00
client_server::get_pushers_route,
2020-06-16 13:11:38 +03:00
client_server::set_pushers_route,
2020-08-06 14:21:53 +03:00
client_server::upgrade_room_route,
server_server::get_server_version_route,
server_server::get_server_keys_route,
server_server::get_server_keys_deprecated_route,
server_server::get_public_rooms_route,
server_server::get_public_rooms_filtered_route,
server_server::send_transaction_message_route,
server_server::get_missing_events_route,
2020-10-05 23:19:22 +03:00
server_server::get_profile_information_route,
2020-02-19 00:07:57 +03:00
],
)
2020-12-19 18:00:11 +03:00
.register(catchers![not_found_catcher])
.attach(AdHoc::on_attach("Config", |rocket| async {
let data =
Database::load_or_create(rocket.figment().extract().expect("config is valid"))
2020-12-06 13:05:51 +03:00
.await
.expect("config is valid");
2020-04-29 09:48:56 +03:00
data.sending
.start_handler(&data.globals, &data.rooms, &data.appservice);
log::set_boxed_logger(Box::new(ConduitLogger {
db: data.clone(),
last_logs: Default::default(),
}))
.unwrap();
log::set_max_level(LevelFilter::Info);
2020-09-15 17:13:54 +03:00
2020-04-29 09:48:56 +03:00
Ok(rocket.manage(data))
}))
}
2020-06-16 14:53:15 +03:00
#[rocket::main]
async fn main() {
setup_rocket().launch().await.unwrap();
2020-02-16 00:42:21 +03:00
}
2020-12-19 18:00:11 +03:00
#[catch(404)]
fn not_found_catcher(_req: &'_ Request<'_>) -> String {
"404 Not Found".to_owned()
}