Skip to content

Commit

Permalink
Interpret only-for-topics/forbidden topics as patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasstarkwayve committed Jun 19, 2024
1 parent 1024475 commit faa4b07
Show file tree
Hide file tree
Showing 15 changed files with 32 additions and 16 deletions.
2 changes: 1 addition & 1 deletion docs/manual/config/config_file_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2775,7 +2775,7 @@ The categorisation of tracing output is incomplete and hence most of the verbosi
The default value is: ``none``

..
generated from ddsi_config.h[58d1dd144dc0e8f3c3ef331fd4472eec7f797c71]
generated from ddsi_config.h[9296f1e4eceda8b8514e7859c5584f1cda35412c]
generated from ddsi__cfgunits.h[bd22f0c0ed210501d0ecd3b07c992eca549ef5aa]
generated from ddsi__cfgelems.h[714f801d2988b476694a198097d36169f7e5e129]
generated from ddsi_config.c[4a1074588af66b81f8fd45393cdecff2b5d55b4d]
Expand Down
2 changes: 1 addition & 1 deletion docs/manual/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -1945,7 +1945,7 @@ While none prevents any message from being written to a DDSI2 log file.
The categorisation of tracing output is incomplete and hence most of the verbosity levels and categories are not of much use in the current release. This is an ongoing process and here we describe the target situation rather than the current situation. Currently, the most useful verbosity levels are config, fine and finest.

The default value is: `none`
<!--- generated from ddsi_config.h[58d1dd144dc0e8f3c3ef331fd4472eec7f797c71] -->
<!--- generated from ddsi_config.h[9296f1e4eceda8b8514e7859c5584f1cda35412c] -->
<!--- generated from ddsi__cfgunits.h[bd22f0c0ed210501d0ecd3b07c992eca549ef5aa] -->
<!--- generated from ddsi__cfgelems.h[714f801d2988b476694a198097d36169f7e5e129] -->
<!--- generated from ddsi_config.c[4a1074588af66b81f8fd45393cdecff2b5d55b4d] -->
Expand Down
2 changes: 1 addition & 1 deletion etc/cyclonedds.rnc
Original file line number Diff line number Diff line change
Expand Up @@ -1343,7 +1343,7 @@ MIIEpAIBAAKCAQEA3HIh...AOBaaqSV37XBUJg==<br>
duration_inf = xsd:token { pattern = "inf|0|(\d+(\.\d*)?([Ee][\-+]?\d+)?|\.\d+([Ee][\-+]?\d+)?) *([num]?s|min|hr|day)" }
memsize = xsd:token { pattern = "0|(\d+(\.\d*)?([Ee][\-+]?\d+)?|\.\d+([Ee][\-+]?\d+)?) *([kMG]i?)?B" }
}
# generated from ddsi_config.h[58d1dd144dc0e8f3c3ef331fd4472eec7f797c71]
# generated from ddsi_config.h[9296f1e4eceda8b8514e7859c5584f1cda35412c]
# generated from ddsi__cfgunits.h[bd22f0c0ed210501d0ecd3b07c992eca549ef5aa]
# generated from ddsi__cfgelems.h[714f801d2988b476694a198097d36169f7e5e129]
# generated from ddsi_config.c[4a1074588af66b81f8fd45393cdecff2b5d55b4d]
Expand Down
2 changes: 1 addition & 1 deletion etc/cyclonedds.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -2013,7 +2013,7 @@ MIIEpAIBAAKCAQEA3HIh...AOBaaqSV37XBUJg==&lt;br&gt;
</xs:restriction>
</xs:simpleType>
</xs:schema>
<!--- generated from ddsi_config.h[58d1dd144dc0e8f3c3ef331fd4472eec7f797c71] -->
<!--- generated from ddsi_config.h[9296f1e4eceda8b8514e7859c5584f1cda35412c] -->
<!--- generated from ddsi__cfgunits.h[bd22f0c0ed210501d0ecd3b07c992eca549ef5aa] -->
<!--- generated from ddsi__cfgelems.h[714f801d2988b476694a198097d36169f7e5e129] -->
<!--- generated from ddsi_config.c[4a1074588af66b81f8fd45393cdecff2b5d55b4d] -->
Expand Down
16 changes: 13 additions & 3 deletions src/core/ddsc/src/dds_psmx.c
Original file line number Diff line number Diff line change
Expand Up @@ -338,10 +338,20 @@ static dds_return_t psmx_instance_load (const struct ddsi_domaingv *gv, const st
goto err_init;
}

psmx_instance->only_for_topics = psmx_instance->forbidden_topics = NULL;
// Copy over either the only_for_topics or the forbidden_topics list, switching to nullptr-terminated array of separately-allocated strings
struct ddsi_config_topic_pattern_listelem * pattern_list = config->only_for_topics ? config->only_for_topics : config->forbidden_topics;
char *** pattern_array_ptr = config->only_for_topics ? &psmx_instance->only_for_topics : &psmx_instance->forbidden_topics;
struct ddsi_config_topic_pattern_listelem * pattern_list;
char *** pattern_array_ptr;

if (config->only_for_topics) {
pattern_list = config->only_for_topics;
pattern_array_ptr = &psmx_instance->only_for_topics;
psmx_instance->forbidden_topics = ddsrt_calloc_s(1, sizeof(char*));
} else if (config->forbidden_topics) {
pattern_list = config->forbidden_topics;
pattern_array_ptr = &psmx_instance->forbidden_topics;
psmx_instance->only_for_topics = ddsrt_calloc_s(1, sizeof(char*));
}

