1
0
mirror of https://github.com/aziascreations/BakaShrot.git synced 2026-11-23 20:58:46 +01:00

Added filtered name lists and the DLL's enumerations, Opened the query connection read-only, Bumped to 0.4.0

- Protocol 8: ListTopics / ListNodes became one ListNames [kind, topics,
  nodes], each filter a name or a pattern: the topics a node pushed to,
  the nodes that pushed to a topic, wildcards included. No storage
  change; the permissions are the lists' (may_list_topic,
  may_list_nodes_of)
- The DLL: the JSON getters are suffixed AsJson (GetNamesListAsJson,
  GetQueryResultAsJson); ListNamesA/W replaces ListTopics / ListNodes.
  Beside them, Win32-like enumerations: EnumerateNames / EnumerateQuery,
  NextName / NextQueryRow (before the first item at first), getters,
  CloseEnum (enumerations.rs). They don't outlive their client:
  FreeClient closes them
- C#: EnumerateTopics / EnumerateNodes / EnumerateQuery as IEnumerable
  (QueryRow for a query), fetched at each foreach, closed in finally
- Queries: the connection opens the file read-only
  (SQLITE_OPEN_READ_ONLY), a fifth guard beside query_only, the
  read-only statement check, one statement only and the PRAGMA-denying
  authorizer; a unit test checks the handle is read-only
