*/
MEM(type_name = json_object_new_string(fr_table_str_by_value(fr_value_box_type_table,
vp->vp_type, "<INVALID>")));
- json_object_object_add(vp_object, "type", type_name);
+ json_object_object_add_ex(vp_object, "type", type_name, JSON_C_OBJECT_KEY_IS_CONSTANT);
/*
* Create a "value" array to hold any attribute values for this attribute...
*/
if (format->value.value_as_array) {
MEM(values = json_object_new_array());
- json_object_object_add(vp_object, "value", values);
+ json_object_object_add_ex(vp_object, "value", values, JSON_C_OBJECT_KEY_IS_CONSTANT);
} else {
/*
* ...unless this is the first time we've seen the attribute and
* value_as_array is false, in which case just add the value directly
* and move on to the next attribute.
*/
- json_object_object_add(vp_object, "value", value);
+ json_object_object_add_ex(vp_object, "value", value, JSON_C_OBJECT_KEY_IS_CONSTANT);
continue;
}
} else {
MEM(values = json_object_new_array());
json_object_array_add(values, json_object_get(convert_value));
json_object_object_del(vp_object, "value");
- json_object_object_add(vp_object, "value", values);
+ json_object_object_add_ex(vp_object, "value", values,
+ JSON_C_OBJECT_KEY_IS_CONSTANT);
}
}
}
*/
MEM(values = json_object_new_array());
json_object_array_add(values, json_object_get(vp_object));
- json_object_object_del(obj, attr_name);
+
+ /*
+ * Existing key will have refcount decremented
+ * and will be freed if thise drops to zero.
+ */
json_object_object_add(obj, attr_name, values);
}
}
* Add the attribute name in the "name" key and the type in the "type" key
*/
MEM(name = json_object_new_string(attr_name));
- json_object_object_add(attrobj, "name", name);
+ json_object_object_add_ex(attrobj, "name", name, JSON_C_OBJECT_KEY_IS_CONSTANT);
MEM(type_name = json_object_new_string(fr_table_str_by_value(fr_value_box_type_table,
vp->vp_type, "<INVALID>")));
- json_object_object_add(attrobj, "type", type_name);
+ json_object_object_add_ex(attrobj, "type", type_name, JSON_C_OBJECT_KEY_IS_CONSTANT);
}
if (format->value.value_as_array) {
/*
* Add "value":[] key to the attribute object
*/
- json_object_object_add(attrobj, "value", values);
+ json_object_object_add_ex(attrobj, "value", values, JSON_C_OBJECT_KEY_IS_CONSTANT);
/*
* Also add to "seen_attributes" to check later
/*
* This is simpler; just add a "value": key to the attribute object.
*/
- json_object_object_add(attrobj, "value", value);
+ json_object_object_add_ex(attrobj, "value", value, JSON_C_OBJECT_KEY_IS_CONSTANT);
}
}
/* create new json object */
cookie->jobj = json_object_new_object();
/* set 'docType' element for new document */
- json_object_object_add(cookie->jobj, "docType", json_object_new_string(inst->doctype));
+ json_object_object_add_ex(cookie->jobj, "docType", json_object_new_string(inst->doctype),
+ JSON_C_OBJECT_KEY_IS_CONSTANT);
/* default startTimestamp and stopTimestamp to null values */
- json_object_object_add(cookie->jobj, "startTimestamp", NULL);
- json_object_object_add(cookie->jobj, "stopTimestamp", NULL);
+ json_object_object_add_ex(cookie->jobj, "startTimestamp", NULL, JSON_C_OBJECT_KEY_IS_CONSTANT);
+ json_object_object_add_ex(cookie->jobj, "stopTimestamp", NULL, JSON_C_OBJECT_KEY_IS_CONSTANT);
}
/* status specific replacements for start/stop time */
/* add start time */
if ((vp = fr_pair_find_by_da(&request->request_pairs, attr_acct_status_type)) != NULL) {
/* add to json object */
- json_object_object_add(cookie->jobj, "startTimestamp",
- mod_value_pair_to_json_object(request, vp));
+ json_object_object_add_ex(cookie->jobj, "startTimestamp",
+ mod_value_pair_to_json_object(request, vp),
+ JSON_C_OBJECT_KEY_IS_CONSTANT);
}
break;
/* add stop time */
if ((vp = fr_pair_find_by_da(&request->request_pairs, attr_event_timestamp)) != NULL) {
/* add to json object */
- json_object_object_add(cookie->jobj, "stopTimestamp",
- mod_value_pair_to_json_object(request, vp));
+ json_object_object_add_ex(cookie->jobj, "stopTimestamp",
+ mod_value_pair_to_json_object(request, vp),
+ JSON_C_OBJECT_KEY_IS_CONSTANT);
}
/* check start timestamp and adjust if needed */
mod_ensure_start_timestamp(cookie->jobj, &request->request_pairs);