#include <string.h>
#include <sys/mman.h>
+#include <pakfire/base64.h>
#include <pakfire/ctx.h>
#include <pakfire/json.h>
#include <pakfire/logging.h>
return r;
}
+int pakfire_json_add_bytes(struct json_object* json,
+ const char* name, const char* data, size_t length) {
+ char* bytes = NULL;
+ int r;
+
+ // Add null if we don't have any data
+ if (!length)
+ return pakfire_json_add_null(json, name);
+
+ // Encode the buffer as base64
+ r = pakfire_b64encode(&bytes, (const unsigned char*)data, length);
+ if (r < 0)
+ goto ERROR;
+
+ // Add the string
+ r = pakfire_json_add_string(json, name, bytes);
+ if (r < 0)
+ goto ERROR;
+
+ERROR:
+ if (bytes)
+ free(bytes);
+
+ return r;
+}
+
int pakfire_json_add_int64(struct json_object* json, const char* name, int64_t value) {
// Convert integer to JSON object
struct json_object* object = json_object_new_int64(value);
int pakfire_json_add_stringn(struct json_object* json, const char* name, const char* value, size_t length);
int pakfire_json_add_stringf(struct json_object* json, const char* name, const char* format, ...)
__attribute__((format(printf, 3, 4)));
+int pakfire_json_add_bytes(struct json_object* json, const char* name, const char* data, size_t length);
int pakfire_json_add_int64(struct json_object* json, const char* name, int64_t value);
int pakfire_json_add_uint64(struct json_object* json, const char* name, uint64_t value);
int pakfire_json_add_double(struct json_object* json, const char* name, double value);