an http based roguelike rpg about jelqing
Blame: src/game/dispatch.rs
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 1 | use super::{ |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 2 | Floor, Lube, Outcome, Run, Story, Technique, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 3 | techniques::{Training, Utility}, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 4 | }; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 5 | use crate::problem::Problem; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 6 | use axum::http::{StatusCode, header}; |
98432b6057aa | atagen | 2026-10-14 09:03 UTC | 7 | use serde_json::{Value, json}; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 8 | use std::{fmt::Write as _, ops::ControlFlow}; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 9 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 10 | impl Run { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 11 | pub fn jelq( |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 12 | &mut self, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 13 | techniques: &[Technique], |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 14 | intensity: i32, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 15 | lube: Option<Lube>, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 16 | ) -> Result<Outcome, Problem> { |
a11497af08aa | atagen | 2026-10-13 12:04 UTC | 17 | if techniques != [Technique::Utility(Utility::Energy)] { |
a11497af08aa | atagen | 2026-10-13 12:04 UTC | 18 | self.check_exhausted()?; |
a11497af08aa | atagen | 2026-10-13 12:04 UTC | 19 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 20 | if self.online.story == Story::Pending { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 21 | return Ok(self.branch_offer()); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 22 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 23 | if self.floor == Floor::Forum { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 24 | return Ok(Outcome::json( |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 25 | StatusCode::SEE_OTHER, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 26 | json!({ "detail": "Refer to the forum." }), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 27 | ) |
a11497af08aa | atagen | 2026-10-13 12:04 UTC | 28 | .header(header::LOCATION, self.path("/thread"))); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 29 | } |
4f54028cba69 | atagen | 2026-10-14 11:45 UTC | 30 | self.check_cage()?; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 31 | match *techniques { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 32 | [Technique::Utility(utility)] => self.utility(utility, lube), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 33 | [Technique::Training(training)] => self.single(training, intensity, lube), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 34 | [Technique::Training(a), Technique::Training(b)] => self.combo(a, b, intensity, lube), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 35 | [_, _] => Err(Problem::new( |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 36 | StatusCode::BAD_REQUEST, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 37 | "combo-invalid", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 38 | "Only training techniques can be combined.", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 39 | )), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 40 | _ => Err(Problem::new( |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 41 | StatusCode::BAD_REQUEST, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 42 | "too-many-techniques", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 43 | "Two techniques at most. The server has limits even if you do not.", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 44 | )), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 45 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 46 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 47 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 48 | pub(super) fn utility( |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 49 | &mut self, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 50 | utility: Utility, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 51 | lube: Option<Lube>, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 52 | ) -> Result<Outcome, Problem> { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 53 | match utility { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 54 | Utility::Warmup => return self.warm_up(), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 55 | Utility::Ice => return self.ice(), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 56 | Utility::Supplement => return self.supplement(), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 57 | Utility::Meditate => return self.meditate(), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 58 | Utility::Energy => return self.energy(), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 59 | Utility::Edge | Utility::Pump => {} |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 60 | } |
bad9f5b8202f | atagen | 2026-10-14 09:23 UTC | 61 | let lube = lube.filter(|_| utility == Utility::Edge); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 62 | self.ready(Technique::Utility(utility), lube)?; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 63 | self.check_storage()?; |
bad9f5b8202f | atagen | 2026-10-14 09:23 UTC | 64 | self.lube_available(lube)?; |
6033b0db186c | atagen | 2026-10-13 12:44 UTC | 65 | self.check_clock()?; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 66 | self.floor_enemy()?; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 67 | match utility { |
bad9f5b8202f | atagen | 2026-10-14 09:23 UTC | 68 | Utility::Edge => self.edge(lube), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 69 | _ => self.pump(), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 70 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 71 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 72 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 73 | pub(super) fn single( |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 74 | &mut self, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 75 | training: Training, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 76 | intensity: i32, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 77 | lube: Option<Lube>, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 78 | ) -> Result<Outcome, Problem> { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 79 | self.ready(Technique::Training(training), lube)?; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 80 | self.check_storage()?; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 81 | self.lube_available(lube)?; |
6033b0db186c | atagen | 2026-10-13 12:44 UTC | 82 | self.check_clock()?; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 83 | self.floor_enemy()?; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 84 | self.take_lube(lube)?; |
bf5f8cb6f60f | atagen | 2026-10-13 12:10 UTC | 85 | let cold = self.cold(); |
bf5f8cb6f60f | atagen | 2026-10-13 12:10 UTC | 86 | self.chafe(lube, intensity, cold); |
3ac624339c98 | atagen | 2026-10-13 12:21 UTC | 87 | self.commit(intensity, lube, 1)?; |
bf5f8cb6f60f | atagen | 2026-10-13 12:10 UTC | 88 | if let ControlFlow::Break(interrupted) = self.mishaps(training, intensity, cold)? { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 89 | return Ok(interrupted); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 90 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 91 | if let ControlFlow::Break(interrupted) = self.hazards(intensity)? { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 92 | return Ok(interrupted); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 93 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 94 | let outcome = self.roll(training, intensity, lube)?; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 95 | Ok(self.gossip(outcome)) |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 96 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 97 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 98 | pub(super) fn combo( |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 99 | &mut self, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 100 | a: Training, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 101 | b: Training, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 102 | intensity: i32, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 103 | lube: Option<Lube>, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 104 | ) -> Result<Outcome, Problem> { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 105 | if a == b { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 106 | return Err(Problem::new( |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 107 | StatusCode::BAD_REQUEST, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 108 | "combo-invalid", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 109 | "A technique cannot be combined with itself. The server has checked.", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 110 | )); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 111 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 112 | self.ready(Technique::Training(a), lube)?; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 113 | self.ready(Technique::Training(b), lube)?; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 114 | self.check_storage()?; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 115 | self.lube_available(lube)?; |
6033b0db186c | atagen | 2026-10-13 12:44 UTC | 116 | self.check_clock()?; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 117 | self.floor_enemy()?; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 118 | self.take_lube(lube)?; |
bf5f8cb6f60f | atagen | 2026-10-13 12:10 UTC | 119 | let cold = self.cold(); |
bf5f8cb6f60f | atagen | 2026-10-13 12:10 UTC | 120 | self.chafe(lube, intensity, cold); |
bf5f8cb6f60f | atagen | 2026-10-13 12:10 UTC | 121 | self.chafe(lube, intensity, cold); |
3ac624339c98 | atagen | 2026-10-13 12:21 UTC | 122 | self.commit(intensity, lube, 2)?; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 123 | for training in [a, b] { |
bf5f8cb6f60f | atagen | 2026-10-13 12:10 UTC | 124 | if let ControlFlow::Break(interrupted) = self.mishaps(training, intensity, cold)? { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 125 | return Ok(interrupted); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 126 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 127 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 128 | if let ControlFlow::Break(interrupted) = self.hazards(intensity)? { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 129 | return Ok(interrupted); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 130 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 131 | |
98432b6057aa | atagen | 2026-10-14 09:03 UTC | 132 | let mut reports = Vec::new(); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 133 | for training in [a, b] { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 134 | let result = self.roll(training, intensity, lube); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 135 | if self.ended.is_some() { |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 136 | return result; |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 137 | } |
98432b6057aa | atagen | 2026-10-14 09:03 UTC | 138 | reports.push(( |
98432b6057aa | atagen | 2026-10-14 09:03 UTC | 139 | training, |
98432b6057aa | atagen | 2026-10-14 09:03 UTC | 140 | Report::of(result.map(|outcome| self.gossip(outcome))), |
98432b6057aa | atagen | 2026-10-14 09:03 UTC | 141 | )); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 142 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 143 | |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 144 | let mut xml = String::from( |
27256acf2780 | atagen | 2026-10-14 13:42 UTC | 145 | "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<D:multistatus xmlns:D=\"DAV:\" xmlns:J=\"https://jelq.dev/\">\n", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 146 | ); |
98432b6057aa | atagen | 2026-10-14 09:03 UTC | 147 | for (training, report) in reports { |
27256acf2780 | atagen | 2026-10-14 13:42 UTC | 148 | report.write( |
27256acf2780 | atagen | 2026-10-14 13:42 UTC | 149 | &mut xml, |
27256acf2780 | atagen | 2026-10-14 13:42 UTC | 150 | &format!("{}?technique={}", self.path(""), training.name()), |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 151 | ); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 152 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 153 | xml.push_str( |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 154 | " <D:responsedescription>Each technique has been reported separately.</D:responsedescription>\n</D:multistatus>\n", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 155 | ); |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 156 | Ok(Outcome::raw( |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 157 | StatusCode::MULTI_STATUS, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 158 | "application/xml; charset=utf-8", |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 159 | xml, |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 160 | )) |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 161 | } |
8b8e83329a1d | atagen | 2026-10-12 12:01 UTC | 162 | } |
98432b6057aa | atagen | 2026-10-14 09:03 UTC | 163 | |
98432b6057aa | atagen | 2026-10-14 09:03 UTC | 164 | /// What one technique of a combo would have answered on its own. |
98432b6057aa | atagen | 2026-10-14 09:03 UTC | 165 | struct Report { |
98432b6057aa | atagen | 2026-10-14 09:03 UTC | 166 | status: StatusCode, |
27256acf2780 | atagen | 2026-10-14 13:42 UTC | 167 | error: Option<&'static str>, |
27256acf2780 | atagen | 2026-10-14 13:42 UTC | 168 | detail: Option<String>, |
27256acf2780 | atagen | 2026-10-14 13:42 UTC | 169 | fields: Vec<(String, String)>, |
98432b6057aa | atagen | 2026-10-14 09:03 UTC | 170 | location: Option<String>, |
98432b6057aa | atagen | 2026-10-14 09:03 UTC | 171 | } |
98432b6057aa | atagen | 2026-10-14 09:03 UTC | 172 | |
98432b6057aa | atagen | 2026-10-14 09:03 UTC | 173 | impl Report { |
98432b6057aa | atagen | 2026-10-14 09:03 UTC | 174 | fn of(result: Result<Outcome, Problem>) -> Self { |
27256acf2780 | atagen | 2026-10-14 13:42 UTC | 175 | let (status, error, location, body) = match result { |
27256acf2780 | atagen | 2026-10-14 13:42 UTC | 176 | Ok(outcome) => ( |
27256acf2780 | atagen | 2026-10-14 13:42 UTC | 177 | outcome.status(), |
27256acf2780 | atagen | 2026-10-14 13:42 UTC | 178 | None, |
27256acf2780 | atagen | 2026-10-14 13:42 UTC | 179 | outcome.header_value(&header::LOCATION).map(str::to_owned), |
27256acf2780 | atagen | 2026-10-14 13:42 UTC | 180 | outcome.body().and_then(Value::as_object).cloned(), |
27256acf2780 | atagen | 2026-10-14 13:42 UTC | 181 | ), |
27256acf2780 | atagen | 2026-10-14 13:42 UTC | 182 | Err(problem) => { |
27256acf2780 | atagen | 2026-10-14 13:42 UTC | 183 | let mut document = problem.document(); |
27256acf2780 | atagen | 2026-10-14 13:42 UTC | 184 | for repeated in ["type", "title", "status"] { |
27256acf2780 | atagen | 2026-10-14 13:42 UTC | 185 | document.remove(repeated); |
27256acf2780 | atagen | 2026-10-14 13:42 UTC | 186 | } |
27256acf2780 | atagen | 2026-10-14 13:42 UTC | 187 | (problem.status(), Some(problem.slug()), None, Some(document)) |
27256acf2780 | atagen | 2026-10-14 13:42 UTC | 188 | } |
27256acf2780 | atagen | 2026-10-14 13:42 UTC | 189 | }; |
27256acf2780 | atagen | 2026-10-14 13:42 UTC | 190 | let mut body = body.unwrap_or_default(); |
27256acf2780 | atagen | 2026-10-14 13:42 UTC | 191 | let detail = body |
27256acf2780 | atagen | 2026-10-14 13:42 UTC | 192 | .remove("detail") |
27256acf2780 | atagen | 2026-10-14 13:42 UTC | 193 | .and_then(|detail| detail.as_str().map(str::to_owned)); |
27256acf2780 | atagen | 2026-10-14 13:42 UTC | 194 | let fields = body |
27256acf2780 | atagen | 2026-10-14 13:42 UTC | 195 | .into_iter() |
27256acf2780 | atagen | 2026-10-14 13:42 UTC | 196 | .map(|(key, value)| match value { |
27256acf2780 | atagen | 2026-10-14 13:42 UTC | 197 | Value::String(text) => (key, text), |
27256acf2780 | atagen | 2026-10-14 13:42 UTC | 198 | other => (key, other.to_string()), |
27256acf2780 | atagen | 2026-10-14 13:42 UTC | 199 | }) |
27256acf2780 | atagen | 2026-10-14 13:42 UTC | 200 | .collect(); |
27256acf2780 | atagen | 2026-10-14 13:42 UTC | 201 | Self { |
27256acf2780 | atagen | 2026-10-14 13:42 UTC | 202 | status, |
27256acf2780 | atagen | 2026-10-14 13:42 UTC | 203 | error, |
27256acf2780 | atagen | 2026-10-14 13:42 UTC | 204 | detail, |
27256acf2780 | atagen | 2026-10-14 13:42 UTC | 205 | fields, |
27256acf2780 | atagen | 2026-10-14 13:42 UTC | 206 | location, |
27256acf2780 | atagen | 2026-10-14 13:42 UTC | 207 | } |
27256acf2780 | atagen | 2026-10-14 13:42 UTC | 208 | } |
27256acf2780 | atagen | 2026-10-14 13:42 UTC | 209 | |
27256acf2780 | atagen | 2026-10-14 13:42 UTC | 210 | /// In RFC 4918's order, with anything the game adds after it under its own namespace. |
27256acf2780 | atagen | 2026-10-14 13:42 UTC | 211 | fn write(&self, xml: &mut String, href: &str) { |
27256acf2780 | atagen | 2026-10-14 13:42 UTC | 212 | let _ = write!( |
27256acf2780 | atagen | 2026-10-14 13:42 UTC | 213 | xml, |
27256acf2780 | atagen | 2026-10-14 13:42 UTC | 214 | " <D:response>\n <D:href>{}</D:href>\n <D:status>HTTP/1.1 {} {}</D:status>\n", |
27256acf2780 | atagen | 2026-10-14 13:42 UTC | 215 | escape(href), |
27256acf2780 | atagen | 2026-10-14 13:42 UTC | 216 | self.status.as_u16(), |
27256acf2780 | atagen | 2026-10-14 13:42 UTC | 217 | crate::problem::reason(self.status), |
27256acf2780 | atagen | 2026-10-14 13:42 UTC | 218 | ); |
27256acf2780 | atagen | 2026-10-14 13:42 UTC | 219 | if let Some(error) = self.error { |
27256acf2780 | atagen | 2026-10-14 13:42 UTC | 220 | let _ = writeln!(xml, " <D:error><J:{error}/></D:error>"); |
27256acf2780 | atagen | 2026-10-14 13:42 UTC | 221 | } |
27256acf2780 | atagen | 2026-10-14 13:42 UTC | 222 | if let Some(detail) = &self.detail { |
27256acf2780 | atagen | 2026-10-14 13:42 UTC | 223 | let _ = writeln!( |
27256acf2780 | atagen | 2026-10-14 13:42 UTC | 224 | xml, |
27256acf2780 | atagen | 2026-10-14 13:42 UTC | 225 | " <D:responsedescription>{}</D:responsedescription>", |
27256acf2780 | atagen | 2026-10-14 13:42 UTC | 226 | escape(detail) |
27256acf2780 | atagen | 2026-10-14 13:42 UTC | 227 | ); |
27256acf2780 | atagen | 2026-10-14 13:42 UTC | 228 | } |
27256acf2780 | atagen | 2026-10-14 13:42 UTC | 229 | if let Some(location) = &self.location { |
27256acf2780 | atagen | 2026-10-14 13:42 UTC | 230 | let _ = writeln!( |
27256acf2780 | atagen | 2026-10-14 13:42 UTC | 231 | xml, |
27256acf2780 | atagen | 2026-10-14 13:42 UTC | 232 | " <D:location><D:href>{}</D:href></D:location>", |
27256acf2780 | atagen | 2026-10-14 13:42 UTC | 233 | escape(location) |
27256acf2780 | atagen | 2026-10-14 13:42 UTC | 234 | ); |
27256acf2780 | atagen | 2026-10-14 13:42 UTC | 235 | } |
27256acf2780 | atagen | 2026-10-14 13:42 UTC | 236 | for (key, value) in &self.fields { |
27256acf2780 | atagen | 2026-10-14 13:42 UTC | 237 | let _ = writeln!(xml, " <J:{key}>{}</J:{key}>", escape(value)); |
98432b6057aa | atagen | 2026-10-14 09:03 UTC | 238 | } |
27256acf2780 | atagen | 2026-10-14 13:42 UTC | 239 | xml.push_str(" </D:response>\n"); |
98432b6057aa | atagen | 2026-10-14 09:03 UTC | 240 | } |
98432b6057aa | atagen | 2026-10-14 09:03 UTC | 241 | } |
98432b6057aa | atagen | 2026-10-14 09:03 UTC | 242 | |
98432b6057aa | atagen | 2026-10-14 09:03 UTC | 243 | fn escape(text: &str) -> String { |
98432b6057aa | atagen | 2026-10-14 09:03 UTC | 244 | text.replace('&', "&") |
98432b6057aa | atagen | 2026-10-14 09:03 UTC | 245 | .replace('<', "<") |
98432b6057aa | atagen | 2026-10-14 09:03 UTC | 246 | .replace('>', ">") |
98432b6057aa | atagen | 2026-10-14 09:03 UTC | 247 | } |