Exemplo n.º 1
0
/* Pretty print a route table entry to a newly allocated string. If sep is NULL,
 * returns comma+space separated string. */
char *trp_route_to_str(TALLOC_CTX *mem_ctx, TRP_ROUTE *entry, const char *sep)
{
  char *comm=tr_name_strdup(entry->comm);
  char *realm=tr_name_strdup(entry->realm);
  char *peer=tr_name_strdup(entry->peer);
  char *trust_router=tr_name_strdup(entry->trust_router);
  char *next_hop=tr_name_strdup(entry->next_hop);
  char *expiry=timespec_to_str(entry->expiry);
  char *result=NULL;

  if (sep==NULL)
    sep=", ";

  result=talloc_asprintf(mem_ctx,
                         "%s%s%s%s%s%s%u%s%s:%d%s%s:%d%s%u%s%u%s%s%s%u",
                         comm, sep,
                         realm, sep,
                         peer, sep,
                         entry->metric, sep,
                         trust_router, entry->trust_router_port, sep,
                         next_hop, entry->next_hop_port, sep,
                         entry->selected, sep,
                         entry->local, sep,
                         expiry, sep,
                         entry->triggered);
  free(comm);
  free(realm);
  free(peer);
  free(trust_router);
  free(next_hop);
  free(expiry);
  return result;
}
Exemplo n.º 2
0
/* Information records for TRP update msg 
 * requires that jrec already be allocated */
static TRP_RC tr_msg_encode_inforec_route(json_t *jrec, TRP_INFOREC *rec )
{
  json_t *jstr=NULL;
  json_t *jint=NULL;
  char *s=NULL;

  if (rec==NULL)
    return TRP_BADTYPE;

  if ((trp_inforec_get_comm(rec)==NULL)
     || (trp_inforec_get_realm(rec)==NULL)
     || (trp_inforec_get_trust_router(rec)==NULL)) {
    return TRP_ERROR;
  }

  s=tr_name_strdup(trp_inforec_get_comm(rec));
  if (s==NULL)
    return TRP_NOMEM;
  jstr=json_string(s);
  free(s);s=NULL;
  if(jstr==NULL)
    return TRP_ERROR;
  json_object_set_new(jrec, "community", jstr);

  s=tr_name_strdup(trp_inforec_get_realm(rec));
  if (s==NULL)
    return TRP_NOMEM;
  jstr=json_string(s);
  free(s);s=NULL;
  if(jstr==NULL)
    return TRP_ERROR;
  json_object_set_new(jrec, "realm", jstr);

  s=tr_name_strdup(trp_inforec_get_trust_router(rec));
  if (s==NULL)
    return TRP_NOMEM;
  jstr=json_string(s);
  free(s);s=NULL;
  if(jstr==NULL)
    return TRP_ERROR;
  json_object_set_new(jrec, "trust_router", jstr);

  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;
}
Exemplo n.º 3
0
static json_t *tr_msg_encode_trp_req(TRP_REQ *req)
{
  json_t *jbody=NULL;
  json_t *jstr=NULL;
  char *s=NULL;

  if (req==NULL)
    return NULL;

  jbody=json_object();
  if (jbody==NULL)
    return NULL;

  if ((NULL==trp_req_get_comm(req))
     || (NULL==trp_req_get_realm(req))) {
    json_decref(jbody);
    return NULL;
  }

  s=tr_name_strdup(trp_req_get_comm(req)); /* ensures null termination */
  if (s==NULL) {
    json_decref(jbody);
    return NULL;
  }
  jstr=json_string(s);
  free(s); s=NULL;
  if (jstr==NULL) {
    json_decref(jbody);
    return NULL;
  }
  json_object_set_new(jbody, "community", jstr);
    
  s=tr_name_strdup(trp_req_get_realm(req)); /* ensures null termination */
  if (s==NULL) {
    json_decref(jbody);
    return NULL;
  }
  jstr=json_string(s);
  free(s); s=NULL;
  if (jstr==NULL) {
    json_decref(jbody);
    return NULL;
  }
  json_object_set_new(jbody, "realm", jstr);

  return jbody;
}