Skip to content

Commit 9f4c5d9

Browse files
committed
Profile toml multiple line desc
1 parent 0ac25fc commit 9f4c5d9

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

ytflow-app-util/include/ytflow_core.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ struct ytflow_result ytflow_profile_update(uint32_t profile_id,
8686

8787
struct ytflow_result ytflow_profile_delete(uint32_t profile_id, const ytflow_connection *conn);
8888

89+
struct ytflow_result ytflow_profile_export_toml(uint32_t profile_id, const ytflow_connection *conn);
90+
91+
struct ytflow_result ytflow_profile_parse_toml(const uint8_t *toml, uintptr_t toml_len);
92+
8993
struct ytflow_result ytflow_plugin_create(uint32_t profile_id,
9094
const char *name,
9195
const char *desc,

ytflow-app-util/src/profile/export.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,13 @@ pub fn export_profile_toml(
133133
.desc
134134
.trim()
135135
.lines()
136-
.map(|l| format!("\n# {}", l.trim()))
136+
.map(|l| {
137+
if l.is_empty() {
138+
"\n#".into()
139+
} else {
140+
format!("\n# {}", l.trim())
141+
}
142+
})
137143
.collect::<Vec<_>>()
138144
.join("");
139145
decor.push_str("\n");
@@ -217,7 +223,7 @@ mod tests {
217223
Plugin::create(
218224
profile_id,
219225
"custom-rule-dispatcher".into(),
220-
"Dispatch connections \n based on custom rules".into(),
226+
"Dispatch connections \n\n based on custom rules".into(),
221227
"rule-dispatcher".into(),
222228
0,
223229
to_cbor(cbor!({
@@ -312,6 +318,7 @@ param.rules = [{ is_udp = true, src = { ip_ranges = ["0.0.0.0/0"], port_ranges =
312318
updated_at = 2024-04-27T09:43:17.191
313319
314320
# Dispatch connections
321+
#
315322
# based on custom rules
316323
[plugins.custom-rule-dispatcher]
317324
plugin = "rule-dispatcher"

ytflow-app-util/src/profile/import.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,14 +167,11 @@ pub fn parse_profile_toml(toml: &[u8]) -> ParseTomlProfileResult<ParsedTomlProfi
167167
.prefix()
168168
.and_then(|p| Some(unsafe { toml.get_unchecked(p.span()?) }))
169169
.unwrap_or_default()
170-
.trim()
171170
.lines()
172-
.map(|l| {
173-
l.trim_start_matches(|c: char| c.is_whitespace() || c == '#')
174-
.trim_end()
175-
})
171+
.filter_map(|l| l.trim_start().strip_prefix('#'))
172+
.map(|l| l.trim())
176173
.collect::<Vec<_>>()
177-
.join(" ");
174+
.join("\n");
178175
let plugin = plugin_table
179176
.get("plugin")
180177
.ok_or_else(|| {
@@ -271,6 +268,8 @@ param.rules = [{ is_udp = true, src = { ip_ranges = ["0.0.0.0/0"], port_ranges =
271268
updated_at = 2024-04-27T09:43:17.191
272269
273270
# Dispatch connections
271+
#
272+
274273
# based on custom rules
275274
[plugins.custom-rule-dispatcher]
276275
plugin = "rule-dispatcher"
@@ -412,6 +411,10 @@ updated_at = 2024-04-27T09:43:17.191
412411
.iter()
413412
.find(|p| p.plugin.name == "custom-rule-dispatcher")
414413
.unwrap();
414+
assert_eq!(
415+
custom_rule_dispatcher.plugin.desc,
416+
"Dispatch connections\n\nbased on custom rules"
417+
);
415418
assert_eq!(custom_rule_dispatcher.plugin.plugin, "rule-dispatcher");
416419
assert_eq!(custom_rule_dispatcher.plugin.plugin_version, 0);
417420
assert_eq!(

0 commit comments

Comments
 (0)