+static json_object * ucs2_validate_command (struct afb_req request,
+ const char* func_name) {
+
+ struct json_object *j_obj = NULL;
+
+ if (!ucsContextS) { /* check UNICENS is initialized */
+ afb_req_fail_f(request, "unicens-init",
+ "Load a configuration before calling %s.",
+ func_name);
+ goto OnErrorExit;
+ }
+
+ j_obj = afb_req_json(request);
+ if (!j_obj) {
+ afb_req_fail_f(request,
+ "query-notjson","query=%s not a valid json entry",
+ afb_req_value(request,""));
+ goto OnErrorExit;
+ }
+
+ AFB_DEBUG("request: %s", json_object_to_json_string(j_obj));
+
+ if (json_object_get_type(j_obj)==json_type_array) {
+ int len = json_object_array_length(j_obj);
+
+ if (len == 1) { /* only support 1 command in array */
+ j_obj = json_object_array_get_idx(j_obj, 0);
+ }
+ else {
+ afb_req_fail_f(request,
+ "query-array",
+ "query of multiple %s commands is not supported",
+ func_name);
+ j_obj = NULL;
+ goto OnErrorExit;
+ }
+ }
+
+ OnErrorExit:
+ return j_obj;
+}
+