osd-contiki/apps/time/resource_timezone.c
Ralf Schlatterbeck c6165a3bcf 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.
2016-02-26 17:13:48 +01:00

49 lines
792 B
C

/**
* \file
* Resource for timezone handling
* \author
* Ralf Schlatterbeck <rsc@runtux.com>
*
* \brief get/put timezone string
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "contiki.h"
#include "time.h"
#include "time_resource.h"
#include "jsonparse.h"
#include "er-coap.h"
#include "generic_resource.h"
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, const char *uri, char *buf, size_t bsize)
{
if (get_tz (buf, bsize) == NULL) {
*buf = '\0';
}
return strlen (buf);
}
GENERIC_RESOURCE
( timezone
, TZ
, s
, 1
, timezone_from_string
, timezone_to_string
);
/*
* VI settings, see coding style
* ex:ts=8:et:sw=2
*/