- Python, PureBasic, the tool, docs, guides and revamp.md (step 16)
  updated; versions 0.4.0 everywhere

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-19 20:19:04 +01:00
parent 1a1603f3f3
commit c513d8bf05
41 changed files with 1625 additions and 297 deletions
+3 -3
View File
@@ -169,11 +169,11 @@ mod tests {
fn versions() {
let mut stream = Vec::new();
write_version(&mut stream).unwrap();
assert_eq!(stream, [7, 0, 0, 0]);
assert_eq!(stream, [8, 0, 0, 0]);
let bytes = read_version(&mut &stream[..]).unwrap();
assert_eq!(check_version(bytes), Ok(()));
assert_eq!(check_version([6, 0, 0, 0]), Err(6));
assert_eq!(check_version([8, 0, 0, 0]), Err(8));
assert_eq!(check_version([7, 0, 0, 0]), Err(7));
assert_eq!(check_version([9, 0, 0, 0]), Err(9));
assert!(read_version(&mut &[7u8, 0][..]).is_err());
}
+1 -1
View File
@@ -1,4 +1,4 @@
//! BakaShrot's protocol, version 7: what the server, the clients and the
//! BakaShrot's protocol, version 8: what the server, the clients and the
//! tools share, and nothing else.
//!
//! No I/O of its own beyond reading and writing frames on a stream it's
+1 -1
View File
@@ -5,7 +5,7 @@
/// The protocol's version. Both ends must have the same: they tell each
/// other first thing (`frame::write_version()`), and abandon the
/// connection if it differs.
pub const PROTOCOL_VERSION: u32 = 7;
pub const PROTOCOL_VERSION: u32 = 8;
/// The ALPN protocol name both ends offer during the TLS handshake: what
/// isn't BakaShrot doesn't get past it. Not versioned: the version is
+14
View File
@@ -45,6 +45,12 @@ pub fn is_valid_name_or_pattern(text: &str) -> bool {
is_valid_name(text) || is_valid_pattern(text)
}
/// Whether `name` is `filter` (a name) or matches it (a pattern), without
/// case: what a list of names and patterns holds, one entry.
pub fn name_matches(filter: &str, name: &str) -> bool {
names_equal(filter, name) || pattern_matches(filter, name)
}
/// Whether the name `name` matches `pattern` (without case). Anything that
/// isn't a valid name never matches.
pub fn pattern_matches(pattern: &str, name: &str) -> bool {
@@ -144,4 +150,12 @@ mod tests {
);
}
}
#[test]
fn filters() {
assert!(name_matches("Logs", "logs"));
assert!(name_matches("sensors.*", "Sensors.kitchen"));
assert!(!name_matches("logs", "logs-1"));
assert!(!name_matches("sensors.*", "sensor.x"));
}
}
+23 -3
View File
@@ -201,16 +201,36 @@ impl TryFrom<u8> for NameKind {
}
}
/// Every topic or node the client may see.
/// The topics or nodes the client may see, of the topic and node pairs
/// with messages that the filters match: the topics a node pushed to, the
/// nodes that pushed to a topic.
///
/// `[11, [kind]]`
/// `[11, [kind, topics, nodes]]`
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ListNames {
/// Topics or nodes.
pub kind: NameKind,
/// Only the pairs whose topic is this name or matches this pattern;
/// nil for any.
pub topics: Option<String>,
/// Only the pairs whose node is this name or matches this pattern;
/// nil for any.
pub nodes: Option<String>,
}
impl Check for ListNames {}
impl Check for ListNames {
fn check(&self) -> Result<(), DecodeError> {
for (filter, field) in [
(&self.topics, "ListNames.topics"),
(&self.nodes, "ListNames.nodes"),
] {
if let Some(filter) = filter {
rules::name_or_pattern(filter, field)?;
}
}
Ok(())
}
}
/// Topics or nodes.
///
+10 -1
View File
@@ -1,4 +1,4 @@
//! Every packet of protocol 7.
//! Every packet of protocol 8.
//!
//! A packet is a MessagePack array of two: its type, then its fields as an
//! array, `[type, [field, field, ...]]`. Structs inside are arrays of their
@@ -298,6 +298,15 @@ pub(crate) mod rules {
require(names::is_valid_name(value), field, "must be a name")
}
/// A topic or node name, or a pattern.
pub fn name_or_pattern(value: &str, field: &'static str) -> Result<(), DecodeError> {
require(
names::is_valid_name_or_pattern(value),
field,
"must be a name or a pattern",
)
}
/// A message id: 1 and up.
pub fn message_id(value: u64, field: &'static str) -> Result<(), DecodeError> {
range(value, 1, MAX_MESSAGE_ID, field)
@@ -9,7 +9,6 @@ use crate::limits::{
MAX_ATTACHMENT_PARTS, MAX_MESSAGE_ID, MAX_MESSAGES_PER_PACKET, MAX_MISSING_ATTACHMENTS,
MAX_NAMES_LIST_ENTRIES,
};
use crate::names;
use serde::{Deserialize, Serialize};
/// What the server takes from this peer, how far it is, and the
@@ -75,11 +74,7 @@ impl Check for SyncState {
] {
rules::most(list.len(), MAX_NAMES_LIST_ENTRIES, field)?;
for item in list {
rules::require(
names::is_valid_name_or_pattern(item),
field,
"must be a name or a pattern",
)?;
rules::name_or_pattern(item, field)?;
}
}
for head in &self.heads {
+33 -2
View File
@@ -98,6 +98,14 @@ fn samples() -> Vec<Packet> {
AttachmentPart { data: vec![1] }.into(),
ListNames {
kind: NameKind::Topic,
topics: None,
nodes: None,
}
.into(),
ListNames {
kind: NameKind::Node,
topics: Some("sensors.*".into()),
nodes: Some("kitchen".into()),
}
.into(),
NamesList {
@@ -297,8 +305,18 @@ fn shapes() {
PacketType::Messages,
(1u8, Vec::<u8>::new())
)));
assert!(malformed(&raw(PacketType::ListNames, (3u8,))), "kind 3");
assert!(malformed(&raw(PacketType::ListNames, (0u8,))), "kind 0");
assert!(
malformed(&raw(PacketType::ListNames, (3u8, (), ()))),
"kind 3"
);
assert!(
malformed(&raw(PacketType::ListNames, (0u8, (), ()))),
"kind 0"
);
assert!(
malformed(&raw(PacketType::ListNames, (1u8,))),
"protocol 7's, no filters"
);
assert!(
malformed(&raw(
PacketType::Attachment,
@@ -365,6 +383,19 @@ fn ranges() {
assert!(Packet::decode(&get(Some(MAX_MESSAGE_ID), 1)).is_ok());
assert!(invalid(&get(Some(MAX_MESSAGE_ID + 1), 1)));
let list = |topics: Option<&str>, nodes: Option<&str>| {
ListNames {
kind: NameKind::Node,
topics: topics.map(Into::into),
nodes: nodes.map(Into::into),
}
.encode()
};
assert!(Packet::decode(&list(Some("sensors.*"), Some("kitchen"))).is_ok());
assert!(invalid(&list(Some("a b"), None)));
assert!(invalid(&list(None, Some(""))));
assert!(invalid(&list(None, Some("12"))));
let times = |pushed_at| {
Messages {
more: false,