+
+ return jresp;
+}
+
+STATIC json_object* mode (AFB_request *request) { /* AFB_SESSION_CHECK */
+
+ radioCtxHandleT *ctx = (radioCtxHandleT*)request->client->ctx;
+ const char *value = getQueryValue (request, "value");
+ json_object *jresp;
+ char *mode_str;
+
+ /* no "?value=" parameter : return current state */
+ if (!value) {
+ jresp = json_object_new_object();
+ ctx->mode ?
+ json_object_object_add (jresp, "mode", json_object_new_string ("AM"))
+ : json_object_object_add (jresp, "mode", json_object_new_string ("FM"));
+ }
+
+ /* "?value=" parameter is "1" or "on" */
+ else if ( atoi(value) == 1 || !strcasecmp(value, "AM") ) {
+ mode_str = strdup ("mode-AM");
+ ctx->mode = AM;
+ }
+
+ /* "?value=" parameter is "0" or "off" */
+ else if ( atoi(value) == 0 || !strcasecmp(value, "FM") ) {
+ mode_str = strdup ("mode-FM");
+ ctx->mode = FM;
+ }
+
+ else {
+ request->errcode = MHD_HTTP_SERVICE_UNAVAILABLE;
+ return (jsonNewMessage (AFB_FAIL, "Invalid value for mode"));
+ }
+
+ _radio_set_mode (ctx->idx, ctx->mode);
+
+ jresp = json_object_new_object();
+ json_object_object_add (jresp, mode_str, json_object_new_string ("ok"));