/**
 * A function to free a deltacloud_loadbalancer structure initially allocated
 * by deltacloud_get_loadbalancer_by_id().
 * @param[in] lb The deltacloud_loadbalancer structure representing the
 *               load balancer
 */
void deltacloud_free_loadbalancer(struct deltacloud_loadbalancer *lb)
{
  if (lb == NULL)
    return;

  SAFE_FREE(lb->href);
  SAFE_FREE(lb->id);
  SAFE_FREE(lb->created_at);
  SAFE_FREE(lb->realm_href);
  SAFE_FREE(lb->realm_id);
  free_action_list(&lb->actions);
  free_address_list(&lb->public_addresses);
  free_list(&lb->listeners, struct deltacloud_loadbalancer_listener,
	    free_listener);
  free_list(&lb->instances, struct deltacloud_loadbalancer_instance,
	    free_lb_instance);
}
int parse_addresses_xml(xmlNodePtr root, xmlXPathContextPtr ctxt,
			struct deltacloud_address **addresses)
{
  struct deltacloud_address *thisaddr;
  char *address;
  xmlNodePtr oldnode, cur;
  int ret = -1;

  *addresses = NULL;

  oldnode = ctxt->node;

  ctxt->node = root;
  cur = root->children;
  while (cur != NULL) {
    if (cur->type == XML_ELEMENT_NODE &&
	STREQ((const char *)cur->name, "address")) {

      address = getXPathString("string(./address)", ctxt);
      if (address != NULL) {
	thisaddr = calloc(1, sizeof(struct deltacloud_address));
	if (thisaddr == NULL) {
	  SAFE_FREE(address);
	  oom_error();
	  goto cleanup;
	}

	thisaddr->address = address;

	/* add_to_list can't fail */
	add_to_list(addresses, struct deltacloud_address, thisaddr);
      }
      /* address is allowed to be NULL, so skip it here */
    }
    cur = cur->next;
  }

  ret = 0;

 cleanup:
  ctxt->node = oldnode;
  if (ret < 0)
    free_address_list(addresses);

  return ret;
}
Example #3
0
void
create_address_entry(struct olsrv2 *olsr,
    struct address_list *addr_list, struct tlv_tuple_local *tlv_list,
    struct address_tuple** address_entry)
{
  struct address_tuple *new_tuple = NULL;
  struct tlv_tuple *new_tlv = NULL;
  struct address_list *tmp_addr = addr_list;
  struct tlv_tuple_local *tmp_tlv = NULL;
  int addr_index;


  while (tmp_addr)
    {
      new_tuple = (struct address_tuple*)olsr_malloc(sizeof(struct address_tuple),
                             __FUNCTION__);
      memset(new_tuple, 0, sizeof(struct address_tuple));
      olsr_ip_copy(olsr, &new_tuple->ip_addr, &tmp_addr->ip_addr);
      new_tuple->ip_version = olsr->olsr_cnf->ip_version;
      new_tuple->next = NULL;
      new_tuple->addr_tlv = NULL;

      tmp_tlv = tlv_list;
      addr_index = tmp_addr->index;
      while (tmp_tlv)
    {

      if(addr_index < tmp_tlv->index_start || tmp_tlv->index_stop < addr_index)
        {
          tmp_tlv = tmp_tlv->next;
          continue;
        }

      new_tlv = (struct tlv_tuple *)olsr_malloc(sizeof(struct tlv_tuple),
                            __FUNCTION__);
      memset(new_tlv, 0, sizeof(struct tlv_tuple));
      new_tlv->type = tmp_tlv->type;
      new_tlv->length = tmp_tlv->one_field_size;
      new_tlv->next = NULL;

      // set value(in case multi value bit unset)
      if(tmp_tlv->multi_value_bit == 0)
        {
          // in case ,value is less or equal than 32 bit
          if (tmp_tlv->one_field_size <= sizeof(olsr_u32_t))
        {
          new_tlv->value = tmp_tlv->value;
          new_tlv->extended_value = NULL;
        }
          // in case ,value is larger or than 32 bit
          else
        {
          new_tlv->value = 0;
          new_tlv->extended_value = (olsr_u8_t *)olsr_malloc(tmp_tlv->length,
                                __FUNCTION__);
          memcpy(new_tlv->extended_value, tmp_tlv->extended_value,
             sizeof(tmp_tlv->length));
        }
        }
      // in case, multi value bit set
      else
        {// less equal 32 bit // maybe ,too last speed
          if (tmp_tlv->one_field_size <= sizeof(olsr_u32_t))
        {
          new_tlv->value = tmp_tlv->multi_value[addr_index-tmp_tlv->index_start];
          new_tlv->extended_value = NULL;
        }
          // greater than 32 bit
          else
        {
          new_tlv->value = 0;
          new_tlv->extended_value = (olsr_u8_t *)olsr_malloc(tmp_tlv->length,
                               __FUNCTION__);
          memcpy(new_tlv->extended_value, tmp_tlv->extended_value, tmp_tlv->length);
          if(DEBUG_OLSRV2)
          {
              olsr_printf("Not supported!!\n");
          }
        }
        }

      //QUEUE new_tlv
      if (new_tuple->addr_tlv == NULL)
        new_tuple->addr_tlv = new_tlv;
      else
        {
          new_tlv->next = new_tuple->addr_tlv;
          new_tuple->addr_tlv = new_tlv;
        }

      tmp_tlv = tmp_tlv->next;
    }           //while tmp_tlv

      //QUEUE new_tuple
      if (*address_entry == NULL)
    *address_entry = new_tuple;
      else
    {
      new_tuple->next = *address_entry;
      *address_entry = new_tuple;
    }

      tmp_addr = tmp_addr->next;
    }//while tmp_addr

  free_address_list(addr_list);
  free_address_tlv(tlv_list);

  return;
}