diff options
author | Mattias Andrée <maandree@kth.se> | 2017-10-24 17:34:31 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2017-10-24 17:44:26 +0200 |
commit | 9f9a554afa4c23284ee624e901e5841ab6636f0d (patch) | |
tree | ec2ab72871d1b7aaace9a7956df47f2d04107f7b | |
parent | Update readme (diff) | |
download | sbus-9f9a554afa4c23284ee624e901e5841ab6636f0d.tar.gz sbus-9f9a554afa4c23284ee624e901e5841ab6636f0d.tar.bz2 sbus-9f9a554afa4c23284ee624e901e5841ab6636f0d.tar.xz |
Use / instead of .
This is more like file path and allows inclusion of
package names (and file paths too if you want that
for some reason) in the routing key.
Diffstat (limited to '')
-rw-r--r-- | README | 18 | ||||
-rw-r--r-- | sbusd.c | 16 | ||||
-rw-r--r-- | test.c | 6 |
3 files changed, 20 insertions, 20 deletions
@@ -30,15 +30,15 @@ Non-features: Routing keys: Routing keys are used to filter received messages. A routing key may contain any byte other than the NUL, whoever there are three - bytes with special meaning: '*', '.', and '!'. '*' should not be + bytes with special meaning: '*', '/', and '!'. '*' should not be in routing keys, but only in routing key patterns, it matches until - the next '.' or end if there are not more '.'s. Additionally if a - routing key pattern ends with '.' that '.' will match to a '.' and - any subsequent byte. For example 'a.*.c.' will match 'a.b.c.' and - 'a.b.c.d.e' but not 'a.b.c' or 'a.c.d'. And empty routing key + the next '/' or end if there are not more '/'s. Additionally if a + routing key pattern ends with '/' that '/' will match to a '/' and + any subsequent byte. For example 'a/*/c/' will match 'a/b/c/' and + 'a/b/c/d/e' but not 'a/b/c' or 'a/c/d'. And empty routing key pattern shall match everything. The token '!' is reserved, a client should never use '!' for any other purpose than specified in the - protocol, unless it has an other byte than a '.' next to it. The + protocol, unless it has an other byte than a '/' next to it. The server may choose to disconnect a client using '!' in an invalid way or simply ignore such messages. @@ -103,11 +103,11 @@ Protocol: sent by the client. Secret messages: - Routing keys starting with '!.cred.' can only be subscribed to + Routing keys starting with '!/cred/' can only be subscribed to by clients with matching credentials. These routing keys must match regular expression - ^!\.cred\.\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)\.\(.*\)$ + ^!\/cred\/\([0-9]*\)\/\([0-9]*\)\/\([0-9]*\)\/\(.*\)$ where \1 is the group ID, \2 is the user ID, \3 is the process ID, and \4 the rest of routing key which may also use this @@ -120,7 +120,7 @@ Secret messages: However, due to network support, these routing keys may need to be prefixed with the credentials for the servers the message goes through. This prefix can be retrieved by simply sending an - empty control message (CMSG) with the routing key '!.cred.prefix' + empty control message (CMSG) with the routing key '!/cred/prefix' and the server will reply with a control message containing prefix using this routing key. Note, prefix is probably the empty string, as the master server do not need to add its credentials to be @@ -154,10 +154,10 @@ is_subscription_match(const char *sub, const char *key) if (!*key) return !*sub; if (!*sub) - return sub == sub_start || sub[-1] == '.'; + return sub == sub_start || sub[-1] == '/'; if (*sub == '*') { sub++; - while (*key && *key != '.') + while (*key && *key != '/') key++; continue; } @@ -181,21 +181,21 @@ is_subscription_acceptable(struct client *cl, const char *key) struct ucred cred; long long int tmp; const char *p; - if (!strncmp(key, "!.cred.", sizeof("!.cred.") - 1)) { + if (!strncmp(key, "!/cred/", sizeof("!/cred/") - 1)) { if (getsockopt(cl->fd, SOL_SOCKET, SO_PEERCRED, &cred, &(socklen_t){sizeof(cred)}) < 0) { weprintf("getsockopt <client> SOL_SOCKET SO_PEERCRED:"); return -1; } errno = 0; - p = &key[sizeof("!.cred.") - 1]; + p = &key[sizeof("!/cred/") - 1]; #define TEST_CRED(ID)\ if (!*p) {\ return 0;\ - } else if (*p++ != '.') {\ + } else if (*p++ != '/') {\ if (!isdigit(*p))\ return 0;\ tmp = strtoll(p, (void *)&p, 10);\ - if (errno || (*p && *p != '.') || (ID##_t)tmp != cred.ID)\ + if (errno || (*p && *p != '/') || (ID##_t)tmp != cred.ID)\ return 0;\ } TEST_CRED(gid); @@ -273,8 +273,8 @@ send_packet(struct client *cl, const char *buf, size_t n) static void handle_cmsg(struct client *cl, const char *msg, size_t n) { - if (!strcmp(msg, "CMSG !.cred.prefix")) { - n = sizeof("CMSG !.cred.prefix"); + if (!strcmp(msg, "CMSG !/cred/prefix")) { + n = sizeof("CMSG !/cred/prefix"); } else { return; } @@ -258,17 +258,17 @@ check(int fd) size_t i; alarm(1); - assert(!libsbus_subscribe(fd, "test.", 0, buf)); + assert(!libsbus_subscribe(fd, "test/", 0, buf)); assert(!libsbus_subscribe(fd, "discard", 0, buf)); assert(!libsbus_unsubscribe(fd, "discard", 0, buf)); assert(!libsbus_publish(fd, "discard", "not caught", strlen("not caught"), 0, buf)); for (i = 0; i < 100; i++) { - sprintf(key, "test.%zu", i); + sprintf(key, "test/%zu", i); sprintf(msg, "%zu", i); assert(!libsbus_publish(fd, key, msg, strlen(msg), 0, buf)); } for (i = 0; i < 100; i++) { - sprintf(key, "test.%zu", i); + sprintf(key, "test/%zu", i); sprintf(msg, "%zu", i); assert(!libsbus_receive(fd, 0, buf, &packet)); assert(packet.type == LIBSBUS_MESSAGE); |