-///
-/// `use_strict_allowlist` should be true only when parsing a remote community, or when parsing a
-/// post/comment in a local community.
-#[tracing::instrument(skip(settings))]
-pub(crate) fn check_is_apub_id_valid(
- apub_id: &Url,
- use_strict_allowlist: bool,
- settings: &Settings,
-) -> Result<(), LemmyError> {
- let domain = apub_id.domain().context(location_info!())?.to_string();
- let local_instance = settings.get_hostname_without_port()?;
-
- if !settings.federation.enabled {
- return if domain == local_instance {
- Ok(())
- } else {
- let error = LemmyError::from(anyhow::anyhow!(
- "Trying to connect with {}, but federation is disabled",
- domain
- ));
- Err(error.with_message("federation_disabled"))
- };
- }
-
- let host = apub_id.host_str().context(location_info!())?;
- let host_as_ip = host.parse::<IpAddr>();
- if host == "localhost" || host_as_ip.is_ok() {
- let error = LemmyError::from(anyhow::anyhow!("invalid hostname {}: {}", host, apub_id));
- return Err(error.with_message("invalid_hostname"));
- }
-
- if apub_id.scheme() != settings.get_protocol_string() {
- let error = LemmyError::from(anyhow::anyhow!(
- "invalid apub id scheme {}: {}",
- apub_id.scheme(),
- apub_id
- ));
- return Err(error.with_message("invalid_scheme"));
+#[tracing::instrument(skip(local_site_data))]
+fn check_apub_id_valid(apub_id: &Url, local_site_data: &LocalSiteData) -> Result<(), &'static str> {
+ let domain = apub_id.domain().expect("apud id has domain").to_string();
+
+ if !local_site_data
+ .local_site
+ .as_ref()
+ .map(|l| l.federation_enabled)
+ .unwrap_or(true)
+ {
+ return Err("Federation disabled");