size_t list_size = 0;
for (struct ddsi_config_topic_pattern_listelem * elem = pattern_list;
elem;
Expand Down
12 changes: 7 additions & 5 deletions src/core/ddsc/src/dds_topic.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "dds/ddsi/ddsi_entity.h"
#include "dds/ddsi/ddsi_endpoint.h"
#include "dds/ddsi/ddsi_entity_index.h"
#include "dds/ddsi/ddsi_misc.h"
#include "dds/ddsi/ddsi_thread.h"
#include "dds/ddsi/ddsi_sertype.h"
#include "dds/ddsi/ddsi_iid.h"
Expand Down Expand Up @@ -587,17 +588,18 @@ dds_entity_t dds_create_topic_impl (
// Check if the topic is in the forbiddenTopics or NOT in the onlyForTopics list, depending
// on which one is used.
// First off, topics not mentioned are allowed iff only_for_topics is unused
bool allowed_by_config = !psmx->only_for_topics[0];
bool allowed_by_config = psmx->only_for_topics[0] == NULL;
// Then any topic in only_for_topics is allowed
for (char **topic = psmx->only_for_topics; *topic; topic++) {
if (strcmp(ktp->name, *topic) == 0) {
for (char **pattern = psmx->only_for_topics; *pattern; pattern++) {
printf("Matching %s against pattern %s\n", ktp->name, *pattern);
if (ddsi_patmatch(*pattern, ktp->name)) {
allowed_by_config = true;
break;
}
}
// And any topic in forbidden_topics is forbidden
for (char **topic = psmx->forbidden_topics; *topic; topic++) {
if (strcmp(ktp->name, *topic) == 0) {
for (char **pattern = psmx->forbidden_topics; *pattern; pattern++) {
if (ddsi_patmatch(*pattern, ktp->name)) {
allowed_by_config = false;
break;
}
Expand Down
1 change: 1 addition & 0 deletions src/core/ddsc/tests/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "dds/ddsrt/cdtors.h"
#include "dds/ddsrt/environ.h"
#include "dds/ddsrt/heap.h"
#include "dds/ddsi/ddsi_misc.h"
#include "ddsi__misc.h"
#include "dds/ddsi/ddsi_xqos.h"

Expand Down
1 change: 1 addition & 0 deletions src/core/ddsc/tests/redundantnw.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "dds/ddsrt/io.h"
#include "dds/ddsrt/misc.h"
#include "dds/ddsrt/heap.h"
#include "dds/ddsi/ddsi_misc.h"

#include "dds__entity.h"
#include "ddsi__addrset.h"
Expand Down
1 change: 1 addition & 0 deletions src/core/ddsi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ set(hdrs_ddsi
ddsi_xevent.h
ddsi_xmsg.h
ddsi_psmx.h
ddsi_misc.h
)

set(hdrs_private_ddsi
Expand Down
2 changes: 1 addition & 1 deletion src/core/ddsi/defconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void ddsi_config_init_default (struct ddsi_config *cfg)
cfg->ssl_min_version.minor = 3;
#endif /* DDS_HAS_TCP_TLS */
}
/* generated from ddsi_config.h[58d1dd144dc0e8f3c3ef331fd4472eec7f797c71] */
/* generated from ddsi_config.h[9296f1e4eceda8b8514e7859c5584f1cda35412c] */
/* generated from ddsi__cfgunits.h[bd22f0c0ed210501d0ecd3b07c992eca549ef5aa] */
/* generated from ddsi__cfgelems.h[714f801d2988b476694a198097d36169f7e5e129] */
/* generated from ddsi_config.c[4a1074588af66b81f8fd45393cdecff2b5d55b4d] */
Expand Down
3 changes: 0 additions & 3 deletions src/core/ddsi/src/ddsi__misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ int ddsi_guid_prefix_eq (const ddsi_guid_prefix_t *a, const ddsi_guid_prefix_t *
/** @component misc */
int ddsi_guid_eq (const struct ddsi_guid *a, const struct ddsi_guid *b);

/** @component misc */
int ddsi_patmatch (const char *pat, const char *str);

#if defined (__cplusplus)
}
#endif
Expand Down
1 change: 1 addition & 0 deletions src/core/ddsi/src/ddsi_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "dds/ddsrt/md5.h"
#include "dds/ddsrt/heap.h"

#include "dds/ddsi/ddsi_misc.h"
#include "ddsi__misc.h"

extern inline ddsi_seqno_t ddsi_from_seqno (const ddsi_sequence_number_t sn);
Expand Down
1 change: 1 addition & 0 deletions src/core/ddsi/src/ddsi_qosmatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "dds/ddsi/ddsi_domaingv.h"
#include "dds/ddsi/ddsi_entity.h"
#include "dds/ddsi/ddsi_qosmatch.h"
#include "dds/ddsi/ddsi_misc.h"
#include "ddsi__typelookup.h"
#include "ddsi__misc.h"
#include "ddsi__typelib.h"
Expand Down
1 change: 1 addition & 0 deletions src/security/core/tests/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "dds/ddsrt/environ.h"
#include "dds/ddsrt/heap.h"
#include "dds/ddsi/ddsi_xqos.h"
#include "dds/ddsi/ddsi_misc.h"
#include "ddsi__misc.h"
#include "dds/security/dds_security_api_defs.h"
#include "common/config_env.h"
Expand Down
1 change: 1 addition & 0 deletions src/security/core/tests/plugin_loading.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "dds/ddsrt/cdtors.h"
#include "dds/ddsrt/environ.h"
#include "dds/ddsrt/heap.h"
#include "dds/ddsi/ddsi_misc.h"
#include "ddsi__misc.h"
#include "dds/security/dds_security_api_defs.h"
#include "common/config_env.h"
Expand Down

0 comments on commit faa4b07

Please sign in to comment.