Refactor tidc/monc to better share code
[trust_router.git] / mon / mon_resp.c
index e1f0761..ee59069 100644 (file)
@@ -65,11 +65,7 @@ static int mon_resp_destructor(void *object)
  * Makes its own copy of the message, so caller can dispose of
  * that after allocating the response.
  *
- * Steals the reference to the payload JSON object. Does not modify the
- * object. Caller should not modify it after allocating the response or
- * undefined behavior will result. If allocation fails, the stolen reference
- * will be released --- if you need to keep a reference, use incref before
- * calling this.
+ * Increments the reference count of the payload if it is not null.
  *
  * @param mem_ctx talloc context for allocation
  * @param req MON_REQ this response corresponds to
@@ -78,18 +74,17 @@ static int mon_resp_destructor(void *object)
  * @param payload JSON object to be send as payload, or null for no payload
  * @return response allocated in the requested talloc context, null on failure
  */
-MON_RESP *mon_resp_new(TALLOC_CTX *mem_ctx,
-                          MON_REQ *req,
-                          MON_RESP_CODE code,
-                          const char *msg,
-                          json_t *payload)
+MON_RESP *mon_resp_new(TALLOC_CTX *mem_ctx, MON_RESP_CODE code, const char *msg, json_t *payload)
 {
   MON_RESP *resp = talloc(mem_ctx, MON_RESP);
   if (resp) {
-    resp->req = req;
     resp->code = code;
     resp->message = tr_new_name(msg);
+
     resp->payload = payload;
+    if (resp->payload)
+      json_incref(resp->payload);
+
     talloc_set_destructor((void *)resp, mon_resp_destructor);
     if (resp->message == NULL) {
       talloc_free(resp); // destructor will be called