libcoap  4.1.1
 All Data Structures Files Functions Variables Typedefs Macros Groups Pages
subscribe.h
Go to the documentation of this file.
1 /* subscribe.h -- subscription handling for CoAP
2  * see draft-hartke-coap-observe-03
3  *
4  * Copyright (C) 2010--2012 Olaf Bergmann <bergmann@tzi.org>
5  *
6  * This file is part of the CoAP library libcoap. Please see
7  * README for terms of use.
8  */
9 
10 
11 #ifndef _COAP_SUBSCRIBE_H_
12 #define _COAP_SUBSCRIBE_H_
13 
14 #include "config.h"
15 #include "address.h"
16 
22 #ifndef COAP_OBS_MAX_NON
23 
28 #define COAP_OBS_MAX_NON 5
29 #endif /* COAP_OBS_MAX_NON */
30 
31 #ifndef COAP_OBS_MAX_FAIL
32 
37 #define COAP_OBS_MAX_FAIL 3
38 #endif /* COAP_OBS_MAX_FAIL */
39 
41 typedef struct coap_subscription_t {
43  coap_address_t subscriber;
45  unsigned int non:1;
46  unsigned int non_cnt:4;
47  unsigned int fail_cnt:2;
48  unsigned int dirty:1;
50  size_t token_length;
51  unsigned char token[8];
52  /* @todo CON/NON flag, block size */
54 
56 
57 #if 0
58 #include "uthash.h"
59 #include "uri.h"
60 #include "list.h"
61 #include "pdu.h"
62 #include "net.h"
63 
64 #if 0
65 typedef unsigned long coap_key_t;
66 
68 #define COAP_INVALID_HASHKEY ((coap_key_t)-1)
69 
70 typedef struct {
71  coap_uri_t *uri; /* unique identifier; memory is released by coap_delete_resource() */
72  UT_hash_handle hh;
73  str *name; /* display name of the resource */
74  unsigned char mediatype; /* media type for resource representation */
75  unsigned int dirty:1; /* set to 1 if resource has changed */
76  unsigned int writable:1; /* set to 1 if resource can be changed using PUT */
77 
78  /* cache-control */
79  unsigned char etag[4]; /* version identifier for this resource
80  * (zero terminated, first byte is zero if not set). */
81  unsigned int maxage; /* maximum cache time (zero means no Max-age option) */
82 
98  int (*data)(coap_uri_t *uri, unsigned char *mediatype, unsigned int offset, unsigned char *buf, unsigned int *buflen, int *finished);
100 #endif
101 
102 typedef struct {
103  coap_key_t resource; /* hash key for subscribed resource */
104  time_t expires; /* expiry time of subscription */
105 
106  coap_address_t subscriber;
108  str token;
110 
111 #define COAP_RESOURCE(node) ((coap_resource_t *)(node)->data)
112 #define COAP_SUBSCRIPTION(node) ((coap_subscription_t *)(node)->data)
113 
115 void coap_check_resource_list(coap_context_t *context);
116 
118 void coap_check_subscriptions(coap_context_t *context);
119 
120 #if 0
121 
127 
133 #endif
134 
137 coap_subscription_t *coap_new_subscription(coap_context_t *context,
138  const coap_uri_t *resource,
139  const struct sockaddr *subscriber,
140  socklen_t addrlen,
141  time_t expiry);
142 
153 coap_key_t coap_add_subscription(coap_context_t *context,
154  coap_subscription_t *subscription);
155 
167 coap_subscription_t * coap_find_subscription(coap_context_t *context,
168  coap_key_t hashkey,
169  struct sockaddr *subscriber,
170  str *token);
178 int coap_delete_subscription(coap_context_t *context,
179  coap_key_t hashkey,
180  struct sockaddr *subscriber);
181 
183 coap_key_t coap_uri_hash(const coap_uri_t *uri);
184 
185 
187 coap_key_t coap_subscription_hash(coap_subscription_t *subscription);
188 #if 0
189 
191 
193 coap_resource_t *coap_get_resource(coap_context_t *ctx, coap_uri_t *uri);
194 #endif
195 
196 #endif
197 
200 #endif /* _COAP_SUBSCRIBE_H_ */
Representation of parsed URI.
Definition: uri.h:18
unsigned char coap_key_t[4]
Definition: hashkey.h:19
int coap_delete_resource(coap_context_t *context, coap_key_t key)
Deletes a resource identified by key.
Definition: resource.c:451
static coap_uri_t uri
Definition: client.c:36
struct coap_subscription_t * next
next element in linked list
Definition: subscribe.h:42
size_t token_length
actual length of token
Definition: subscribe.h:50
struct coap_subscription_t coap_subscription_t
Subscriber information.
representation of network addresses
void coap_add_resource(coap_context_t *context, coap_resource_t *resource)
Registers the given resource for context.
Definition: resource.c:440
unsigned int non_cnt
up to 15 non-confirmable notifies allowed
Definition: subscribe.h:46
struct coap_resource_t coap_resource_t
Subscriber information.
Definition: subscribe.h:41
unsigned int dirty
set if the notification temporarily could not be sent (in that case, the resource's partiallydirty fl...
Definition: subscribe.h:48
Definition: str.h:14
unsigned int fail_cnt
up to 3 confirmable notifies can fail
Definition: subscribe.h:47
unsigned char token[8]
token used for subscription
Definition: subscribe.h:51
void coap_subscription_init(coap_subscription_t *)
Definition: subscribe.c:30
unsigned int non
send non-confirmable notifies if 1
Definition: subscribe.h:45
coap_address_t subscriber
address and port of subscriber
Definition: subscribe.h:43
The CoAP stack's global state is stored in a coap_context_t object.
Definition: net.h:97
coap_resource_t * coap_get_resource_from_key(coap_context_t *context, coap_key_t key)
Returns the resource identified by the unique string key.
Definition: resource.c:503