int tid_req_add_path(TID_REQ *req, const char *this_system, unsigned port) { char *path_element = talloc_asprintf(req, "%s:%u", this_system, port); if (!req->path) { req->path = json_array(); if (!req->path) return -1; tid_req_cleanup_json(req, req->path); } return json_array_append( req->path, json_string(path_element)); }
static TID_REQ *tr_msg_decode_tidreq(json_t *jreq) { TID_REQ *treq = NULL; json_t *jrp_realm = NULL; json_t *jrealm = NULL; json_t *jcomm = NULL; json_t *jorig_coi = NULL; json_t *jdh = NULL; json_t *jpath = NULL; json_t *jexpire_interval = NULL; if (!(treq =tid_req_new())) { tr_crit("tr_msg_decode_tidreq(): Error allocating TID_REQ structure."); return NULL; } /* store required fields from request */ if ((NULL == (jrp_realm = json_object_get(jreq, "rp_realm"))) || (NULL == (jrealm = json_object_get(jreq, "target_realm"))) || (NULL == (jcomm = json_object_get(jreq, "community")))) { tr_notice("tr_msg_decode(): Error parsing required fields."); tid_req_free(treq); return NULL; } jpath = json_object_get(jreq, "path"); jexpire_interval = json_object_get(jreq, "expiration_interval"); treq->rp_realm = tr_new_name((char *)json_string_value(jrp_realm)); treq->realm = tr_new_name((char *)json_string_value(jrealm)); treq->comm = tr_new_name((char *)json_string_value(jcomm)); /* Get DH Info from the request */ if (NULL == (jdh = json_object_get(jreq, "dh_info"))) { tr_debug("tr_msg_decode(): Error parsing dh_info."); tid_req_free(treq); return NULL; } treq->tidc_dh = tr_msg_decode_dh(jdh); /* store optional "orig_coi" field */ if (NULL != (jorig_coi = json_object_get(jreq, "orig_coi"))) { treq->orig_coi = tr_new_name((char *)json_string_value(jorig_coi)); } treq->cons = (TR_CONSTRAINT_SET *) json_object_get(jreq, "constraints"); if (treq->cons) { if (!tr_constraint_set_validate(treq->cons)) { tr_debug("Constraint set validation failed"); tid_req_free(treq); return NULL; } json_incref((json_t *) treq->cons); tid_req_cleanup_json(treq, (json_t *) treq->cons); } if (jpath) { json_incref(jpath); treq->path = jpath; tid_req_cleanup_json(treq, jpath); } if (jexpire_interval) treq->expiration_interval = json_integer_value(jexpire_interval); return treq; }