From b63631359756e802d17f09404774750c2d36a6ce Mon Sep 17 00:00:00 2001 From: Tobias Stark Date: Fri, 7 Jun 2024 09:26:43 +0000 Subject: [PATCH 1/4] Add onlyForTopics and forbiddenTopics config option --- docs/manual/config/config_file_reference.rst | 36 ++++++++++-- docs/manual/options.md | 28 +++++++-- etc/cyclonedds.rnc | 22 +++++-- etc/cyclonedds.xsd | 24 ++++++-- src/core/ddsc/include/dds/ddsc/dds_psmx.h | 2 + src/core/ddsc/src/dds_psmx.c | 61 ++++++++++++++++++++ src/core/ddsc/src/dds_topic.c | 24 ++++++++ src/core/ddsi/defconfig.c | 10 ++-- src/core/ddsi/include/dds/ddsi/ddsi_config.h | 11 ++++ src/core/ddsi/src/ddsi__cfgelems.h | 15 +++++ src/core/ddsi/src/ddsi_config.c | 48 ++++++++++++++- src/tools/_confgen/_confgen.h | 1 + src/tools/_confgen/generate_defconfig.c | 12 ++++ 13 files changed, 264 insertions(+), 30 deletions(-) diff --git a/docs/manual/config/config_file_reference.rst b/docs/manual/config/config_file_reference.rst index ffe85c57b5..199709a2a8 100644 --- a/docs/manual/config/config_file_reference.rst +++ b/docs/manual/config/config_file_reference.rst @@ -654,7 +654,7 @@ The default value is: ``default`` //CycloneDDS/Domain/General/Interfaces/PubSubMessageExchange ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -Attributes: :ref:`config`, :ref:`library`, :ref:`name`, :ref:`priority` +Attributes: :ref:`config`, :ref:`forbiddenTopics`, :ref:`library`, :ref:`name`, :ref:`onlyForTopics`, :ref:`priority` This element defines a PSMX. @@ -671,6 +671,18 @@ This attribute specifies any configuration data for the PSMX instance.This has n The default value is: ```` +.. _`//CycloneDDS/Domain/General/Interfaces/PubSubMessageExchange[@forbiddenTopics]`: + +//CycloneDDS/Domain/General/Interfaces/PubSubMessageExchange[@forbiddenTopics] +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Text + +A comma-separated list of topics that should never use this psmx.Mutually exclusive with onlyForTopics. + +The default value is: ```` + + .. _`//CycloneDDS/Domain/General/Interfaces/PubSubMessageExchange[@library]`: //CycloneDDS/Domain/General/Interfaces/PubSubMessageExchange[@library] @@ -695,6 +707,18 @@ This attribute specifies the name of the interface. The default value is: ```` +.. _`//CycloneDDS/Domain/General/Interfaces/PubSubMessageExchange[@onlyForTopics]`: + +//CycloneDDS/Domain/General/Interfaces/PubSubMessageExchange[@onlyForTopics] +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Text + +A comma-separated list of all the topics that should use this PSMX.This option can be used to restrict the PSMX to a selected list of topics.Mutually exclusive with forbiddenTopics. + +The default value is: ```` + + .. _`//CycloneDDS/Domain/General/Interfaces/PubSubMessageExchange[@priority]`: //CycloneDDS/Domain/General/Interfaces/PubSubMessageExchange[@priority] @@ -2704,14 +2728,14 @@ The categorisation of tracing output is incomplete and hence most of the verbosi The default value is: ``none`` .. - generated from ddsi_config.h[83ad19f1a665710b0c82b3ac6b861e6c8e83913f] + generated from ddsi_config.h[99b38dad99d609bd1f2e2aa7b43cf2a3aa10948d] generated from ddsi__cfgunits.h[bd22f0c0ed210501d0ecd3b07c992eca549ef5aa] - generated from ddsi__cfgelems.h[194217161977869610495a7889bbc1e6bc976ce1] - generated from ddsi_config.c[a439a20e32fe327db26f2f10028d0056e46c1a0b] - generated from _confgen.h[e32eabfc35e9f3a7dcb63b19ed148c0d17c6e5fc] + generated from ddsi__cfgelems.h[fdfcbecb910d6a859d5e5ab25d81065aaca18ae8] + generated from ddsi_config.c[3f9cdfe5934118aeb3e6f7e8d9b71f815e8021c2] + generated from _confgen.h[b3b98385ecc752860a55e126b3893423730f53ab] generated from _confgen.c[237308acd53897a34e8c643e16e05a61d73ffd65] generated from generate_rnc.c[b50e4b7ab1d04b2bc1d361a0811247c337b74934] generated from generate_md.c[789b92e422631684352909cfb8bf43f6ceb16a01] generated from generate_rst.c[3c4b523fbb57c8e4a7e247379d06a8021ccc21c4] generated from generate_xsd.c[6b6818d7f17a35d56c376c04ec1410427f34c0f0] - generated from generate_defconfig.c[63ca9d8ae2f1ce2e761c9d4c0510a45eb062d830] + generated from generate_defconfig.c[0ef1411470804c3db386c20c8752b161eb8418ae] diff --git a/docs/manual/options.md b/docs/manual/options.md index 217bb09790..b8ef648685 100644 --- a/docs/manual/options.md +++ b/docs/manual/options.md @@ -437,7 +437,7 @@ The default value is: `default` ##### //CycloneDDS/Domain/General/Interfaces/PubSubMessageExchange -Attributes: [config](#cycloneddsdomaingeneralinterfacespubsubmessageexchangeconfig), [library](#cycloneddsdomaingeneralinterfacespubsubmessageexchangelibrary), [name](#cycloneddsdomaingeneralinterfacespubsubmessageexchangename), [priority](#cycloneddsdomaingeneralinterfacespubsubmessageexchangepriority) +Attributes: [config](#cycloneddsdomaingeneralinterfacespubsubmessageexchangeconfig), [forbiddenTopics](#cycloneddsdomaingeneralinterfacespubsubmessageexchangeforbiddentopics), [library](#cycloneddsdomaingeneralinterfacespubsubmessageexchangelibrary), [name](#cycloneddsdomaingeneralinterfacespubsubmessageexchangename), [onlyForTopics](#cycloneddsdomaingeneralinterfacespubsubmessageexchangeonlyfortopics), [priority](#cycloneddsdomaingeneralinterfacespubsubmessageexchangepriority) This element defines a PSMX. @@ -450,6 +450,14 @@ This attribute specifies any configuration data for the PSMX instance.This has n The default value is: `` +##### //CycloneDDS/Domain/General/Interfaces/PubSubMessageExchange[@forbiddenTopics] +Text + +A comma-separated list of topics that should never use this psmx.Mutually exclusive with onlyForTopics. + +The default value is: `` + + ##### //CycloneDDS/Domain/General/Interfaces/PubSubMessageExchange[@library] Text @@ -466,6 +474,14 @@ This attribute specifies the name of the interface. The default value is: `` +##### //CycloneDDS/Domain/General/Interfaces/PubSubMessageExchange[@onlyForTopics] +Text + +A comma-separated list of all the topics that should use this PSMX.This option can be used to restrict the PSMX to a selected list of topics.Mutually exclusive with forbiddenTopics. + +The default value is: `` + + ##### //CycloneDDS/Domain/General/Interfaces/PubSubMessageExchange[@priority] Text @@ -1898,14 +1914,14 @@ 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` - + - - - + + + - + diff --git a/etc/cyclonedds.rnc b/etc/cyclonedds.rnc index f1d4c36265..6209957a25 100644 --- a/etc/cyclonedds.rnc +++ b/etc/cyclonedds.rnc @@ -317,6 +317,12 @@ CycloneDDS configuration""" ] ] text }? & [ a:documentation [ xml:lang="en" """ +

A comma-separated list of topics that should never use this psmx.Mutually exclusive with onlyForTopics.

+

The default value is: <empty>

""" ] ] + attribute forbiddenTopics { + text + }? + & [ a:documentation [ xml:lang="en" """

This attribute specifies the filename of the interface library.

The default value is: <empty>

