]> mj.ucw.cz Git - subauth.git/blobdiff - server/cmd.c
Database of users
[subauth.git] / server / cmd.c
index a53622e8522f498e433f51bf746f6315fb47427e..125422a93614ded3623c43991bb1dbd35f5479f5 100644 (file)
@@ -18,7 +18,7 @@ static void cmd_ok(struct client *c)
   cmd_error(c, "");
 }
 
-static const char *get_string(struct json_node *n, const char *key)
+const char *get_string(struct json_node *n, const char *key)
 {
   struct json_node *s = json_object_get(n, key);
   if (s && s->type == JSON_STRING)
@@ -27,6 +27,40 @@ static const char *get_string(struct json_node *n, const char *key)
     return NULL;
 }
 
+bool get_uint(struct json_node *n, const char *key, uint *dest)
+{
+  struct json_node *s = json_object_get(n, key);
+  if (s && s->type == JSON_NUMBER)
+    {
+      uint u = (uint) s->number;
+      if ((double) u == s->number)
+       {
+         *dest = u;
+         return 1;
+       }
+    }
+  *dest = 0;
+  return 0;
+}
+
+struct json_node **get_array(struct json_node *n, const char *key)
+{
+  struct json_node *s = json_object_get(n, key);
+  if (s && s->type == JSON_ARRAY)
+    return s->elements;
+  else
+    return NULL;
+}
+
+struct json_node *get_object(struct json_node *n, const char *key)
+{
+  struct json_node *s = json_object_get(n, key);
+  if (s && s->type == JSON_OBJECT)
+    return s;
+  else
+    return NULL;
+}
+
 static void cmd_nop(struct client *c)
 {
   cmd_ok(c);