*
*/
+#include <strings.h>
#include <jansson.h>
#include <talloc.h>
-#include <trust_router/tr_name.h>
+#include <tr_name_internal.h>
#include <trp_internal.h>
#include <tr_comm.h>
#include <tr_apc.h>
struct trp_inforec_type_entry *entry=trp_inforec_type_table;
while ((entry->type != TRP_INFOREC_TYPE_UNKNOWN)
- && (strcmp(s, entry->name)!=0)) {
+ && (strcasecmp(s, entry->name)!=0)) {
entry++;
}
return entry->type;
return tr_dup_name(trp_inforec_get_next_hop(rec));
}
+/**
+ * Set the next hop for the inforec
+ *
+ * Returns TRP_SUCCESS if it set the next hop value for the inforec.
+ * Returns TRP_UNSUPPORTED if the inforec does not have a next hop record but
+ * otherwise nothing went wrong.
+ * Returns TRP_ERROR or another error if there was a failure.
+ *
+ * @param rec
+ * @param next_hop
+ * @return TRP_SUCCESS if the value was set, TRP_UNSUPPORTED if the inforec does not support next hop, or an error code on failure
+ */
TRP_RC trp_inforec_set_next_hop(TRP_INFOREC *rec, TR_NAME *next_hop)
{
+ /* Any inforec types that support next_hop should set it here. */
switch (rec->type) {
case TRP_INFOREC_TYPE_ROUTE:
if (rec->data->route==NULL)
return TRP_ERROR;
rec->data->route->next_hop=next_hop;
break;
- case TRP_INFOREC_TYPE_COMMUNITY:
- /* next hop not used for community records */
- break;
+
default:
- break;
+ /* next hop not used for other records */
+ return TRP_UNSUPPORTED;
}
return TRP_SUCCESS;
}
talloc_steal(upd, rec);
}
+/**
+ * Removes and frees the selected inforec.
+ *
+ * @param upd Update to remove from
+ * @param rec Inforec to remove
+ */
+void trp_upd_remove_inforec(TRP_UPD *upd, TRP_INFOREC *rec)
+{
+ TRP_INFOREC *this=upd->records;
+
+ /* special case for the first element */
+ if (this==rec) {
+ upd->records=upd->records->next;
+ trp_inforec_free(this);
+ return;
+ }
+
+ while (this->next!=NULL) {
+ if (this->next==rec) {
+ this->next=this->next->next; /* this->next is not null */
+ trp_inforec_free(rec);
+ }
+ this=this->next;
+ }
+}
+
+size_t trp_upd_num_inforecs(TRP_UPD *upd)
+{
+ size_t count=0;
+ TRP_INFOREC *this=upd->records;
+
+ while (this != NULL) {
+ count++;
+ this=this->next;
+ }
+ return count;
+}
+
+
TR_NAME *trp_upd_get_realm(TRP_UPD *upd)
{
return upd->realm;
{
TRP_INFOREC *rec=NULL;
TR_NAME *cpy=NULL;
-
+
for (rec=trp_upd_get_inforec(upd); rec!=NULL; rec=trp_inforec_get_next(rec)) {
- if (trp_inforec_set_next_hop(rec, cpy=tr_new_name(hostname)) != TRP_SUCCESS) {
- tr_err("trp_upd_set_next_hop: error setting next hop.");
- tr_free_name(cpy);
+ switch (trp_inforec_set_next_hop(rec, cpy=tr_new_name(hostname))) {
+ case TRP_SUCCESS:
+ /* Success, the TR_NAME in cpy is now stored with the inforec */
+ break;
+
+ case TRP_UNSUPPORTED:
+ /* No error, but the inforec does not accept a next_hop. Free our copy. */
+ tr_free_name(cpy);
+ break;
+
+ default:
+ tr_err("trp_upd_set_next_hop: error setting next hop.");
+ tr_free_name(cpy);
+ break;
}
}
}
static void trp_inforec_route_print(TRP_INFOREC_DATA *data)
{
if (data->route!=NULL) {
- printf(" trust_router=%.*s\n metric=%d\n interval=%d]\n",
+ tr_info(" trust_router=%.*s\n metric=%d\n interval=%d]\n",
data->route->trust_router->len, data->route->trust_router->buf,
data->route->metric, data->route->interval);
}
static void trp_inforec_comm_print(TRP_INFOREC_DATA *data)
{
if (data->comm!=NULL) {
- printf(" type=%s\n role=%s\n owner=%.*s\n contact=%.*s]\n",
+ tr_info(" type=%s\n role=%s\n owner=%.*s\n contact=%.*s]\n",
tr_comm_type_to_str(data->comm->comm_type),
tr_realm_role_to_str(data->comm->role),
data->comm->owner_realm->len, data->comm->owner_realm->buf,