libcoap  4.0.3
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator 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 {
45  unsigned int non:1;
46  unsigned int non_cnt:4;
47  unsigned int fail_cnt:2;
49  size_t token_length;
50  unsigned char token[8];
51  /* @todo CON/NON flag, block size */
53 
55 
56 #if 0
57 #include "uthash.h"
58 #include "uri.h"
59 #include "list.h"
60 #include "pdu.h"
61 #include "net.h"
62 
63 #if 0
64 typedef unsigned long coap_key_t;
65 
67 #define COAP_INVALID_HASHKEY ((coap_key_t)-1)
68 
69 typedef struct {
70  coap_uri_t *uri; /* unique identifier; memory is released by coap_delete_resource() */
71  UT_hash_handle hh;
72  str *name; /* display name of the resource */
73  unsigned char mediatype; /* media type for resource representation */
74  unsigned int dirty:1; /* set to 1 if resource has changed */
75  unsigned int writable:1; /* set to 1 if resource can be changed using PUT */
76 
77  /* cache-control */
78  unsigned char etag[4]; /* version identifier for this resource
79  * (zero terminated, first byte is zero if not set). */
80  unsigned int maxage; /* maximum cache time (zero means no Max-age option) */
81 
97  int (*data)(coap_uri_t *uri, unsigned char *mediatype, unsigned int offset, unsigned char *buf, unsigned int *buflen, int *finished);
99 #endif
100 
101 typedef struct {
102  coap_key_t resource; /* hash key for subscribed resource */
103  time_t expires; /* expiry time of subscription */
104 
105  coap_address_t subscriber;
107  str token;
109 
110 #define COAP_RESOURCE(node) ((coap_resource_t *)(node)->data)
111 #define COAP_SUBSCRIPTION(node) ((coap_subscription_t *)(node)->data)
112 
114 void coap_check_resource_list(coap_context_t *context);
115 
117 void coap_check_subscriptions(coap_context_t *context);
118 
119 #if 0
120 
126 
132 #endif
133 
136 coap_subscription_t *coap_new_subscription(coap_context_t *context,
137  const coap_uri_t *resource,
138  const struct sockaddr *subscriber,
139  socklen_t addrlen,
140  time_t expiry);
141 
152 coap_key_t coap_add_subscription(coap_context_t *context,
153  coap_subscription_t *subscription);
154 
166 coap_subscription_t * coap_find_subscription(coap_context_t *context,
167  coap_key_t hashkey,
168  struct sockaddr *subscriber,
169  str *token);
177 int coap_delete_subscription(coap_context_t *context,
178  coap_key_t hashkey,
179  struct sockaddr *subscriber);
180 
182 coap_key_t coap_uri_hash(const coap_uri_t *uri);
183 
184 
186 coap_key_t coap_subscription_hash(coap_subscription_t *subscription);
187 #if 0
188 
190 
192 coap_resource_t *coap_get_resource(coap_context_t *ctx, coap_uri_t *uri);
193 #endif
194 
195 #endif
196 
199 #endif /* _COAP_SUBSCRIBE_H_ */