From f97bc19434fc01d844a0f09a54e0e72d37f9117a Mon Sep 17 00:00:00 2001 From: Jon Shallow Date: Thu, 13 Feb 2025 12:52:04 +0000 Subject: [PATCH] Observe: Clarify observing of Unknown or Proxy URIs is not supported --- man/coap_observe.txt.in | 6 ++++-- src/coap_resource.c | 8 +++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/man/coap_observe.txt.in b/man/coap_observe.txt.in index 06228048..9466e334 100644 --- a/man/coap_observe.txt.in +++ b/man/coap_observe.txt.in @@ -99,11 +99,13 @@ observable status of the _resource_ by the setting of _mode_. If _mode_ is _resource_ is no longer observable. *NOTE:* It is not possible for the Unknown Resource, created by -*coap_resource_unknown_init*(3), to be observable as the Uri-Path is not known +*coap_resource_unknown_init2*(3), to be observable as the Uri-Path is not known when libcoap creates a "fake GET/FETCH request". The Unknown Resource PUT handler must create a new resource and mark the resource as "observable" if a specific resource needs to be observable. The application must then -manage the deletion of the resource at the appropriate time. +manage the deletion of the resource at the appropriate time. Similarily, +it is not possible to observe the resource set up by +*coap_resource_proxy_uri_init2*() or *coap_resource_reverse_proxy_init*(). *NOTE:* The type (confirmable or non-confirmable) of the triggered observe GET response is determined not by the initial GET/FETCH request, but diff --git a/src/coap_resource.c b/src/coap_resource.c index d7800202..f3712dc9 100644 --- a/src/coap_resource.c +++ b/src/coap_resource.c @@ -1379,7 +1379,13 @@ coap_resource_release_userdata_handler(coap_context_t *context, void coap_resource_set_get_observable(coap_resource_t *resource, int mode) { - resource->observable = mode ? 1 : 0; + if (resource->is_unknown || resource->is_proxy_uri) { + /* We cannot observe these */ + coap_log_debug("coap_resource_set_get_observable: Not supported for Unknown or Proxy URIs\n"); + resource->observable = 0; + } else { + resource->observable = mode ? 1 : 0; + } } coap_str_const_t *