Refactor GENERIC_RESOURCE macro

Now callback functions get the URI of the request, this allows to use a
single resource for multiple different URIs.
The is_json flag is now gone for the to-string function, instead the
macro has an is_str flag. If set this automagically produces quotes
around the string for json output.
Now from-string functions can return an error-code, 0 for success, -1
for error.
This commit is contained in:
Ralf Schlatterbeck 2016-02-26 07:54:05 +01:00
parent c7daa7c45d
commit c6165a3bcf
9 changed files with 106 additions and 68 deletions

View file

@ -17,13 +17,14 @@
#include "er-coap.h"
#include "generic_resource.h"
void timezone_from_string (const char *name, const char *s)
int timezone_from_string (const char *name, const char *uri, const char *s)
{
set_tz (s);
return 0;
}
size_t
timezone_to_string (const char *name, uint8_t is_json, char *buf, size_t bsize)
timezone_to_string (const char *name, const char *uri, char *buf, size_t bsize)
{
if (get_tz (buf, bsize) == NULL) {
*buf = '\0';
@ -35,6 +36,7 @@ GENERIC_RESOURCE
( timezone
, TZ
, s
, 1
, timezone_from_string
, timezone_to_string
);