1 /* resource.c -- generic resource handling
3 * Copyright (C) 2010--2014 Olaf Bergmann <bergmann@tzi.org>
5 * This file is part of the CoAP library libcoap. Please see
6 * README for terms of use.
9 #include "include/coap/config.h"
10 #include "include/coap/net.h"
11 #include "include/coap/debug.h"
12 #include "include/coap/resource.h"
13 #include "include/coap/subscribe.h"
16 #include "include/coap/utlist.h"
17 /* mem.h is only needed for the string free calls for
18 * COAP_ATTR_FLAGS_RELEASE_NAME / COAP_ATTR_FLAGS_RELEASE_VALUE /
19 * COAP_RESOURCE_FLAGS_RELEASE_URI. not sure what those lines should actually
21 #include "include/coap/mem.h"
23 #include <lwip/memp.h>
25 #define COAP_MALLOC_TYPE(Type) \
26 ((coap_##Type##_t *)memp_malloc(MEMP_COAP_##Type))
27 #define COAP_FREE_TYPE(Type, Object) memp_free(MEMP_COAP_##Type, Object)
30 #if defined(WITH_POSIX) || defined(WITH_ARDUINO) || defined(_WIN32)
31 #include "include/coap/utlist.h"
32 #include "include/coap/mem.h"
34 #define COAP_MALLOC_TYPE(Type) \
35 ((coap_##Type##_t *)coap_malloc(sizeof(coap_##Type##_t)))
36 #define COAP_FREE_TYPE(Type, Object) coap_free(Object)
38 #endif /* WITH_POSIX */
42 MEMB(resource_storage, coap_resource_t, COAP_MAX_RESOURCES);
43 MEMB(attribute_storage, coap_attr_t, COAP_MAX_ATTRIBUTES);
44 MEMB(subscription_storage, coap_subscription_t, COAP_MAX_SUBSCRIBERS);
49 memb_init(&resource_storage);
50 memb_init(&attribute_storage);
51 memb_init(&subscription_storage);
54 static inline coap_subscription_t *
55 coap_malloc_subscription()
57 return memb_alloc(&subscription_storage);
61 coap_free_subscription(coap_subscription_t *subscription)
63 memb_free(&subscription_storage, subscription);
65 #endif /* WITH_CONTIKI */
68 #define min(a,b) ((a) < (b) ? (a) : (b))
71 /* Helper functions for conditional output of character sequences into
72 * a given buffer. The first Offset characters are skipped.
76 * Adds Char to Buf if Offset is zero. Otherwise, Char is not written
77 * and Offset is decremented.
79 #define PRINT_WITH_OFFSET(Buf,Offset,Char) \
80 if ((Offset) == 0) { \
81 (*(Buf)++) = (Char); \
87 * Adds Char to Buf if Offset is zero and Buf is less than Bufend.
89 #define PRINT_COND_WITH_OFFSET(Buf,Bufend,Offset,Char,Result) { \
90 if ((Buf) < (Bufend)) { \
91 PRINT_WITH_OFFSET(Buf,Offset,Char); \
97 * Copies at most Length characters of Str to Buf. The first Offset
98 * characters are skipped. Output may be truncated to Bufend - Buf
101 #define COPY_COND_WITH_OFFSET(Buf,Bufend,Offset,Str,Length,Result) { \
103 for (i = 0; i < (Length); i++) { \
104 PRINT_COND_WITH_OFFSET((Buf), (Bufend), (Offset), (Str)[i], (Result)); \
108 static int match(const str *text, const str *pattern, int match_prefix, int match_substring)
113 if (text->length < pattern->length)
118 unsigned char *next_token = text->s;
119 size_t remaining_length = text->length;
120 while (remaining_length)
123 unsigned char *token = next_token;
124 next_token = (unsigned char *) memchr(token, ' ', remaining_length);
128 token_length = next_token - token;
129 remaining_length -= (token_length + 1);
134 token_length = remaining_length;
135 remaining_length = 0;
138 if ((match_prefix || pattern->length == token_length)
139 && memcmp(token, pattern->s, pattern->length) == 0)
145 return (match_prefix || pattern->length == text->length)
146 && memcmp(text->s, pattern->s, pattern->length) == 0;
150 * Prints the names of all known resources to @p buf. This function
151 * sets @p buflen to the number of bytes actually written and returns
152 * @c 1 on succes. On error, the value in @p buflen is undefined and
153 * the return value will be @c 0.
155 * @param context The context with the resource map.
156 * @param buf The buffer to write the result.
157 * @param buflen Must be initialized to the maximum length of @p buf and will be
158 * set to the length of the well-known response on return.
159 * @param offset The offset in bytes where the output shall start and is
160 * shifted accordingly with the characters that have been
161 * processed. This parameter is used to support the block
163 * @param query_filter A filter query according to <a href="http://tools.ietf.org/html/draft-ietf-core-link-format-11#section-4.1">Link Format</a>
165 * @return COAP_PRINT_STATUS_ERROR on error. Otherwise, the lower 28 bits are
166 * set to the number of bytes that have actually been written to
167 * @p buf. COAP_PRINT_STATUS_TRUNC is set when the output has been
170 #if defined(__GNUC__) && defined(WITHOUT_QUERY_FILTER)
172 print_wellknown(coap_context_t *context, unsigned char *buf, size_t *buflen,
174 coap_opt_t *query_filter __attribute__ ((unused)))
176 #else /* not a GCC */
177 coap_print_status_t print_wellknown(coap_context_t *context, unsigned char *buf, size_t *buflen,
178 size_t offset, coap_opt_t *query_filter)
182 unsigned char *p = buf;
183 const unsigned char *bufend = buf + *buflen;
184 size_t left, written = 0;
185 coap_print_status_t result;
186 const size_t old_offset = offset;
187 int subsequent_resource = 0;
188 #ifndef COAP_RESOURCES_NOHASH
189 coap_resource_t *tmp;
191 #ifndef WITHOUT_QUERY_FILTER
193 { 0, NULL }, query_pattern =
195 int flags = 0; /* MATCH_SUBSTRING, MATCH_PREFIX, MATCH_URI */
196 #define MATCH_URI 0x01
197 #define MATCH_PREFIX 0x02
198 #define MATCH_SUBSTRING 0x04
199 static const str _rt_attributes[] =
201 { 2, (unsigned char *) "rt" },
202 { 2, (unsigned char *) "if" },
203 { 3, (unsigned char *) "rel" },
205 #endif /* WITHOUT_QUERY_FILTER */
209 #endif /* WITH_CONTIKI */
211 #ifndef WITHOUT_QUERY_FILTER
212 /* split query filter, if any */
215 resource_param.s = COAP_OPT_VALUE(query_filter);
216 while (resource_param.length < COAP_OPT_LENGTH(query_filter)
217 && resource_param.s[resource_param.length] != '=')
218 resource_param.length++;
220 if (resource_param.length < COAP_OPT_LENGTH(query_filter))
222 const str *rt_attributes;
223 if (resource_param.length == 4 && memcmp(resource_param.s, "href", 4) == 0)
226 for (rt_attributes = _rt_attributes; rt_attributes->s; rt_attributes++)
228 if (resource_param.length == rt_attributes->length
229 && memcmp(resource_param.s, rt_attributes->s, rt_attributes->length) == 0)
231 flags |= MATCH_SUBSTRING;
236 /* rest is query-pattern */
237 query_pattern.s = COAP_OPT_VALUE(query_filter) + resource_param.length + 1;
239 assert((resource_param.length + 1) <= COAP_OPT_LENGTH(query_filter));
240 query_pattern.length = COAP_OPT_LENGTH(query_filter) - (resource_param.length + 1);
242 if ((query_pattern.s[0] == '/') && ((flags & MATCH_URI) == MATCH_URI))
245 query_pattern.length--;
248 if (query_pattern.length && query_pattern.s[query_pattern.length - 1] == '*')
250 query_pattern.length--;
251 flags |= MATCH_PREFIX;
255 #endif /* WITHOUT_QUERY_FILTER */
259 #ifdef COAP_RESOURCES_NOHASH
260 LL_FOREACH(context->resources, r)
263 HASH_ITER(hh, context->resources, r, tmp)
266 #else /* WITH_CONTIKI */
267 r = (coap_resource_t *)resource_storage.mem;
268 for (i = 0; i < resource_storage.num; ++i, ++r)
270 if (!resource_storage.count[i])
272 #endif /* WITH_CONTIKI */
274 #ifndef WITHOUT_QUERY_FILTER
275 if (resource_param.length)
276 { /* there is a query filter */
278 if (flags & MATCH_URI)
279 { /* match resource URI */
280 if (!match(&r->uri, &query_pattern, (flags & MATCH_PREFIX) != 0,
281 (flags & MATCH_SUBSTRING) != 0))
285 { /* match attribute */
288 attr = coap_find_attr(r, resource_param.s, resource_param.length);
291 if (attr->value.s[0] == '"')
292 { /* if attribute has a quoted value, remove double quotes */
293 unquoted_val.length = attr->value.length - 2;
294 unquoted_val.s = attr->value.s + 1;
298 unquoted_val = attr->value;
300 if (!(match(&unquoted_val, &query_pattern, (flags & MATCH_PREFIX) != 0,
301 (flags & MATCH_SUBSTRING) != 0)))
305 #endif /* WITHOUT_QUERY_FILTER */
307 if (!subsequent_resource)
308 { /* this is the first resource */
309 subsequent_resource = 1;
313 PRINT_COND_WITH_OFFSET(p, bufend, offset, ',', written);
316 left = bufend - p; /* calculate available space */
317 result = coap_print_link(r, p, &left, &offset);
319 if (result & COAP_PRINT_STATUS_ERROR)
324 /* coap_print_link() returns the number of characters that
325 * where actually written to p. Now advance to its end. */
326 p += COAP_PRINT_OUTPUT_LENGTH(result);
332 if (result + old_offset - offset < *buflen)
334 result |= COAP_PRINT_STATUS_TRUNC;
340 coap_resource_init(const unsigned char *uri, size_t len, int flags)
344 #if defined(WITH_POSIX) || defined(WITH_ARDUINO) || defined(_WIN32)
345 r = (coap_resource_t *)coap_malloc(sizeof(coap_resource_t));
348 r = (coap_resource_t *)memp_malloc(MEMP_COAP_RESOURCE);
351 r = (coap_resource_t *)memb_alloc(&resource_storage);
355 memset(r, 0, sizeof(coap_resource_t));
358 LIST_STRUCT_INIT(r, link_attr);
359 #endif /* WITH_CONTIKI */
360 LIST_STRUCT_INIT(r, subscribers);
362 r->uri.s = (unsigned char *) uri;
365 coap_hash_path(r->uri.s, r->uri.length, r->key);
371 debug("coap_resource_init: no memory left\n");
378 coap_add_attr(coap_resource_t *resource, const unsigned char *name, size_t nlen,
379 const unsigned char *val, size_t vlen, int flags)
381 coap_attr_t *attr = NULL;
383 if (!resource || !name)
386 #if defined(WITH_POSIX) || defined(WITH_ARDUINO) || defined(_WIN32)
387 attr = (coap_attr_t *)coap_malloc(sizeof(coap_attr_t));
390 attr = (coap_attr_t *)memp_malloc(MEMP_COAP_RESOURCEATTR);
393 attr = (coap_attr_t *)memb_alloc(&attribute_storage);
398 attr->name.length = nlen;
399 attr->value.length = val ? vlen : 0;
401 attr->name.s = (unsigned char *) name;
402 attr->value.s = (unsigned char *) val;
406 /* add attribute to resource list */
408 LL_PREPEND(resource->link_attr, attr);
409 #else /* WITH_CONTIKI */
410 list_add(resource->link_attr, attr);
411 #endif /* WITH_CONTIKI */
415 debug("coap_add_attr: no memory left\n");
422 coap_find_attr(coap_resource_t *resource, const unsigned char *name, size_t nlen)
426 if (!resource || !name)
430 LL_FOREACH(resource->link_attr, attr)
432 #else /* WITH_CONTIKI */
433 for (attr = list_head(resource->link_attr); attr;
434 attr = list_item_next(attr))
436 #endif /* WITH_CONTIKI */
437 if (attr->name.length == nlen && memcmp(attr->name.s, name, nlen) == 0)
444 void coap_delete_attr(coap_attr_t *attr)
448 if (attr->flags & COAP_ATTR_FLAGS_RELEASE_NAME)
449 coap_free(attr->name.s);
450 if (attr->flags & COAP_ATTR_FLAGS_RELEASE_VALUE)
451 coap_free(attr->value.s);
456 memp_free(MEMP_COAP_RESOURCEATTR, attr);
459 /* FIXME it looks like this was never implemented */
463 void coap_hash_request_uri(const coap_pdu_t *request, coap_key_t key)
465 coap_opt_iterator_t opt_iter;
466 coap_opt_filter_t filter;
469 memset(key, 0, sizeof(coap_key_t));
471 coap_option_filter_clear(filter);
472 coap_option_setb(filter, COAP_OPTION_URI_PATH);
474 coap_option_iterator_init((coap_pdu_t *) request, &opt_iter, filter);
475 while ((option = coap_option_next(&opt_iter)))
476 coap_hash(COAP_OPT_VALUE(option), COAP_OPT_LENGTH(option), key);
479 void coap_add_resource(coap_context_t *context, coap_resource_t *resource)
482 #ifdef COAP_RESOURCES_NOHASH
483 LL_PREPEND(context->resources, resource);
485 HASH_ADD(hh, context->resources, key, sizeof(coap_key_t), resource);
487 #endif /* WITH_CONTIKI */
490 int coap_delete_resource(coap_context_t *context, coap_key_t key)
492 coap_resource_t *resource = NULL;
493 coap_attr_t *attr = NULL, *tmp = NULL;
495 coap_subscription_t *obs;
501 resource = coap_get_resource_from_key(context, key);
506 #if defined(WITH_POSIX) || defined(WITH_LWIP) || defined(WITH_ARDUINO) || defined(_WIN32)
507 #ifdef COAP_RESOURCES_NOHASH
508 LL_DELETE(context->resources, resource);
510 HASH_DELETE(hh, context->resources, resource);
513 /* delete registered attributes */
514 LL_FOREACH_SAFE(resource->link_attr, attr, tmp) coap_delete_attr(attr);
516 if (resource->flags & COAP_RESOURCE_FLAGS_RELEASE_URI)
517 coap_free(resource->uri.s);
519 #if defined(WITH_POSIX) || defined(WITH_ARDUINO) || defined(_WIN32)
523 memp_free(MEMP_COAP_RESOURCE, resource);
525 #else /* not (WITH_POSIX || WITH_LWIP || WITH_ARDUINO) */
526 /* delete registered attributes */
527 while ((attr = list_pop(resource->link_attr)))
528 memb_free(&attribute_storage, attr);
530 /* delete subscribers */
531 while ((obs = list_pop(resource->subscribers)))
533 /* FIXME: notify observer that its subscription has been removed */
534 memb_free(&subscription_storage, obs);
537 memb_free(&resource_storage, resource);
538 #endif /* WITH_CONTIKI */
544 coap_get_resource_from_key(coap_context_t *context, coap_key_t key)
547 coap_resource_t *resource;
548 #ifdef COAP_RESOURCES_NOHASH
550 LL_FOREACH(context->resources, resource)
552 /* if you think you can outspart the compiler and speed things up by (eg by
553 * casting to uint32* and comparing alues), increment this counter: 1 */
554 if (memcmp(key, resource->key, sizeof(coap_key_t)) == 0)
559 HASH_FIND(hh, context->resources, key, sizeof(coap_key_t), resource);
563 #else /* WITH_CONTIKI */
565 coap_resource_t *ptr2;
567 /* the search function is basically taken from memb.c */
568 ptr2 = (coap_resource_t *)resource_storage.mem;
569 for (i = 0; i < resource_storage.num; ++i)
571 if (resource_storage.count[i] &&
572 (memcmp(ptr2->key, key, sizeof(coap_key_t)) == 0))
573 return (coap_resource_t *)ptr2;
578 #endif /* WITH_CONTIKI */
581 coap_print_status_t coap_print_link(const coap_resource_t *resource, unsigned char *buf,
582 size_t *len, size_t *offset)
584 unsigned char *p = buf;
585 const unsigned char *bufend = buf + *len;
587 coap_print_status_t result = 0;
588 const size_t old_offset = *offset;
591 PRINT_COND_WITH_OFFSET(p, bufend, *offset, '<', *len);
592 PRINT_COND_WITH_OFFSET(p, bufend, *offset, '/', *len);
594 COPY_COND_WITH_OFFSET(p, bufend, *offset, resource->uri.s, resource->uri.length, *len);
596 PRINT_COND_WITH_OFFSET(p, bufend, *offset, '>', *len);
599 LL_FOREACH(resource->link_attr, attr)
601 #else /* WITH_CONTIKI */
602 for (attr = list_head(resource->link_attr); attr;
603 attr = list_item_next(attr))
605 #endif /* WITH_CONTIKI */
607 PRINT_COND_WITH_OFFSET(p, bufend, *offset, ';', *len);
609 COPY_COND_WITH_OFFSET(p, bufend, *offset, attr->name.s, attr->name.length, *len);
613 PRINT_COND_WITH_OFFSET(p, bufend, *offset, '=', *len);
615 COPY_COND_WITH_OFFSET(p, bufend, *offset, attr->value.s, attr->value.length, *len);
619 if (resource->observable)
621 COPY_COND_WITH_OFFSET(p, bufend, *offset, ";obs", 4, *len);
625 if (result + old_offset - *offset < *len)
627 result |= COAP_PRINT_STATUS_TRUNC;
633 #ifndef WITHOUT_OBSERVE
634 coap_subscription_t *
635 coap_find_observer(coap_resource_t *resource, const coap_address_t *peer, const str *token)
637 coap_subscription_t *s;
642 for (s = (coap_subscription_t *) list_head(resource->subscribers);
643 s; s = (coap_subscription_t *) list_item_next((void *) s))
645 if (coap_address_equals(&s->subscriber, peer)
647 || (token->length == s->token_length
648 && memcmp(token->s, s->token, token->length) == 0)))
655 coap_subscription_t *
656 coap_add_observer(coap_resource_t *resource, const coap_address_t *observer, const str *token)
658 coap_subscription_t *s;
662 /* Check if there is already a subscription for this peer. */
663 s = coap_find_observer(resource, observer, token);
665 /* We are done if subscription was found. */
669 /* s points to a different subscription, so we have to create
671 s = COAP_MALLOC_TYPE(subscription);
676 coap_subscription_init(s);
677 memcpy(&s->subscriber, observer, sizeof(coap_address_t));
679 if (token && token->length)
681 s->token_length = token->length;
682 memcpy(s->token, token->s, min(s->token_length, 8));
685 /* add subscriber to resource */
686 list_add(resource->subscribers, s);
691 void coap_touch_observer(coap_context_t *context, const coap_address_t *observer, const str *token)
694 coap_subscription_t *s;
697 #ifdef COAP_RESOURCES_NOHASH
698 LL_FOREACH(context->resources, r)
701 coap_resource_t *tmp;
702 HASH_ITER(hh, context->resources, r, tmp)
705 s = coap_find_observer(r, observer, token);
711 #else /* WITH_CONTIKI */
712 r = (coap_resource_t *)resource_storage.mem;
713 for (i = 0; i < resource_storage.num; ++i, ++r)
715 if (resource_storage.count[i])
717 s = coap_find_observer(r, observer, token);
724 #endif /* WITH_CONTIKI */
727 void coap_delete_observer(coap_resource_t *resource, const coap_address_t *observer,
730 coap_subscription_t *s;
732 s = coap_find_observer(resource, observer, token);
736 list_remove(resource->subscribers, s);
738 COAP_FREE_TYPE(subscription, s);
742 static void coap_notify_observers(coap_context_t *context, coap_resource_t *r)
744 coap_method_handler_t h;
745 coap_subscription_t *obs;
747 coap_pdu_t *response;
749 if (r->observable && (r->dirty || r->partiallydirty))
751 r->partiallydirty = 0;
753 /* retrieve GET handler, prepare response */
754 h = r->handler[COAP_REQUEST_GET - 1];
755 assert(h); /* we do not allow subscriptions if no
756 * GET handler is defined */
758 for (obs = (coap_subscription_t *) list_head(r->subscribers);
759 obs; obs = (coap_subscription_t *) list_item_next((void *) obs))
761 if (r->dirty == 0 && obs->dirty == 0)
762 /* running this resource due to partiallydirty,
763 * but this observation's notification was already enqueued */
766 coap_tid_t tid = COAP_INVALID_TID;
768 /* initialize response */
769 response = coap_pdu_init(COAP_MESSAGE_CON, 0, 0, COAP_MAX_PDU_SIZE);
773 r->partiallydirty = 1;
774 debug("coap_check_notify: pdu init failed, resource stays partially dirty\n");
778 if (!coap_add_token(response, obs->token_length, obs->token))
781 r->partiallydirty = 1;
782 debug("coap_check_notify: cannot add token, resource stays partially dirty\n");
783 coap_delete_pdu(response);
787 token.length = obs->token_length;
788 token.s = obs->token;
790 response->transport_hdr->udp.id = coap_new_message_id(context);
791 if (obs->non && obs->non_cnt < COAP_OBS_MAX_NON)
793 response->transport_hdr->udp.type = COAP_MESSAGE_NON;
797 response->transport_hdr->udp.type = COAP_MESSAGE_CON;
799 /* fill with observer-specific data */
800 h(context, r, &obs->subscriber, NULL, &token, response);
802 if (response->transport_hdr->udp.type == COAP_MESSAGE_CON)
804 tid = coap_send_confirmed(context, &obs->subscriber, response);
809 tid = coap_send(context, &obs->subscriber, response);
813 if (COAP_INVALID_TID == tid || response->transport_hdr->udp.type != COAP_MESSAGE_CON)
814 coap_delete_pdu(response);
815 if (COAP_INVALID_TID == tid)
817 debug("coap_check_notify: sending failed, resource stays partially dirty\n");
819 r->partiallydirty = 1;
824 /* Increment value for next Observe use. */
830 void coap_check_notify(coap_context_t *context)
835 #ifdef COAP_RESOURCES_NOHASH
836 LL_FOREACH(context->resources, r)
839 coap_resource_t *tmp;
840 HASH_ITER(hh, context->resources, r, tmp)
843 coap_notify_observers(context, r);
845 #else /* WITH_CONTIKI */
848 r = (coap_resource_t *)resource_storage.mem;
849 for (i = 0; i < resource_storage.num; ++i, ++r)
851 if (resource_storage.count[i])
853 coap_notify_observers(context, r);
856 #endif /* WITH_CONTIKI */
860 * Checks the failure counter for (peer, token) and removes peer from
861 * the list of observers for the given resource when COAP_OBS_MAX_FAIL
864 * @param context The CoAP context to use
865 * @param resource The resource to check for (peer, token)
866 * @param peer The observer's address
867 * @param token The token that has been used for subscription.
869 static void coap_remove_failed_observers(coap_context_t *context, coap_resource_t *resource,
870 const coap_address_t *peer, const str *token)
872 coap_subscription_t *obs;
874 for (obs = (coap_subscription_t *) list_head(resource->subscribers);
875 obs; obs = (coap_subscription_t *) list_item_next((void *) obs))
877 if (coap_address_equals(peer, &obs->subscriber) && token->length == obs->token_length
878 && memcmp(token->s, obs->token, token->length) == 0)
881 /* count failed notifies and remove when
882 * COAP_MAX_FAILED_NOTIFY is reached */
883 if (obs->fail_cnt < COAP_OBS_MAX_FAIL)
887 list_remove(resource->subscribers, obs);
891 if (LOG_DEBUG <= coap_get_log_level())
893 #ifndef INET6_ADDRSTRLEN
894 #define INET6_ADDRSTRLEN 40
896 unsigned char addr[INET6_ADDRSTRLEN + 8];
898 if (coap_print_addr(&obs->subscriber, addr, INET6_ADDRSTRLEN + 8))
899 debug("** removed observer %s\n", addr);
902 coap_cancel_all_messages(context, &obs->subscriber, obs->token, obs->token_length);
904 COAP_FREE_TYPE(subscription, obs);
907 break; /* break loop if observer was found */
911 void coap_handle_failed_notify(coap_context_t *context, const coap_address_t *peer,
918 #ifdef COAP_RESOURCES_NOHASH
919 LL_FOREACH(context->resources, r)
922 coap_resource_t *tmp;
923 HASH_ITER(hh, context->resources, r, tmp)
926 coap_remove_failed_observers(context, r, peer, token);
928 #else /* WITH_CONTIKI */
931 r = (coap_resource_t *)resource_storage.mem;
932 for (i = 0; i < resource_storage.num; ++i, ++r)
934 if (resource_storage.count[i])
936 coap_remove_failed_observers(context, r, peer, token);
939 #endif /* WITH_CONTIKI */
941 #endif /* WITHOUT_NOTIFY */