Esempio n. 1
0
void tsi_peer_property_destruct(tsi_peer_property *property) {
  if (property->name != NULL) {
    free(property->name);
  }
  if (property->value.data != NULL) {
    free(property->value.data);
  }
  *property = tsi_init_peer_property(); /* Reset everything to 0. */
}
tsi_result tsi_construct_allocated_string_peer_property(
    const char *name, size_t value_length, tsi_peer_property *property) {
  *property = tsi_init_peer_property();
  if (name != NULL) property->name = gpr_strdup(name);
  if (value_length > 0) {
    property->value.data = gpr_zalloc(value_length);
    property->value.length = value_length;
  }
  return TSI_OK;
}
Esempio n. 3
0
tsi_result tsi_construct_real_peer_property(const char* name, double value,
                                            tsi_peer_property* property) {
  *property = tsi_init_peer_property();
  property->type = TSI_PEER_PROPERTY_TYPE_REAL;
  if (name != NULL) {
    property->name = tsi_strdup(name);
    if (property->name == NULL) return TSI_OUT_OF_RESOURCES;
  }
  property->value.real = value;
  return TSI_OK;
}
Esempio n. 4
0
tsi_result tsi_construct_unsigned_integer_peer_property(
    const char* name, uint64_t value, tsi_peer_property* property) {
  *property = tsi_init_peer_property();
  property->type = TSI_PEER_PROPERTY_TYPE_UNSIGNED_INTEGER;
  if (name != NULL) {
    property->name = tsi_strdup(name);
    if (property->name == NULL) return TSI_OUT_OF_RESOURCES;
  }
  property->value.unsigned_int = value;
  return TSI_OK;
}
Esempio n. 5
0
tsi_result tsi_construct_allocated_string_peer_property(
    const char *name, size_t value_length, tsi_peer_property *property) {
  *property = tsi_init_peer_property();
  if (name != NULL) {
    property->name = tsi_strdup(name);
    if (property->name == NULL) return TSI_OUT_OF_RESOURCES;
  }
  if (value_length > 0) {
    property->value.data = calloc(1, value_length);
    if (property->value.data == NULL) {
      tsi_peer_property_destruct(property);
      return TSI_OUT_OF_RESOURCES;
    }
    property->value.length = value_length;
  }
  return TSI_OK;
}
Esempio n. 6
0
void tsi_peer_property_destruct(tsi_peer_property* property) {
  if (property->name != NULL) {
    free(property->name);
  }
  switch (property->type) {
    case TSI_PEER_PROPERTY_TYPE_STRING:
      if (property->value.string.data != NULL) {
        free(property->value.string.data);
      }
      break;
    case TSI_PEER_PROPERTY_TYPE_LIST:
      tsi_peer_destroy_list_property(property->value.list.children,
                                     property->value.list.child_count);
    default:
      /* Nothing to free. */
      break;
  }
  *property = tsi_init_peer_property(); /* Reset everything to 0. */
}
Esempio n. 7
0
tsi_result tsi_construct_list_peer_property(const char* name,
                                            size_t child_count,
                                            tsi_peer_property* property) {
  *property = tsi_init_peer_property();
  property->type = TSI_PEER_PROPERTY_TYPE_LIST;
  if (name != NULL) {
    property->name = tsi_strdup(name);
    if (property->name == NULL) return TSI_OUT_OF_RESOURCES;
  }
  if (child_count > 0) {
    property->value.list.children =
        calloc(child_count, sizeof(tsi_peer_property));
    if (property->value.list.children == NULL) {
      tsi_peer_property_destruct(property);
      return TSI_OUT_OF_RESOURCES;
    }
    property->value.list.child_count = child_count;
  }
  return TSI_OK;
}