+ jint=json_integer(trp_inforec_get_metric(rec));
+ if(jint==NULL)
+ return TRP_ERROR;
+ json_object_set_new(jrec, "metric", jint);
+
+ jint=json_integer(trp_inforec_get_interval(rec));
+ if(jint==NULL)
+ return TRP_ERROR;
+ json_object_set_new(jrec, "interval", jint);
+
+ return TRP_SUCCESS;
+}
+
+/* returns a json array */
+static json_t *tr_msg_encode_apcs(TR_APC *apcs)
+{
+ TALLOC_CTX *tmp_ctx=talloc_new(NULL);
+ TR_APC_ITER *iter=tr_apc_iter_new(tmp_ctx);
+ TR_APC *apc=NULL;
+ json_t *jarray=NULL;
+ json_t *jid=NULL;
+
+ if (iter==NULL)
+ goto cleanup;
+
+ jarray=json_array();
+ if (jarray==NULL)
+ goto cleanup;
+
+ for (apc=tr_apc_iter_first(iter, apcs); apc!=NULL; apc=tr_apc_iter_next(iter)) {
+ jid=tr_name_to_json_string(tr_apc_get_id(apc));
+ if ((jid==NULL) || (json_array_append_new(jarray, jid)!=0)) {
+ json_decref(jarray);
+ jarray=NULL;
+ goto cleanup;
+ }
+ }
+
+cleanup:
+ talloc_free(tmp_ctx);
+ return jarray;
+}
+
+static TR_APC *tr_msg_decode_apcs(TALLOC_CTX *mem_ctx, json_t *jarray, TRP_RC *rc)
+{
+ TALLOC_CTX *tmp_ctx=talloc_new(NULL);
+ size_t ii=0;
+ TR_APC *apc_list=NULL;
+ TR_APC *new=NULL;
+ json_t *jstr=NULL;
+
+ *rc=TRP_ERROR;
+
+ for (ii=0; ii<json_array_size(jarray); ii++) {
+ jstr=json_array_get(jarray, ii);
+ new=tr_apc_new(tmp_ctx);
+ if ((jstr==NULL) || (new==NULL) || (!json_is_string(jstr))) {
+ apc_list=NULL; /* these are all in tmp_ctx, so they'll still get cleaned up */
+ goto cleanup;
+ }
+
+ tr_apc_set_id(new, tr_new_name(json_string_value(jstr)));
+ if (tr_apc_get_id(new)==NULL) {
+ apc_list=NULL; /* these are all in tmp_ctx, so they'll still get cleaned up */
+ goto cleanup;
+ }
+
+ tr_apc_add(apc_list, new);
+ }
+
+ *rc=TRP_SUCCESS;
+
+ if (apc_list!=NULL)
+ talloc_steal(mem_ctx, apc_list);
+
+cleanup:
+ talloc_free(tmp_ctx);
+ return apc_list;
+}
+
+static TRP_RC tr_msg_encode_inforec_comm(json_t *jrec, TRP_INFOREC *rec)
+{
+ json_t *jstr=NULL;
+ json_t *jint=NULL;
+ json_t *japcs=NULL;
+ const char *sconst=NULL;
+ TR_COMM_TYPE commtype=TR_COMM_UNKNOWN;
+
+ if (rec==NULL)
+ return TRP_BADTYPE;
+
+ commtype=trp_inforec_get_comm_type(rec);
+ if (commtype==TR_COMM_UNKNOWN) {
+ tr_notice("tr_msg_encode_inforec_comm: unknown community type.");
+ return TRP_ERROR;
+ }
+ sconst=tr_comm_type_to_str(commtype);
+ if (sconst==NULL)
+ return TRP_ERROR;
+ jstr=json_string(sconst);