]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Make cupsJSONAdd public API (needed for making JWK sets)
authorMichael R Sweet <msweet@msweet.org>
Sat, 25 May 2024 19:15:42 +0000 (15:15 -0400)
committerMichael R Sweet <msweet@msweet.org>
Sat, 25 May 2024 19:15:42 +0000 (15:15 -0400)
cups/json-private.h
cups/json.c
cups/json.h
cups/jwt.c
cups/libcups2.def

index da78a4c7311905c2ada6bb56a1dab1c3f983bd22..3eeaf0507f76f97a3faac641f34465bb80f8bc0e 100644 (file)
@@ -19,7 +19,6 @@ extern "C" {
 // 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;
 
 
index aaa25f33b248ad286ca0217767a0515a57eafec8..de19e3d58b2670ab1ad9c42a255bf9697237e9b8 100644 (file)
@@ -40,17 +40,29 @@ static void free_json(cups_json_t *json);
 
 
 //
-// '_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)
@@ -1350,7 +1362,7 @@ cupsJSONNew(cups_json_t  *parent, // I - Parent JSON node or `NULL` for a root n
     node->type = type;
 
     if (parent)
-      _cupsJSONAdd(parent, after, node);
+      cupsJSONAdd(parent, after, node);
   }
 
   return (node);
index 2accb596e1b49eafb9cd7c66efc1cda9ff494a31..699500727bc0b8a531a4bb616ebad1da30a1ec28 100644 (file)
@@ -38,6 +38,8 @@ typedef struct _cups_json_s cups_json_t;// JSON node @since CUPS 2.5@
 // 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;
index 70c2c295592ba309599444ec11e4819f13c61443..fb706c1f55d39cba0abf974d8938819d7a0aeb94 100644 (file)
@@ -1091,7 +1091,7 @@ cupsJWTSetClaimValue(
   _cupsJSONDelete(jwt->claims, claim);
 
   // Add claim...
-  _cupsJSONAdd(jwt->claims, cupsJSONNewKey(jwt->claims, NULL, claim), value);
+  cupsJSONAdd(jwt->claims, cupsJSONNewKey(jwt->claims, NULL, claim), value);
 }
 
 
@@ -1175,7 +1175,7 @@ cupsJWTSetHeaderValue(
   _cupsJSONDelete(jwt->jose, header);
 
   // Add claim...
-  _cupsJSONAdd(jwt->jose, cupsJSONNewKey(jwt->jose, NULL, header), value);
+  cupsJSONAdd(jwt->jose, cupsJSONNewKey(jwt->jose, NULL, header), value);
 }
 
 
index 9b79927bdee4dc5606cc2d75ad532a7e80b13e4d..c63c4f1539ced880380b350ff826a270a5025290 100644 (file)
@@ -18,7 +18,6 @@ _cupsGetUserDefault
 _cupsGlobalLock
 _cupsGlobalUnlock
 _cupsGlobals
-_cupsJSONAdd
 _cupsJSONDelete
 _cupsLangPrintError
 _cupsLangPrintf
@@ -303,6 +302,7 @@ cupsGetUserAgent
 cupsHMACData
 cupsHashData
 cupsHashString
+cupsJSONAdd
 cupsJSONDelete
 cupsJSONExportFile
 cupsJSONExportString