// Functions...
//
-extern void _cupsJSONAdd(cups_json_t *parent, cups_json_t *after, cups_json_t *node) _CUPS_PRIVATE;
extern void _cupsJSONDelete(cups_json_t *json, const char *key) _CUPS_PRIVATE;
//
-// '_cupsJSONAdd()' - Add a node to a JSON node.
+// 'cupsJSONAdd()' - Add a node to a JSON node.
+//
+// This function adds an existing JSON node as a child of other JSON node.
+// The "parent" argument specifies the node to add to. The "after" argument
+// specifies a child of the parent node or `NULL` to append to the end of the
+// children.
+//
+// Note: The node being added must not already be the child of another parent.
//
void
-_cupsJSONAdd(cups_json_t *parent, // I - Parent JSON node
- cups_json_t *after, // I - Previous sibling node or `NULL` to append to the end
- cups_json_t *node) // I - JSON node to add
+cupsJSONAdd(cups_json_t *parent, // I - Parent JSON node
+ cups_json_t *after, // I - Previous sibling node or `NULL` to append to the end
+ cups_json_t *node) // I - JSON node to add
{
cups_json_t *current; // Current node
+ // Range check input...
+ if (!parent || !node || node->parent)
+ return;
+
+ // Add the node to the parent...
node->parent = parent;
if (after)
node->type = type;
if (parent)
- _cupsJSONAdd(parent, after, node);
+ cupsJSONAdd(parent, after, node);
}
return (node);
// Functions...
//
+extern void cupsJSONAdd(cups_json_t *parent, cups_json_t *after, cups_json_t *node) _CUPS_PUBLIC;
+
extern void cupsJSONDelete(cups_json_t *json) _CUPS_PUBLIC;
extern bool cupsJSONExportFile(cups_json_t *json, const char *filename) _CUPS_PUBLIC;
_cupsJSONDelete(jwt->claims, claim);
// Add claim...
- _cupsJSONAdd(jwt->claims, cupsJSONNewKey(jwt->claims, NULL, claim), value);
+ cupsJSONAdd(jwt->claims, cupsJSONNewKey(jwt->claims, NULL, claim), value);
}
_cupsJSONDelete(jwt->jose, header);
// Add claim...
- _cupsJSONAdd(jwt->jose, cupsJSONNewKey(jwt->jose, NULL, header), value);
+ cupsJSONAdd(jwt->jose, cupsJSONNewKey(jwt->jose, NULL, header), value);
}