""" ] ] attribute library { @@ -329,6 +335,12 @@ CycloneDDS configuration""" ] ] text }? & [ a:documentation [ xml:lang="en" """ +

A comma-separated list of all the topics that should use this PSMX.This option can be used to restrict the PSMX to a selected list of topics.Mutually exclusive with forbiddenTopics.

+

The default value is: <empty>

""" ] ] + attribute onlyForTopics { + text + }? + & [ a:documentation [ xml:lang="en" """

This attribute specifies the interface priority (decimal integer or default). The default value for a PSMX is 0.

The default value is: default

""" ] ] attribute priority { @@ -1313,14 +1325,14 @@ MIIEpAIBAAKCAQEA3HIh...AOBaaqSV37XBUJg==
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[83ad19f1a665710b0c82b3ac6b861e6c8e83913f] +# generated from ddsi_config.h[99b38dad99d609bd1f2e2aa7b43cf2a3aa10948d] # generated from ddsi__cfgunits.h[bd22f0c0ed210501d0ecd3b07c992eca549ef5aa] -# generated from ddsi__cfgelems.h[194217161977869610495a7889bbc1e6bc976ce1] -# generated from ddsi_config.c[a439a20e32fe327db26f2f10028d0056e46c1a0b] -# generated from _confgen.h[e32eabfc35e9f3a7dcb63b19ed148c0d17c6e5fc] +# generated from ddsi__cfgelems.h[fdfcbecb910d6a859d5e5ab25d81065aaca18ae8] +# generated from ddsi_config.c[3f9cdfe5934118aeb3e6f7e8d9b71f815e8021c2] +# generated from _confgen.h[b3b98385ecc752860a55e126b3893423730f53ab] # generated from _confgen.c[237308acd53897a34e8c643e16e05a61d73ffd65] # generated from generate_rnc.c[b50e4b7ab1d04b2bc1d361a0811247c337b74934] # generated from generate_md.c[789b92e422631684352909cfb8bf43f6ceb16a01] # generated from generate_rst.c[3c4b523fbb57c8e4a7e247379d06a8021ccc21c4] # generated from generate_xsd.c[6b6818d7f17a35d56c376c04ec1410427f34c0f0] -# generated from generate_defconfig.c[63ca9d8ae2f1ce2e761c9d4c0510a45eb062d830] +# generated from generate_defconfig.c[0ef1411470804c3db386c20c8752b161eb8418ae] diff --git a/etc/cyclonedds.xsd b/etc/cyclonedds.xsd index c314d2fdb2..2a8077fb62 100644 --- a/etc/cyclonedds.xsd +++ b/etc/cyclonedds.xsd @@ -502,6 +502,13 @@ CycloneDDS configuration <p>This attribute specifies any configuration data for the PSMX instance.This has no meaning in CycloneDDS itself, and its parsing is deferred to thePSMX implementation.</p> +<p>The default value is: <code>&lt;empty&gt;</code></p> + + + + + +<p>A comma-separated list of topics that should never use this psmx.Mutually exclusive with onlyForTopics.</p> <p>The default value is: <code>&lt;empty&gt;</code></p> @@ -516,6 +523,13 @@ CycloneDDS configuration <p>This attribute specifies the name of the interface. </p> +<p>The default value is: <code>&lt;empty&gt;</code></p> + + + + + +<p>A comma-separated list of all the topics that should use this PSMX.This option can be used to restrict the PSMX to a selected list of topics.Mutually exclusive with forbiddenTopics.</p> <p>The default value is: <code>&lt;empty&gt;</code></p> @@ -1971,14 +1985,14 @@ MIIEpAIBAAKCAQEA3HIh...AOBaaqSV37XBUJg==<br> - + - - - + + + - + diff --git a/src/core/ddsc/include/dds/ddsc/dds_psmx.h b/src/core/ddsc/include/dds/ddsc/dds_psmx.h index 2ccf4e87d9..18ecd1dc85 100644 --- a/src/core/ddsc/include/dds/ddsc/dds_psmx.h +++ b/src/core/ddsc/include/dds/ddsc/dds_psmx.h @@ -260,6 +260,8 @@ typedef struct dds_psmx { dds_psmx_ops_t ops; //!< associated functions const char *instance_name; //!< name of this PSMX instance int32_t priority; //!< priority of choosing this interface + char ** only_for_topics; //!< See ddsi_config_psmx. Format is nullptr-terminated array of separately allocated char* + char ** forbidden_topics; //!< See ddsi_config_psmx. Format is nullptr-terminated array of separately allocated char* const struct ddsi_locator *locator; //!< the locator for this PSMX instance dds_psmx_instance_id_t instance_id; //!< the identifier of this PSMX instance struct dds_psmx_topic_list_elem *psmx_topics; //!< associated topics diff --git a/src/core/ddsc/src/dds_psmx.c b/src/core/ddsc/src/dds_psmx.c index d382c1524d..76e2412102 100644 --- a/src/core/ddsc/src/dds_psmx.c +++ b/src/core/ddsc/src/dds_psmx.c @@ -11,6 +11,7 @@ #include #include "dds/ddsrt/heap.h" +#include "dds/ddsrt/string.h" #include "dds/ddsrt/dynlib.h" #include "dds/ddsrt/mh3.h" #include "dds/ddsrt/io.h" @@ -27,6 +28,8 @@ static struct dds_psmx_endpoint * psmx_create_endpoint (struct dds_psmx_topic *psmx_topic, const struct dds_qos *qos, dds_psmx_endpoint_type_t endpoint_type); static dds_return_t psmx_delete_endpoint (struct dds_psmx_endpoint *psmx_endpoint); +void deep_cleanup_topic_array(char **topic_array); + dds_return_t dds_add_psmx_topic_to_list (struct dds_psmx_topic *psmx_topic, struct dds_psmx_topic_list_elem **list) { if (!psmx_topic) @@ -84,6 +87,14 @@ dds_return_t dds_remove_psmx_topic_from_list (struct dds_psmx_topic *psmx_topic, return ret; } +// Free all members of a nullptr-terminated array of separately allocated char pointers +void deep_cleanup_topic_array(char **topic_array) { + for (char * topic = *topic_array; topic; topic++) { + ddsrt_free((void*)topic); + } + ddsrt_free((void*)topic_array); +} + dds_return_t dds_add_psmx_endpoint_to_list (struct dds_psmx_endpoint *psmx_endpoint, struct dds_psmx_endpoint_list_elem **list) { if (!psmx_endpoint) @@ -164,6 +175,12 @@ dds_return_t dds_psmx_cleanup_generic (struct dds_psmx *psmx) dds_free ((void *) psmx->instance_name); dds_free ((void *) psmx->locator); + deep_cleanup_topic_array(psmx->only_for_topics); + psmx->only_for_topics = NULL; + + deep_cleanup_topic_array(psmx->forbidden_topics); + psmx->forbidden_topics = NULL; + while (ret == DDS_RETCODE_OK && psmx->psmx_topics) ret = dds_remove_psmx_topic_from_list (psmx->psmx_topics->topic, &psmx->psmx_topics); @@ -313,11 +330,55 @@ static dds_return_t psmx_instance_load (const struct ddsi_domaingv *gv, const st goto err_init; } psmx_instance->priority = config->priority.value; + + if (config->only_for_topics.size > 0 && config->forbidden_topics.size > 0) { + ret = DDS_RETCODE_UNSUPPORTED; + GVERROR ("Failed to initialize PSMX instance '%s': conflicting options only_for_topics and forbidden_topics were both present", + config->name); + goto err_init; + } + + // Copy over the only_for_topics and forbidden_topics array, switching to nullptr-terminated array of separately-allocated strings + psmx_instance->only_for_topics = psmx_instance->forbidden_topics = NULL; + + // Allocate +1 for the final nullptr terminator + psmx_instance->only_for_topics = ddsrt_calloc_s(config->only_for_topics.size + 1, sizeof(char*)); + psmx_instance->forbidden_topics = ddsrt_calloc_s(config->forbidden_topics.size + 1, sizeof(char*)); + if (!psmx_instance->only_for_topics || !psmx_instance->forbidden_topics) { + GVERROR ("Failed to initialize PSMX instance '%s': out of memory", + config->name); + goto err_topic_arrays_oom; + } + + for (size_t i = 0 ; i < config->only_for_topics.size; i++) { + psmx_instance->only_for_topics[i] = ddsrt_strdup(config->only_for_topics.topics[i]); + if (psmx_instance->only_for_topics[i] == NULL) { + GVERROR ("Failed to initialize PSMX instance '%s': out of memory", + config->name); + goto err_topic_arrays_oom; + } + } + for (size_t i = 0 ; i < config->forbidden_topics.size; i++) { + psmx_instance->forbidden_topics[i] = ddsrt_strdup(config->forbidden_topics.topics[i]); + if (psmx_instance->forbidden_topics[i] == NULL) { + GVERROR ("Failed to initialize PSMX instance '%s': out of memory", + config->name); + goto err_topic_arrays_oom; + } + } + *out = psmx_instance; *lib_handle = handle; ddsrt_free (configstr); return DDS_RETCODE_OK; +err_topic_arrays_oom: + if (psmx_instance->only_for_topics) { + deep_cleanup_topic_array(psmx_instance->only_for_topics); + } + if (psmx_instance->forbidden_topics) { + deep_cleanup_topic_array(psmx_instance->forbidden_topics); + } err_init: err_dlsym: ddsrt_dlclose (handle); diff --git a/src/core/ddsc/src/dds_topic.c b/src/core/ddsc/src/dds_topic.c index 3165b62f06..49eb3b8ef6 100644 --- a/src/core/ddsc/src/dds_topic.c +++ b/src/core/ddsc/src/dds_topic.c @@ -583,6 +583,30 @@ dds_entity_t dds_create_topic_impl ( struct dds_psmx *psmx = dom->psmx_instances.instances[i]; if (!psmx->ops.type_qos_supported (psmx, DDS_PSMX_ENDPOINT_TYPE_UNSET, sertype_registered->data_type_props, new_qos)) continue; + + // 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]; + // Then any topic in only_for_topics is allowed + for (char **topic = psmx->only_for_topics; *topic; topic++) { + if (strcmp(ktp->name, *topic) == 0) { + 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) { + allowed_by_config = false; + break; + } + } + + if (!allowed_by_config) { + continue; + } + struct dds_psmx_topic *psmx_topic = psmx->ops.create_topic (psmx, ktp->name, sertype_registered->type_name, sertype_registered->data_type_props); if (psmx_topic == NULL) { diff --git a/src/core/ddsi/defconfig.c b/src/core/ddsi/defconfig.c index b84a164347..c6953d5947 100644 --- a/src/core/ddsi/defconfig.c +++ b/src/core/ddsi/defconfig.c @@ -99,14 +99,14 @@ 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[83ad19f1a665710b0c82b3ac6b861e6c8e83913f] */ +/* generated from ddsi_config.h[99b38dad99d609bd1f2e2aa7b43cf2a3aa10948d] */ /* generated from ddsi__cfgunits.h[bd22f0c0ed210501d0ecd3b07c992eca549ef5aa] */ -/* generated from ddsi__cfgelems.h[194217161977869610495a7889bbc1e6bc976ce1] */ -/* generated from ddsi_config.c[a439a20e32fe327db26f2f10028d0056e46c1a0b] */ -/* generated from _confgen.h[e32eabfc35e9f3a7dcb63b19ed148c0d17c6e5fc] */ +/* generated from ddsi__cfgelems.h[fdfcbecb910d6a859d5e5ab25d81065aaca18ae8] */ +/* generated from ddsi_config.c[3f9cdfe5934118aeb3e6f7e8d9b71f815e8021c2] */ +/* generated from _confgen.h[b3b98385ecc752860a55e126b3893423730f53ab] */ /* generated from _confgen.c[237308acd53897a34e8c643e16e05a61d73ffd65] */ /* generated from generate_rnc.c[b50e4b7ab1d04b2bc1d361a0811247c337b74934] */ /* generated from generate_md.c[789b92e422631684352909cfb8bf43f6ceb16a01] */ /* generated from generate_rst.c[3c4b523fbb57c8e4a7e247379d06a8021ccc21c4] */ /* generated from generate_xsd.c[6b6818d7f17a35d56c376c04ec1410427f34c0f0] */ -/* generated from generate_defconfig.c[63ca9d8ae2f1ce2e761c9d4c0510a45eb062d830] */ +/* generated from generate_defconfig.c[0ef1411470804c3db386c20c8752b161eb8418ae] */ diff --git a/src/core/ddsi/include/dds/ddsi/ddsi_config.h b/src/core/ddsi/include/dds/ddsi/ddsi_config.h index 0abc6fe808..890e6c5ce8 100644 --- a/src/core/ddsi/include/dds/ddsi/ddsi_config.h +++ b/src/core/ddsi/include/dds/ddsi/ddsi_config.h @@ -237,11 +237,22 @@ enum ddsi_config_entity_naming_mode { DDSI_ENTITY_NAMING_DEFAULT_FANCY }; +// The array is stored as size + pointer to pointer array. +// If size is zero, the pointer is NULL rather than a pointer to an empty array. +// The pointed-to strings are allocated right after the array, so +// a simple `free(topics)` frees everything +struct ddsi_config_topic_array { + size_t size; + char **topics; +}; + struct ddsi_config_psmx { char *name; char *library; char *config; struct ddsi_config_maybe_int32 priority; + struct ddsi_config_topic_array forbidden_topics; + struct ddsi_config_topic_array only_for_topics; }; struct ddsi_config_psmx_listelem { diff --git a/src/core/ddsi/src/ddsi__cfgelems.h b/src/core/ddsi/src/ddsi__cfgelems.h index 2b17969bb6..c93be2c109 100644 --- a/src/core/ddsi/src/ddsi__cfgelems.h +++ b/src/core/ddsi/src/ddsi__cfgelems.h @@ -134,6 +134,21 @@ static struct cfgelem psmx_attributes[] = { "This has no meaning in CycloneDDS itself, and its parsing is deferred to the" "PSMX implementation.

" )), + STRING("forbiddenTopics", NULL, 1, "", + MEMBEROF(ddsi_config_psmx_listelem, cfg.forbidden_topics), + FUNCTIONS(if_topic_array, uf_topic_array, ff_topic_array, pf_topic_array), + DESCRIPTION( + "

A comma-separated list of topics that should never use this psmx." + "Mutually exclusive with onlyForTopics.

" + )), + STRING("onlyForTopics", NULL, 1, "", + MEMBEROF(ddsi_config_psmx_listelem, cfg.only_for_topics), + FUNCTIONS(if_topic_array, uf_topic_array, ff_topic_array, pf_topic_array), + DESCRIPTION( + "

A comma-separated list of all the topics that should use this PSMX." + "This option can be used to restrict the PSMX to a selected list of topics." + "Mutually exclusive with forbiddenTopics.

" + )), END_MARKER }; diff --git a/src/core/ddsi/src/ddsi_config.c b/src/core/ddsi/src/ddsi_config.c index 4db60cf602..dd9a990906 100644 --- a/src/core/ddsi/src/ddsi_config.c +++ b/src/core/ddsi/src/ddsi_config.c @@ -52,6 +52,11 @@ typedef enum update_result (*update_fun_t) (struct ddsi_cfgst *cfgst, void *pare typedef void (*free_fun_t) (struct ddsi_cfgst *cfgst, void *parent, struct cfgelem const * const cfgelem); typedef void (*print_fun_t) (struct ddsi_cfgst *cfgst, void *parent, struct cfgelem const * const cfgelem, uint32_t sources); +// Split the given string at commas. Returns a freshly allocated char* array pointing to the +// split words and returns the number of words found in *nwords. The pointed-to strings are +// contained in the returned allocation, so a single `free` on the return value frees everything +static char **split_at_comma (const char *str, size_t *nwords); + struct unit { const char *name; int64_t multiplier; @@ -192,6 +197,7 @@ DU(deaf_mute); DUPF(min_tls_version); #endif DUPF(shm_loglevel); +DUPF(topic_array); #undef DUPF #undef DU #undef PF @@ -199,6 +205,7 @@ DUPF(shm_loglevel); #define DF(fname) static void fname (struct ddsi_cfgst *cfgst, void *parent, struct cfgelem const * const cfgelem) DF(ff_free); DF(ff_networkAddresses); +DF(ff_topic_array); #undef DF #define DI(fname) static int fname (struct ddsi_cfgst *cfgst, void *parent, struct cfgelem const * const cfgelem) @@ -214,6 +221,7 @@ DI(if_thread_properties); #ifdef DDS_HAS_SECURITY DI(if_omg_security); #endif +DI(if_topic_array); #undef DI /* drop extra information, i.e. DESCRIPTION, RANGE, UNIT and VALUES */ @@ -680,9 +688,7 @@ static int if_psmx(struct ddsi_cfgst *cfgst, void *parent, struct cfgelem const struct ddsi_config_psmx_listelem *new = if_common (cfgst, parent, cfgelem, sizeof(*new)); if (new == NULL) return -1; - new->cfg.name = NULL; - new->cfg.library = NULL; - new->cfg.config = NULL; + memset(&new->cfg, 0, sizeof(new->cfg)); return 0; } @@ -1279,6 +1285,42 @@ static void ff_networkAddresses (struct ddsi_cfgst *cfgst, void *parent, struct ddsrt_free (*elem); } +static int if_topic_array(struct ddsi_cfgst *cfgst, void *parent, struct cfgelem const * const cfgelem) { + struct ddsi_config_topic_array * elem = cfg_address (cfgst, parent, cfgelem); + elem->size = 0; + elem->topics = NULL; + return 0; +} + +static enum update_result uf_topic_array (struct ddsi_cfgst *cfgst, void *parent, struct cfgelem const * const cfgelem, UNUSED_ARG(int first), const char *value) { + struct ddsi_config_topic_array * elem = cfg_address (cfgst, parent, cfgelem); + free(elem->topics); + if (*value == '\0') { + elem->size = 0; + elem->topics = NULL; + } else { + elem->topics = split_at_comma(value, &elem->size); + } + return URES_SUCCESS; +} + +static void ff_topic_array (struct ddsi_cfgst *cfgst, void *parent, struct cfgelem const * const cfgelem) { + struct ddsi_config_topic_array * elem = cfg_address (cfgst, parent, cfgelem); + free(elem->topics); +} + +static void pf_topic_array (struct ddsi_cfgst *cfgst, UNUSED_ARG (void *parent), UNUSED_ARG (struct cfgelem const * const cfgelem), uint32_t sources) { + struct ddsi_config_topic_array * elem = cfg_address (cfgst, parent, cfgelem); + if (elem->size == 0) { + // Just passing "" produces a "zero-length format string" warning + cfg_logelem (cfgst, sources, "%s", ""); + } else { + for (size_t i = 0; i < elem->size; ++i) { + cfg_logelem (cfgst, sources, "%s", elem->topics[i]); + } + } +} + #ifdef DDSRT_HAVE_SSM static const char *allow_multicast_names[] = { "false", "spdp", "asm", "ssm", "true", NULL }; static const uint32_t allow_multicast_codes[] = { DDSI_AMC_FALSE, DDSI_AMC_SPDP, DDSI_AMC_ASM, DDSI_AMC_SSM, DDSI_AMC_TRUE }; diff --git a/src/tools/_confgen/_confgen.h b/src/tools/_confgen/_confgen.h index cd64e8ae90..b404bacca1 100644 --- a/src/tools/_confgen/_confgen.h +++ b/src/tools/_confgen/_confgen.h @@ -53,6 +53,7 @@ void gendef_pf_transport_selector (FILE *fp, void *parent, struct cfgelem const void gendef_pf_many_sockets_mode (FILE *fp, void *parent, struct cfgelem const * const cfgelem); void gendef_pf_standards_conformance (FILE *fp, void *parent, struct cfgelem const * const cfgelem); void gendef_pf_shm_loglevel (FILE *fp, void *parent, struct cfgelem const * const cfgelem); +void gendef_pf_topic_array (FILE *fp, void *parent, struct cfgelem const * const cfgelem); struct cfgunit { const char *name; diff --git a/src/tools/_confgen/generate_defconfig.c b/src/tools/_confgen/generate_defconfig.c index 1122998307..e96eca7c94 100644 --- a/src/tools/_confgen/generate_defconfig.c +++ b/src/tools/_confgen/generate_defconfig.c @@ -193,6 +193,18 @@ void gendef_pf_standards_conformance (FILE *out, void *parent, struct cfgelem co void gendef_pf_shm_loglevel (FILE *out, void *parent, struct cfgelem const * const cfgelem) { gendef_pf_int (out, parent, cfgelem); } +void gendef_pf_topic_array (FILE *out, void *parent, struct cfgelem const * const cfgelem) { + struct ddsi_config_topic_array * elem = cfg_address (parent, cfgelem); + if (elem->size == 0) { + // The default zero-initialization does the right thing, nothing to do here + } else { + // Creating an initializer out of a dds_config_topic_array is a bit involved (we'd need to + // glue the topics back together with commas and also set up the allocation just like split_at_comma + // does it). At the same time, it's probably not useful. So restrict the gendef to empty arrays for now + // and implement this once it's actually needed. + fprintf(out, "#error \"Non-empty topic arrays not supported in default config\"\n"); + } +} static void gen_defaults (FILE *out, void *parent, struct cfgelem const * const cfgelem) { From 1024475cfd3da3180f9d033a87880cece3f72531 Mon Sep 17 00:00:00 2001 From: Tobias Stark Date: Wed, 19 Jun 2024 13:56:42 +0000 Subject: [PATCH 2/4] Change config format of topic allow/denylists to XML elements --- docs/manual/config/config_file_reference.rst | 101 ++++++++++++++----- docs/manual/options.md | 65 ++++++++---- etc/cyclonedds.rnc | 52 ++++++---- etc/cyclonedds.xsd | 64 ++++++++---- src/core/ddsc/src/dds_psmx.c | 36 +++---- src/core/ddsi/defconfig.c | 10 +- src/core/ddsi/include/dds/ddsi/ddsi_config.h | 14 +-- src/core/ddsi/src/ddsi__cfgelems.h | 55 +++++++--- src/core/ddsi/src/ddsi_config.c | 41 +------- src/tools/_confgen/_confgen.h | 1 - src/tools/_confgen/generate_defconfig.c | 12 --- 11 files changed, 280 insertions(+), 171 deletions(-) diff --git a/docs/manual/config/config_file_reference.rst b/docs/manual/config/config_file_reference.rst index 199709a2a8..797058b7b9 100644 --- a/docs/manual/config/config_file_reference.rst +++ b/docs/manual/config/config_file_reference.rst @@ -654,7 +654,8 @@ The default value is: ``default`` //CycloneDDS/Domain/General/Interfaces/PubSubMessageExchange ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -Attributes: :ref:`config`, :ref:`forbiddenTopics`, :ref:`library`, :ref:`name`, :ref:`onlyForTopics`, :ref:`priority` +Attributes: :ref:`config`, :ref:`library`, :ref:`name`, :ref:`priority` +Children: :ref:`forbiddenTopics`, :ref:`onlyForTopics` This element defines a PSMX. @@ -671,18 +672,6 @@ This attribute specifies any configuration data for the PSMX instance.This has n The default value is: ```` -.. _`//CycloneDDS/Domain/General/Interfaces/PubSubMessageExchange[@forbiddenTopics]`: - -//CycloneDDS/Domain/General/Interfaces/PubSubMessageExchange[@forbiddenTopics] -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -Text - -A comma-separated list of topics that should never use this psmx.Mutually exclusive with onlyForTopics. - -The default value is: ```` - - .. _`//CycloneDDS/Domain/General/Interfaces/PubSubMessageExchange[@library]`: //CycloneDDS/Domain/General/Interfaces/PubSubMessageExchange[@library] @@ -707,28 +696,86 @@ This attribute specifies the name of the interface. The default value is: ```` -.. _`//CycloneDDS/Domain/General/Interfaces/PubSubMessageExchange[@onlyForTopics]`: +.. _`//CycloneDDS/Domain/General/Interfaces/PubSubMessageExchange[@priority]`: -//CycloneDDS/Domain/General/Interfaces/PubSubMessageExchange[@onlyForTopics] -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +//CycloneDDS/Domain/General/Interfaces/PubSubMessageExchange[@priority] +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Text -A comma-separated list of all the topics that should use this PSMX.This option can be used to restrict the PSMX to a selected list of topics.Mutually exclusive with forbiddenTopics. +This attribute specifies the interface priority (decimal integer or default). The default value for a PSMX is 0. + +The default value is: ``default`` + + +.. _`//CycloneDDS/Domain/General/Interfaces/PubSubMessageExchange/forbiddenTopics`: + +//CycloneDDS/Domain/General/Interfaces/PubSubMessageExchange/forbiddenTopics +"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" + +Children: :ref:`Pattern` + +A list of topics that should never use this psmx. Mutually exclusive with onlyForTopics. + + +.. _`//CycloneDDS/Domain/General/Interfaces/PubSubMessageExchange/forbiddenTopics/Pattern`: + +//CycloneDDS/Domain/General/Interfaces/PubSubMessageExchange/forbiddenTopics/Pattern +____________________________________________________________________________________ + +Attributes: :ref:`value` + +Text + +A pattern (with ? and \* wildcards) that is matched against topics. The default value is: ```` -.. _`//CycloneDDS/Domain/General/Interfaces/PubSubMessageExchange[@priority]`: +.. _`//CycloneDDS/Domain/General/Interfaces/PubSubMessageExchange/forbiddenTopics/Pattern[@value]`: -//CycloneDDS/Domain/General/Interfaces/PubSubMessageExchange[@priority] -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +//CycloneDDS/Domain/General/Interfaces/PubSubMessageExchange/forbiddenTopics/Pattern[@value] +____________________________________________________________________________________________ Text -This attribute specifies the interface priority (decimal integer or default). The default value for a PSMX is 0. -The default value is: ``default`` +The default value is: ```` + + +.. _`//CycloneDDS/Domain/General/Interfaces/PubSubMessageExchange/onlyForTopics`: + +//CycloneDDS/Domain/General/Interfaces/PubSubMessageExchange/onlyForTopics +"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" + +Children: :ref:`Pattern` + +A list of topics that should never use this psmx. Mutually exclusive with onlyForTopics. + + +.. _`//CycloneDDS/Domain/General/Interfaces/PubSubMessageExchange/onlyForTopics/Pattern`: + +//CycloneDDS/Domain/General/Interfaces/PubSubMessageExchange/onlyForTopics/Pattern +__________________________________________________________________________________ + +Attributes: :ref:`value` + +Text + +A pattern (with ? and \* wildcards) that is matched against topics. + +The default value is: ```` + + +.. _`//CycloneDDS/Domain/General/Interfaces/PubSubMessageExchange/forbiddenTopics/Pattern[@value]`: + +//CycloneDDS/Domain/General/Interfaces/PubSubMessageExchange/forbiddenTopics/Pattern[@value] +____________________________________________________________________________________________ + +Text + + +The default value is: ```` .. _`//CycloneDDS/Domain/General/MaxMessageSize`: @@ -2728,14 +2775,14 @@ The categorisation of tracing output is incomplete and hence most of the verbosi The default value is: ``none`` .. - generated from ddsi_config.h[99b38dad99d609bd1f2e2aa7b43cf2a3aa10948d] + generated from ddsi_config.h[58d1dd144dc0e8f3c3ef331fd4472eec7f797c71] generated from ddsi__cfgunits.h[bd22f0c0ed210501d0ecd3b07c992eca549ef5aa] - generated from ddsi__cfgelems.h[fdfcbecb910d6a859d5e5ab25d81065aaca18ae8] - generated from ddsi_config.c[3f9cdfe5934118aeb3e6f7e8d9b71f815e8021c2] - generated from _confgen.h[b3b98385ecc752860a55e126b3893423730f53ab] + generated from ddsi__cfgelems.h[714f801d2988b476694a198097d36169f7e5e129] + generated from ddsi_config.c[4a1074588af66b81f8fd45393cdecff2b5d55b4d] + generated from _confgen.h[e32eabfc35e9f3a7dcb63b19ed148c0d17c6e5fc] generated from _confgen.c[237308acd53897a34e8c643e16e05a61d73ffd65] generated from generate_rnc.c[b50e4b7ab1d04b2bc1d361a0811247c337b74934] generated from generate_md.c[789b92e422631684352909cfb8bf43f6ceb16a01] generated from generate_rst.c[3c4b523fbb57c8e4a7e247379d06a8021ccc21c4] generated from generate_xsd.c[6b6818d7f17a35d56c376c04ec1410427f34c0f0] - generated from generate_defconfig.c[0ef1411470804c3db386c20c8752b161eb8418ae] + generated from generate_defconfig.c[63ca9d8ae2f1ce2e761c9d4c0510a45eb062d830] diff --git a/docs/manual/options.md b/docs/manual/options.md index b8ef648685..03a94d3e13 100644 --- a/docs/manual/options.md +++ b/docs/manual/options.md @@ -437,7 +437,8 @@ The default value is: `default` ##### //CycloneDDS/Domain/General/Interfaces/PubSubMessageExchange -Attributes: [config](#cycloneddsdomaingeneralinterfacespubsubmessageexchangeconfig), [forbiddenTopics](#cycloneddsdomaingeneralinterfacespubsubmessageexchangeforbiddentopics), [library](#cycloneddsdomaingeneralinterfacespubsubmessageexchangelibrary), [name](#cycloneddsdomaingeneralinterfacespubsubmessageexchangename), [onlyForTopics](#cycloneddsdomaingeneralinterfacespubsubmessageexchangeonlyfortopics), [priority](#cycloneddsdomaingeneralinterfacespubsubmessageexchangepriority) +Attributes: [config](#cycloneddsdomaingeneralinterfacespubsubmessageexchangeconfig), [library](#cycloneddsdomaingeneralinterfacespubsubmessageexchangelibrary), [name](#cycloneddsdomaingeneralinterfacespubsubmessageexchangename), [priority](#cycloneddsdomaingeneralinterfacespubsubmessageexchangepriority) +Children: [forbiddenTopics](#cycloneddsdomaingeneralinterfacespubsubmessageexchangeforbiddentopics), [onlyForTopics](#cycloneddsdomaingeneralinterfacespubsubmessageexchangeonlyfortopics) This element defines a PSMX. @@ -450,44 +451,74 @@ This attribute specifies any configuration data for the PSMX instance.This has n The default value is: `` -##### //CycloneDDS/Domain/General/Interfaces/PubSubMessageExchange[@forbiddenTopics] +##### //CycloneDDS/Domain/General/Interfaces/PubSubMessageExchange[@library] Text -A comma-separated list of topics that should never use this psmx.Mutually exclusive with onlyForTopics. +This attribute specifies the filename of the interface library. The default value is: `` -##### //CycloneDDS/Domain/General/Interfaces/PubSubMessageExchange[@library] +##### //CycloneDDS/Domain/General/Interfaces/PubSubMessageExchange[@name] Text -This attribute specifies the filename of the interface library. +This attribute specifies the name of the interface. The default value is: `` -##### //CycloneDDS/Domain/General/Interfaces/PubSubMessageExchange[@name] +##### //CycloneDDS/Domain/General/Interfaces/PubSubMessageExchange[@priority] Text -This attribute specifies the name of the interface. +This attribute specifies the interface priority (decimal integer or default). The default value for a PSMX is 0. + +The default value is: `default` + + +###### //CycloneDDS/Domain/General/Interfaces/PubSubMessageExchange/forbiddenTopics +Children: [Pattern](#cycloneddsdomaingeneralinterfacespubsubmessageexchangeforbiddentopicspattern) + +A list of topics that should never use this psmx. Mutually exclusive with onlyForTopics. + + +####### //CycloneDDS/Domain/General/Interfaces/PubSubMessageExchange/forbiddenTopics/Pattern +Attributes: [value](#cycloneddsdomaingeneralinterfacespubsubmessageexchangeforbiddentopicspatternvalue) + +Text + +A pattern (with ? and \* wildcards) that is matched against topics. The default value is: `` -##### //CycloneDDS/Domain/General/Interfaces/PubSubMessageExchange[@onlyForTopics] +####### //CycloneDDS/Domain/General/Interfaces/PubSubMessageExchange/forbiddenTopics/Pattern[@value] Text -A comma-separated list of all the topics that should use this PSMX.This option can be used to restrict the PSMX to a selected list of topics.Mutually exclusive with forbiddenTopics. The default value is: `` -##### //CycloneDDS/Domain/General/Interfaces/PubSubMessageExchange[@priority] +###### //CycloneDDS/Domain/General/Interfaces/PubSubMessageExchange/onlyForTopics +Children: [Pattern](#cycloneddsdomaingeneralinterfacespubsubmessageexchangeonlyfortopicspattern) + +A list of topics that should never use this psmx. Mutually exclusive with onlyForTopics. + + +####### //CycloneDDS/Domain/General/Interfaces/PubSubMessageExchange/onlyForTopics/Pattern +Attributes: [value](#cycloneddsdomaingeneralinterfacespubsubmessageexchangeforbiddentopicspatternvalue) + Text -This attribute specifies the interface priority (decimal integer or default). The default value for a PSMX is 0. +A pattern (with ? and \* wildcards) that is matched against topics. -The default value is: `default` +The default value is: `` + + +####### //CycloneDDS/Domain/General/Interfaces/PubSubMessageExchange/forbiddenTopics/Pattern[@value] +Text + + +The default value is: `` #### //CycloneDDS/Domain/General/MaxMessageSize @@ -1914,14 +1945,14 @@ 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` - + - - - + + + - + diff --git a/etc/cyclonedds.rnc b/etc/cyclonedds.rnc index 6209957a25..44f6a20acb 100644 --- a/etc/cyclonedds.rnc +++ b/etc/cyclonedds.rnc @@ -317,12 +317,6 @@ CycloneDDS configuration""" ] ] text }? & [ a:documentation [ xml:lang="en" """ -

A comma-separated list of topics that should never use this psmx.Mutually exclusive with onlyForTopics.

-

The default value is: <empty>

""" ] ] - attribute forbiddenTopics { - text - }? - & [ a:documentation [ xml:lang="en" """

This attribute specifies the filename of the interface library.

The default value is: <empty>

""" ] ] attribute library { @@ -335,17 +329,41 @@ CycloneDDS configuration""" ] ] text }? & [ a:documentation [ xml:lang="en" """ -

A comma-separated list of all the topics that should use this PSMX.This option can be used to restrict the PSMX to a selected list of topics.Mutually exclusive with forbiddenTopics.

-

The default value is: <empty>

""" ] ] - attribute onlyForTopics { - text - }? - & [ a:documentation [ xml:lang="en" """

This attribute specifies the interface priority (decimal integer or default). The default value for a PSMX is 0.

The default value is: default

""" ] ] attribute priority { text }? + & [ a:documentation [ xml:lang="en" """ +

A list of topics that should never use this psmx. Mutually exclusive with onlyForTopics.

""" ] ] + element forbiddenTopics { + [ a:documentation [ xml:lang="en" """ +

A pattern (with ? and * wildcards) that is matched against topics.

+

The default value is: <empty>

""" ] ] + element Pattern { + [ a:documentation [ xml:lang="en" """ + +

The default value is: <empty>

""" ] ] + attribute value { + text + } + }* + }? + & [ a:documentation [ xml:lang="en" """ +

A list of topics that should never use this psmx. Mutually exclusive with onlyForTopics.

""" ] ] + element onlyForTopics { + [ a:documentation [ xml:lang="en" """ +

A pattern (with ? and * wildcards) that is matched against topics.

+

The default value is: <empty>

""" ] ] + element Pattern { + [ a:documentation [ xml:lang="en" """ + +

The default value is: <empty>

""" ] ] + attribute value { + text + } + }* + }? }* }? & [ a:documentation [ xml:lang="en" """ @@ -1325,14 +1343,14 @@ MIIEpAIBAAKCAQEA3HIh...AOBaaqSV37XBUJg==
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[99b38dad99d609bd1f2e2aa7b43cf2a3aa10948d] +# generated from ddsi_config.h[58d1dd144dc0e8f3c3ef331fd4472eec7f797c71] # generated from ddsi__cfgunits.h[bd22f0c0ed210501d0ecd3b07c992eca549ef5aa] -# generated from ddsi__cfgelems.h[fdfcbecb910d6a859d5e5ab25d81065aaca18ae8] -# generated from ddsi_config.c[3f9cdfe5934118aeb3e6f7e8d9b71f815e8021c2] -# generated from _confgen.h[b3b98385ecc752860a55e126b3893423730f53ab] +# generated from ddsi__cfgelems.h[714f801d2988b476694a198097d36169f7e5e129] +# generated from ddsi_config.c[4a1074588af66b81f8fd45393cdecff2b5d55b4d] +# generated from _confgen.h[e32eabfc35e9f3a7dcb63b19ed148c0d17c6e5fc] # generated from _confgen.c[237308acd53897a34e8c643e16e05a61d73ffd65] # generated from generate_rnc.c[b50e4b7ab1d04b2bc1d361a0811247c337b74934] # generated from generate_md.c[789b92e422631684352909cfb8bf43f6ceb16a01] # generated from generate_rst.c[3c4b523fbb57c8e4a7e247379d06a8021ccc21c4] # generated from generate_xsd.c[6b6818d7f17a35d56c376c04ec1410427f34c0f0] -# generated from generate_defconfig.c[0ef1411470804c3db386c20c8752b161eb8418ae] +# generated from generate_defconfig.c[63ca9d8ae2f1ce2e761c9d4c0510a45eb062d830] diff --git a/etc/cyclonedds.xsd b/etc/cyclonedds.xsd index 2a8077fb62..2d810743f7 100644 --- a/etc/cyclonedds.xsd +++ b/etc/cyclonedds.xsd @@ -498,17 +498,14 @@ CycloneDDS configuration <p>This element defines a PSMX.</p> + + + + <p>This attribute specifies any configuration data for the PSMX instance.This has no meaning in CycloneDDS itself, and its parsing is deferred to thePSMX implementation.</p> -<p>The default value is: <code>&lt;empty&gt;</code></p> - - - - - -<p>A comma-separated list of topics that should never use this psmx.Mutually exclusive with onlyForTopics.</p> <p>The default value is: <code>&lt;empty&gt;</code></p> @@ -526,22 +523,53 @@ CycloneDDS configuration <p>The default value is: <code>&lt;empty&gt;</code></p> - + -<p>A comma-separated list of all the topics that should use this PSMX.This option can be used to restrict the PSMX to a selected list of topics.Mutually exclusive with forbiddenTopics.</p> -<p>The default value is: <code>&lt;empty&gt;</code></p> +<p>This attribute specifies the interface priority (decimal integer or <i>default</i>). The default value for a PSMX is 0.</p> +<p>The default value is: <code>default</code></p> - + + + + + +<p>A list of topics that should never use this psmx. Mutually exclusive with onlyForTopics. </p> + + + + + + + + + + +<p>A pattern (with ? and * wildcards) that is matched against topics. </p> +<p>The default value is: <code>&lt;empty&gt;</code></p> + + + -<p>This attribute specifies the interface priority (decimal integer or <i>default</i>). The default value for a PSMX is 0.</p> -<p>The default value is: <code>default</code></p> + +<p>The default value is: <code>&lt;empty&gt;</code></p> + + + +<p>A list of topics that should never use this psmx. Mutually exclusive with onlyForTopics. </p> + + + + + + + @@ -1985,14 +2013,14 @@ MIIEpAIBAAKCAQEA3HIh...AOBaaqSV37XBUJg==<br> - + - - - + + + - + diff --git a/src/core/ddsc/src/dds_psmx.c b/src/core/ddsc/src/dds_psmx.c index 76e2412102..a9e8fd6424 100644 --- a/src/core/ddsc/src/dds_psmx.c +++ b/src/core/ddsc/src/dds_psmx.c @@ -331,36 +331,38 @@ static dds_return_t psmx_instance_load (const struct ddsi_domaingv *gv, const st } psmx_instance->priority = config->priority.value; - if (config->only_for_topics.size > 0 && config->forbidden_topics.size > 0) { + if (config->only_for_topics && config->forbidden_topics) { ret = DDS_RETCODE_UNSUPPORTED; GVERROR ("Failed to initialize PSMX instance '%s': conflicting options only_for_topics and forbidden_topics were both present", config->name); goto err_init; } - // Copy over the only_for_topics and forbidden_topics array, switching to nullptr-terminated array of separately-allocated strings 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; + size_t list_size = 0; + for (struct ddsi_config_topic_pattern_listelem * elem = pattern_list; + elem; + elem = elem->next) { + list_size++; + } + // Allocate +1 for the final nullptr terminator - psmx_instance->only_for_topics = ddsrt_calloc_s(config->only_for_topics.size + 1, sizeof(char*)); - psmx_instance->forbidden_topics = ddsrt_calloc_s(config->forbidden_topics.size + 1, sizeof(char*)); - if (!psmx_instance->only_for_topics || !psmx_instance->forbidden_topics) { + *pattern_array_ptr = ddsrt_calloc_s(list_size + 1, sizeof(char*)); + if (!*pattern_array_ptr) { GVERROR ("Failed to initialize PSMX instance '%s': out of memory", config->name); - goto err_topic_arrays_oom; + goto err_init; } - for (size_t i = 0 ; i < config->only_for_topics.size; i++) { - psmx_instance->only_for_topics[i] = ddsrt_strdup(config->only_for_topics.topics[i]); - if (psmx_instance->only_for_topics[i] == NULL) { - GVERROR ("Failed to initialize PSMX instance '%s': out of memory", - config->name); - goto err_topic_arrays_oom; - } - } - for (size_t i = 0 ; i < config->forbidden_topics.size; i++) { - psmx_instance->forbidden_topics[i] = ddsrt_strdup(config->forbidden_topics.topics[i]); - if (psmx_instance->forbidden_topics[i] == NULL) { + + const struct ddsi_config_topic_pattern_listelem * elem = pattern_list; + for (int i = 0; elem; i++, elem = elem->next) { + (*pattern_array_ptr)[i] = ddsrt_strdup(elem->pattern); + if ((*pattern_array_ptr)[i] == NULL) { GVERROR ("Failed to initialize PSMX instance '%s': out of memory", config->name); goto err_topic_arrays_oom; diff --git a/src/core/ddsi/defconfig.c b/src/core/ddsi/defconfig.c index c6953d5947..89d88cd119 100644 --- a/src/core/ddsi/defconfig.c +++ b/src/core/ddsi/defconfig.c @@ -99,14 +99,14 @@ 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[99b38dad99d609bd1f2e2aa7b43cf2a3aa10948d] */ +/* generated from ddsi_config.h[58d1dd144dc0e8f3c3ef331fd4472eec7f797c71] */ /* generated from ddsi__cfgunits.h[bd22f0c0ed210501d0ecd3b07c992eca549ef5aa] */ -/* generated from ddsi__cfgelems.h[fdfcbecb910d6a859d5e5ab25d81065aaca18ae8] */ -/* generated from ddsi_config.c[3f9cdfe5934118aeb3e6f7e8d9b71f815e8021c2] */ -/* generated from _confgen.h[b3b98385ecc752860a55e126b3893423730f53ab] */ +/* generated from ddsi__cfgelems.h[714f801d2988b476694a198097d36169f7e5e129] */ +/* generated from ddsi_config.c[4a1074588af66b81f8fd45393cdecff2b5d55b4d] */ +/* generated from _confgen.h[e32eabfc35e9f3a7dcb63b19ed148c0d17c6e5fc] */ /* generated from _confgen.c[237308acd53897a34e8c643e16e05a61d73ffd65] */ /* generated from generate_rnc.c[b50e4b7ab1d04b2bc1d361a0811247c337b74934] */ /* generated from generate_md.c[789b92e422631684352909cfb8bf43f6ceb16a01] */ /* generated from generate_rst.c[3c4b523fbb57c8e4a7e247379d06a8021ccc21c4] */ /* generated from generate_xsd.c[6b6818d7f17a35d56c376c04ec1410427f34c0f0] */ -/* generated from generate_defconfig.c[0ef1411470804c3db386c20c8752b161eb8418ae] */ +/* generated from generate_defconfig.c[63ca9d8ae2f1ce2e761c9d4c0510a45eb062d830] */ diff --git a/src/core/ddsi/include/dds/ddsi/ddsi_config.h b/src/core/ddsi/include/dds/ddsi/ddsi_config.h index 890e6c5ce8..0aa2518828 100644 --- a/src/core/ddsi/include/dds/ddsi/ddsi_config.h +++ b/src/core/ddsi/include/dds/ddsi/ddsi_config.h @@ -237,13 +237,9 @@ enum ddsi_config_entity_naming_mode { DDSI_ENTITY_NAMING_DEFAULT_FANCY }; -// The array is stored as size + pointer to pointer array. -// If size is zero, the pointer is NULL rather than a pointer to an empty array. -// The pointed-to strings are allocated right after the array, so -// a simple `free(topics)` frees everything -struct ddsi_config_topic_array { - size_t size; - char **topics; +struct ddsi_config_topic_pattern_listelem { + struct ddsi_config_topic_pattern_listelem *next; + const char *pattern; }; struct ddsi_config_psmx { @@ -251,8 +247,8 @@ struct ddsi_config_psmx { char *library; char *config; struct ddsi_config_maybe_int32 priority; - struct ddsi_config_topic_array forbidden_topics; - struct ddsi_config_topic_array only_for_topics; + struct ddsi_config_topic_pattern_listelem *forbidden_topics; + struct ddsi_config_topic_pattern_listelem *only_for_topics; }; struct ddsi_config_psmx_listelem { diff --git a/src/core/ddsi/src/ddsi__cfgelems.h b/src/core/ddsi/src/ddsi__cfgelems.h index c93be2c109..696544267e 100644 --- a/src/core/ddsi/src/ddsi__cfgelems.h +++ b/src/core/ddsi/src/ddsi__cfgelems.h @@ -106,6 +106,34 @@ static struct cfgelem network_interface_attributes[] = { END_MARKER }; +static struct cfgelem topic_pattern_cfgattr[] = { + STRING("value", NULL, 1, NULL, + MEMBEROF(ddsi_config_topic_pattern_listelem, pattern), + FUNCTIONS(0, uf_string, ff_free, pf_string), + DESCRIPTION("")), + END_MARKER +}; + +static struct cfgelem only_for_topics_cfgelem[] = { + STRING("Pattern", topic_pattern_cfgattr, INT_MAX, NULL, + MEMBEROF(ddsi_config_psmx_listelem, cfg.only_for_topics), + FUNCTIONS(if_topic_pattern_list, 0, 0, 0), + DESCRIPTION( + "

A pattern (with ? and * wildcards) that is matched against topics.

" + )), + END_MARKER +}; + +static struct cfgelem forbidden_topics_cfgelem[] = { + STRING("Pattern", topic_pattern_cfgattr, INT_MAX, NULL, + MEMBEROF(ddsi_config_psmx_listelem, cfg.forbidden_topics), + FUNCTIONS(if_topic_pattern_list, 0, 0, 0), + DESCRIPTION( + "

A pattern (with ? and * wildcards) that is matched against topics.

" + )), + END_MARKER +}; + static struct cfgelem psmx_attributes[] = { STRING("name", NULL, 1, "", MEMBEROF(ddsi_config_psmx_listelem, cfg.name), @@ -134,20 +162,23 @@ static struct cfgelem psmx_attributes[] = { "This has no meaning in CycloneDDS itself, and its parsing is deferred to the" "PSMX implementation.

" )), - STRING("forbiddenTopics", NULL, 1, "", - MEMBEROF(ddsi_config_psmx_listelem, cfg.forbidden_topics), - FUNCTIONS(if_topic_array, uf_topic_array, ff_topic_array, pf_topic_array), + END_MARKER +}; + +static struct cfgelem psmx_cfgelems[] = { + GROUP("forbiddenTopics", forbidden_topics_cfgelem, NULL, 1, + NOMEMBER, + NOFUNCTIONS, DESCRIPTION( - "

A comma-separated list of topics that should never use this psmx." - "Mutually exclusive with onlyForTopics.

" + "

A list of topics that should never use this psmx. " + "Mutually exclusive with onlyForTopics.

" )), - STRING("onlyForTopics", NULL, 1, "", - MEMBEROF(ddsi_config_psmx_listelem, cfg.only_for_topics), - FUNCTIONS(if_topic_array, uf_topic_array, ff_topic_array, pf_topic_array), + GROUP("onlyForTopics", only_for_topics_cfgelem, NULL, 1, + NOMEMBER, + NOFUNCTIONS, DESCRIPTION( - "

A comma-separated list of all the topics that should use this PSMX." - "This option can be used to restrict the PSMX to a selected list of topics." - "Mutually exclusive with forbiddenTopics.

" + "

A list of topics that should never use this psmx. " + "Mutually exclusive with onlyForTopics.

" )), END_MARKER }; @@ -161,7 +192,7 @@ static struct cfgelem interfaces_cfgelems[] = { "to autoselect the interface CycloneDDS considers the highest quality. If " "autodetermine=\"false\" (the default), you must specify the name and/or address " "attribute. If you specify both, they must match the same interface.

")), - GROUP("PubSubMessageExchange", NULL, psmx_attributes, INT_MAX, + GROUP("PubSubMessageExchange", psmx_cfgelems, psmx_attributes, INT_MAX, MEMBER(psmx_instances), FUNCTIONS(if_psmx, 0, 0, 0), DESCRIPTION( diff --git a/src/core/ddsi/src/ddsi_config.c b/src/core/ddsi/src/ddsi_config.c index dd9a990906..4ad5084182 100644 --- a/src/core/ddsi/src/ddsi_config.c +++ b/src/core/ddsi/src/ddsi_config.c @@ -197,7 +197,6 @@ DU(deaf_mute); DUPF(min_tls_version); #endif DUPF(shm_loglevel); -DUPF(topic_array); #undef DUPF #undef DU #undef PF @@ -205,7 +204,6 @@ DUPF(topic_array); #define DF(fname) static void fname (struct ddsi_cfgst *cfgst, void *parent, struct cfgelem const * const cfgelem) DF(ff_free); DF(ff_networkAddresses); -DF(ff_topic_array); #undef DF #define DI(fname) static int fname (struct ddsi_cfgst *cfgst, void *parent, struct cfgelem const * const cfgelem) @@ -221,7 +219,7 @@ DI(if_thread_properties); #ifdef DDS_HAS_SECURITY DI(if_omg_security); #endif -DI(if_topic_array); +DI(if_topic_pattern_list); #undef DI /* drop extra information, i.e. DESCRIPTION, RANGE, UNIT and VALUES */ @@ -1285,42 +1283,13 @@ static void ff_networkAddresses (struct ddsi_cfgst *cfgst, void *parent, struct ddsrt_free (*elem); } -static int if_topic_array(struct ddsi_cfgst *cfgst, void *parent, struct cfgelem const * const cfgelem) { - struct ddsi_config_topic_array * elem = cfg_address (cfgst, parent, cfgelem); - elem->size = 0; - elem->topics = NULL; +static int if_topic_pattern_list(struct ddsi_cfgst *cfgst, void *parent, struct cfgelem const * const cfgelem) { + struct ddsi_config_topic_pattern_listelem * new = if_common (cfgst, parent, cfgelem, sizeof(*new)); + if (new == NULL) + return -1; return 0; } -static enum update_result uf_topic_array (struct ddsi_cfgst *cfgst, void *parent, struct cfgelem const * const cfgelem, UNUSED_ARG(int first), const char *value) { - struct ddsi_config_topic_array * elem = cfg_address (cfgst, parent, cfgelem); - free(elem->topics); - if (*value == '\0') { - elem->size = 0; - elem->topics = NULL; - } else { - elem->topics = split_at_comma(value, &elem->size); - } - return URES_SUCCESS; -} - -static void ff_topic_array (struct ddsi_cfgst *cfgst, void *parent, struct cfgelem const * const cfgelem) { - struct ddsi_config_topic_array * elem = cfg_address (cfgst, parent, cfgelem); - free(elem->topics); -} - -static void pf_topic_array (struct ddsi_cfgst *cfgst, UNUSED_ARG (void *parent), UNUSED_ARG (struct cfgelem const * const cfgelem), uint32_t sources) { - struct ddsi_config_topic_array * elem = cfg_address (cfgst, parent, cfgelem); - if (elem->size == 0) { - // Just passing "" produces a "zero-length format string" warning - cfg_logelem (cfgst, sources, "%s", ""); - } else { - for (size_t i = 0; i < elem->size; ++i) { - cfg_logelem (cfgst, sources, "%s", elem->topics[i]); - } - } -} - #ifdef DDSRT_HAVE_SSM static const char *allow_multicast_names[] = { "false", "spdp", "asm", "ssm", "true", NULL }; static const uint32_t allow_multicast_codes[] = { DDSI_AMC_FALSE, DDSI_AMC_SPDP, DDSI_AMC_ASM, DDSI_AMC_SSM, DDSI_AMC_TRUE }; diff --git a/src/tools/_confgen/_confgen.h b/src/tools/_confgen/_confgen.h index b404bacca1..cd64e8ae90 100644 --- a/src/tools/_confgen/_confgen.h +++ b/src/tools/_confgen/_confgen.h @@ -53,7 +53,6 @@ void gendef_pf_transport_selector (FILE *fp, void *parent, struct cfgelem const void gendef_pf_many_sockets_mode (FILE *fp, void *parent, struct cfgelem const * const cfgelem); void gendef_pf_standards_conformance (FILE *fp, void *parent, struct cfgelem const * const cfgelem); void gendef_pf_shm_loglevel (FILE *fp, void *parent, struct cfgelem const * const cfgelem); -void gendef_pf_topic_array (FILE *fp, void *parent, struct cfgelem const * const cfgelem); struct cfgunit { const char *name; diff --git a/src/tools/_confgen/generate_defconfig.c b/src/tools/_confgen/generate_defconfig.c index e96eca7c94..1122998307 100644 --- a/src/tools/_confgen/generate_defconfig.c +++ b/src/tools/_confgen/generate_defconfig.c @@ -193,18 +193,6 @@ void gendef_pf_standards_conformance (FILE *out, void *parent, struct cfgelem co void gendef_pf_shm_loglevel (FILE *out, void *parent, struct cfgelem const * const cfgelem) { gendef_pf_int (out, parent, cfgelem); } -void gendef_pf_topic_array (FILE *out, void *parent, struct cfgelem const * const cfgelem) { - struct ddsi_config_topic_array * elem = cfg_address (parent, cfgelem); - if (elem->size == 0) { - // The default zero-initialization does the right thing, nothing to do here - } else { - // Creating an initializer out of a dds_config_topic_array is a bit involved (we'd need to - // glue the topics back together with commas and also set up the allocation just like split_at_comma - // does it). At the same time, it's probably not useful. So restrict the gendef to empty arrays for now - // and implement this once it's actually needed. - fprintf(out, "#error \"Non-empty topic arrays not supported in default config\"\n"); - } -} static void gen_defaults (FILE *out, void *parent, struct cfgelem const * const cfgelem) { From faa4b07d58727b184c1b7e47b80ab8dbb2593e78 Mon Sep 17 00:00:00 2001 From: Tobias Stark Date: Wed, 19 Jun 2024 15:04:38 +0000 Subject: [PATCH 3/4] Interpret only-for-topics/forbidden topics as patterns --- docs/manual/config/config_file_reference.rst | 2 +- docs/manual/options.md | 2 +- etc/cyclonedds.rnc | 2 +- etc/cyclonedds.xsd | 2 +- src/core/ddsc/src/dds_psmx.c | 16 +++++++++++++--- src/core/ddsc/src/dds_topic.c | 12 +++++++----- src/core/ddsc/tests/config.c | 1 + src/core/ddsc/tests/redundantnw.c | 1 + src/core/ddsi/CMakeLists.txt | 1 + src/core/ddsi/defconfig.c | 2 +- src/core/ddsi/src/ddsi__misc.h | 3 --- src/core/ddsi/src/ddsi_misc.c | 1 + src/core/ddsi/src/ddsi_qosmatch.c | 1 + src/security/core/tests/config.c | 1 + src/security/core/tests/plugin_loading.c | 1 + 15 files changed, 32 insertions(+), 16 deletions(-) diff --git a/docs/manual/config/config_file_reference.rst b/docs/manual/config/config_file_reference.rst index 797058b7b9..7ba7eb79a1 100644 --- a/docs/manual/config/config_file_reference.rst +++ b/docs/manual/config/config_file_reference.rst @@ -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] diff --git a/docs/manual/options.md b/docs/manual/options.md index 03a94d3e13..7c0b2488ce 100644 --- a/docs/manual/options.md +++ b/docs/manual/options.md @@ -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` - + diff --git a/etc/cyclonedds.rnc b/etc/cyclonedds.rnc index 44f6a20acb..ac6c4a902a 100644 --- a/etc/cyclonedds.rnc +++ b/etc/cyclonedds.rnc @@ -1343,7 +1343,7 @@ MIIEpAIBAAKCAQEA3HIh...AOBaaqSV37XBUJg==
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] diff --git a/etc/cyclonedds.xsd b/etc/cyclonedds.xsd index 2d810743f7..b5523ed283 100644 --- a/etc/cyclonedds.xsd +++ b/etc/cyclonedds.xsd @@ -2013,7 +2013,7 @@ MIIEpAIBAAKCAQEA3HIh...AOBaaqSV37XBUJg==<br> - + diff --git a/src/core/ddsc/src/dds_psmx.c b/src/core/ddsc/src/dds_psmx.c index a9e8fd6424..e48dab5042 100644 --- a/src/core/ddsc/src/dds_psmx.c +++ b/src/core/ddsc/src/dds_psmx.c @@ -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; diff --git a/src/core/ddsc/src/dds_topic.c b/src/core/ddsc/src/dds_topic.c index 49eb3b8ef6..f3cda67667 100644 --- a/src/core/ddsc/src/dds_topic.c +++ b/src/core/ddsc/src/dds_topic.c @@ -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" @@ -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; } diff --git a/src/core/ddsc/tests/config.c b/src/core/ddsc/tests/config.c index 33d45bfc3f..f10831291e 100644 --- a/src/core/ddsc/tests/config.c +++ b/src/core/ddsc/tests/config.c @@ -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" diff --git a/src/core/ddsc/tests/redundantnw.c b/src/core/ddsc/tests/redundantnw.c index b7e8400d75..25c54b3b57 100644 --- a/src/core/ddsc/tests/redundantnw.c +++ b/src/core/ddsc/tests/redundantnw.c @@ -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" diff --git a/src/core/ddsi/CMakeLists.txt b/src/core/ddsi/CMakeLists.txt index 685594b693..61bbd66d30 100644 --- a/src/core/ddsi/CMakeLists.txt +++ b/src/core/ddsi/CMakeLists.txt @@ -139,6 +139,7 @@ set(hdrs_ddsi ddsi_xevent.h ddsi_xmsg.h ddsi_psmx.h + ddsi_misc.h ) set(hdrs_private_ddsi diff --git a/src/core/ddsi/defconfig.c b/src/core/ddsi/defconfig.c index 89d88cd119..87b348b429 100644 --- a/src/core/ddsi/defconfig.c +++ b/src/core/ddsi/defconfig.c @@ -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] */ diff --git a/src/core/ddsi/src/ddsi__misc.h b/src/core/ddsi/src/ddsi__misc.h index e940865f47..1498ef82a7 100644 --- a/src/core/ddsi/src/ddsi__misc.h +++ b/src/core/ddsi/src/ddsi__misc.h @@ -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 diff --git a/src/core/ddsi/src/ddsi_misc.c b/src/core/ddsi/src/ddsi_misc.c index fd8b71cc89..1d228a82b1 100644 --- a/src/core/ddsi/src/ddsi_misc.c +++ b/src/core/ddsi/src/ddsi_misc.c @@ -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); diff --git a/src/core/ddsi/src/ddsi_qosmatch.c b/src/core/ddsi/src/ddsi_qosmatch.c index ed3ee4e442..d756233374 100644 --- a/src/core/ddsi/src/ddsi_qosmatch.c +++ b/src/core/ddsi/src/ddsi_qosmatch.c @@ -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" diff --git a/src/security/core/tests/config.c b/src/security/core/tests/config.c index 0f763a04cd..9b24600120 100644 --- a/src/security/core/tests/config.c +++ b/src/security/core/tests/config.c @@ -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" diff --git a/src/security/core/tests/plugin_loading.c b/src/security/core/tests/plugin_loading.c index 266eb00593..8a1fbbdae5 100644 --- a/src/security/core/tests/plugin_loading.c +++ b/src/security/core/tests/plugin_loading.c @@ -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" From 1bc4083b6dfa57bebc7cb5bf72c8557d204e853e Mon Sep 17 00:00:00 2001 From: Tobias Stark Date: Wed, 19 Jun 2024 15:08:06 +0000 Subject: [PATCH 4/4] Remove a few redundant zero initialisations --- docs/manual/config/config_file_reference.rst | 2 +- docs/manual/options.md | 2 +- etc/cyclonedds.rnc | 2 +- etc/cyclonedds.xsd | 2 +- src/core/ddsi/defconfig.c | 2 +- src/core/ddsi/src/ddsi_config.c | 18 ------------------ 6 files changed, 5 insertions(+), 23 deletions(-) diff --git a/docs/manual/config/config_file_reference.rst b/docs/manual/config/config_file_reference.rst index 7ba7eb79a1..776a9907fb 100644 --- a/docs/manual/config/config_file_reference.rst +++ b/docs/manual/config/config_file_reference.rst @@ -2778,7 +2778,7 @@ The default value is: ``none`` generated from ddsi_config.h[9296f1e4eceda8b8514e7859c5584f1cda35412c] generated from ddsi__cfgunits.h[bd22f0c0ed210501d0ecd3b07c992eca549ef5aa] generated from ddsi__cfgelems.h[714f801d2988b476694a198097d36169f7e5e129] - generated from ddsi_config.c[4a1074588af66b81f8fd45393cdecff2b5d55b4d] + generated from ddsi_config.c[6fa39d18f6f0d241b7592a0dc23741e2a934ff2e] generated from _confgen.h[e32eabfc35e9f3a7dcb63b19ed148c0d17c6e5fc] generated from _confgen.c[237308acd53897a34e8c643e16e05a61d73ffd65] generated from generate_rnc.c[b50e4b7ab1d04b2bc1d361a0811247c337b74934] diff --git a/docs/manual/options.md b/docs/manual/options.md index 7c0b2488ce..48717e1727 100644 --- a/docs/manual/options.md +++ b/docs/manual/options.md @@ -1948,7 +1948,7 @@ The default value is: `none` - + diff --git a/etc/cyclonedds.rnc b/etc/cyclonedds.rnc index ac6c4a902a..3ca7939d2f 100644 --- a/etc/cyclonedds.rnc +++ b/etc/cyclonedds.rnc @@ -1346,7 +1346,7 @@ MIIEpAIBAAKCAQEA3HIh...AOBaaqSV37XBUJg==
# generated from ddsi_config.h[9296f1e4eceda8b8514e7859c5584f1cda35412c] # generated from ddsi__cfgunits.h[bd22f0c0ed210501d0ecd3b07c992eca549ef5aa] # generated from ddsi__cfgelems.h[714f801d2988b476694a198097d36169f7e5e129] -# generated from ddsi_config.c[4a1074588af66b81f8fd45393cdecff2b5d55b4d] +# generated from ddsi_config.c[6fa39d18f6f0d241b7592a0dc23741e2a934ff2e] # generated from _confgen.h[e32eabfc35e9f3a7dcb63b19ed148c0d17c6e5fc] # generated from _confgen.c[237308acd53897a34e8c643e16e05a61d73ffd65] # generated from generate_rnc.c[b50e4b7ab1d04b2bc1d361a0811247c337b74934] diff --git a/etc/cyclonedds.xsd b/etc/cyclonedds.xsd index b5523ed283..f927c0524d 100644 --- a/etc/cyclonedds.xsd +++ b/etc/cyclonedds.xsd @@ -2016,7 +2016,7 @@ MIIEpAIBAAKCAQEA3HIh...AOBaaqSV37XBUJg==<br> - + diff --git a/src/core/ddsi/defconfig.c b/src/core/ddsi/defconfig.c index 87b348b429..f374f380ad 100644 --- a/src/core/ddsi/defconfig.c +++ b/src/core/ddsi/defconfig.c @@ -102,7 +102,7 @@ void ddsi_config_init_default (struct ddsi_config *cfg) /* generated from ddsi_config.h[9296f1e4eceda8b8514e7859c5584f1cda35412c] */ /* generated from ddsi__cfgunits.h[bd22f0c0ed210501d0ecd3b07c992eca549ef5aa] */ /* generated from ddsi__cfgelems.h[714f801d2988b476694a198097d36169f7e5e129] */ -/* generated from ddsi_config.c[4a1074588af66b81f8fd45393cdecff2b5d55b4d] */ +/* generated from ddsi_config.c[6fa39d18f6f0d241b7592a0dc23741e2a934ff2e] */ /* generated from _confgen.h[e32eabfc35e9f3a7dcb63b19ed148c0d17c6e5fc] */ /* generated from _confgen.c[237308acd53897a34e8c643e16e05a61d73ffd65] */ /* generated from generate_rnc.c[b50e4b7ab1d04b2bc1d361a0811247c337b74934] */ diff --git a/src/core/ddsi/src/ddsi_config.c b/src/core/ddsi/src/ddsi_config.c index 4ad5084182..b6983127b3 100644 --- a/src/core/ddsi/src/ddsi_config.c +++ b/src/core/ddsi/src/ddsi_config.c @@ -667,7 +667,6 @@ static int if_thread_properties (struct ddsi_cfgst *cfgst, void *parent, struct struct ddsi_config_thread_properties_listelem *new = if_common (cfgst, parent, cfgelem, sizeof(*new)); if (new == NULL) return -1; - new->name = NULL; return 0; } @@ -676,8 +675,6 @@ static int if_network_interfaces(struct ddsi_cfgst *cfgst, void *parent, struct struct ddsi_config_network_interface_listelem *new = if_common (cfgst, parent, cfgelem, sizeof(*new)); if (new == NULL) return -1; - new->cfg.name = NULL; - new->cfg.address = NULL; return 0; } @@ -686,7 +683,6 @@ static int if_psmx(struct ddsi_cfgst *cfgst, void *parent, struct cfgelem const struct ddsi_config_psmx_listelem *new = if_common (cfgst, parent, cfgelem, sizeof(*new)); if (new == NULL) return -1; - memset(&new->cfg, 0, sizeof(new->cfg)); return 0; } @@ -696,14 +692,6 @@ static int if_network_partition (struct ddsi_cfgst *cfgst, void *parent, struct struct ddsi_config_networkpartition_listelem *new = if_common (cfgst, parent, cfgelem, sizeof(*new)); if (new == NULL) return -1; - new->address_string = NULL; - new->interface_names = NULL; - new->uc_addresses = NULL; - new->asm_addresses = NULL; -#ifdef DDSRT_HAVE_SSM - new->ssm_addresses = NULL; -#endif - new->name = NULL; return 0; } @@ -712,7 +700,6 @@ static int if_ignored_partition (struct ddsi_cfgst *cfgst, void *parent, struct struct ddsi_config_ignoredpartition_listelem *new = if_common (cfgst, parent, cfgelem, sizeof(*new)); if (new == NULL) return -1; - new->DCPSPartitionTopic = NULL; return 0; } @@ -721,9 +708,6 @@ static int if_partition_mapping (struct ddsi_cfgst *cfgst, void *parent, struct struct ddsi_config_partitionmapping_listelem *new = if_common (cfgst, parent, cfgelem, sizeof(*new)); if (new == NULL) return -1; - new->DCPSPartitionTopic = NULL; - new->networkPartition = NULL; - new->partition = NULL; return 0; } #endif /* DDS_HAS_NETWORK_PARTITIONS */ @@ -733,7 +717,6 @@ static int if_peer (struct ddsi_cfgst *cfgst, void *parent, struct cfgelem const struct ddsi_config_peer_listelem *new = if_common (cfgst, parent, cfgelem, sizeof (*new)); if (new == NULL) return -1; - new->peer = NULL; return 0; } @@ -743,7 +726,6 @@ static int if_omg_security (struct ddsi_cfgst *cfgst, void *parent, struct cfgel struct ddsi_config_omg_security_listelem *new = if_common (cfgst, parent, cfgelem, sizeof (*new)); if (new == NULL) return -1; - memset(&new->cfg, 0, sizeof(new->cfg)); return 0; } #endif