From: Michael R Sweet Date: Sat, 25 May 2024 19:15:42 +0000 (-0400) Subject: Make cupsJSONAdd public API (needed for making JWK sets) X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c0024f101a41c8383bf9224cdb0f2078924561ee;p=thirdparty%2Fcups.git Make cupsJSONAdd public API (needed for making JWK sets) --- diff --git a/cups/json-private.h b/cups/json-private.h index da78a4c731..3eeaf0507f 100644 --- a/cups/json-private.h +++ b/cups/json-private.h @@ -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; diff --git a/cups/json.c b/cups/json.c index aaa25f33b2..de19e3d58b 100644 --- a/cups/json.c +++ b/cups/json.c @@ -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); diff --git a/cups/json.h b/cups/json.h index 2accb596e1..699500727b 100644 --- a/cups/json.h +++ b/cups/json.h @@ -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; diff --git a/cups/jwt.c b/cups/jwt.c index 70c2c29559..fb706c1f55 100644 --- a/cups/jwt.c +++ b/cups/jwt.c @@ -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); } diff --git a/cups/libcups2.def b/cups/libcups2.def index 9b79927bde..c63c4f1539 100644 --- a/cups/libcups2.def +++ b/cups/libcups2.def @@ -18,7 +18,6 @@ _cupsGetUserDefault _cupsGlobalLock _cupsGlobalUnlock _cupsGlobals -_cupsJSONAdd _cupsJSONDelete _cupsLangPrintError _cupsLangPrintf @@ -303,6 +302,7 @@ cupsGetUserAgent cupsHMACData cupsHashData cupsHashString +cupsJSONAdd cupsJSONDelete cupsJSONExportFile cupsJSONExportString