/** * @brief Append variable to cvec * * @param vec cvec to append to * @param name name of the variable * @param type type of the variable, supported types are: * - CGV_STRING * - CGV_UINT64 * - CGV_UINT32 * - CGV_INT32 * - CGV_INT64 * - CGV_BOOL * - CGV_REST * @param value value of the variable * @param value_len length of the value * @return int 0 on success, -1 on failure */ intappend_var_to_cvec(cvec* vec, constchar* name, enum cv_type type, void* value, size_t value_len) { cg_var* cv; int ret = -1;
clixon_debug(CLIXON_DBG_DEFAULT, "append_var_to_cvec, name %s, type %d, value %p, value_len %d", name, type, value, value_len);
if ((cv = cv_new(type)) == NULL) { clixon_debug(CLIXON_DBG_DEFAULT, "Failed to create cv"); goto done; }
if (name && cv_name_set(cv, name) == NULL) { clixon_debug(CLIXON_DBG_DEFAULT, "Failed to set name"); cv_free(cv); goto done; }
switch (type) { case CGV_STRING: if (cv_string_set(cv, (char*)value) < 0) { clixon_debug(CLIXON_DBG_DEFAULT, "Failed to set string"); cv_free(cv); goto done; } break; case CGV_UINT64: if (cv_uint64_set(cv, *(uint64_t*)value) < 0) { clixon_debug(CLIXON_DBG_DEFAULT, "Failed to set uint64"); cv_free(cv); goto done; } break; case CGV_UINT32: if (cv_uint32_set(cv, *(uint32_t*)value) < 0) { clixon_debug(CLIXON_DBG_DEFAULT, "Failed to set uint32"); cv_free(cv); goto done; } break; case CGV_INT32: if (cv_int32_set(cv, *(int32_t*)value) < 0) { clixon_debug(CLIXON_DBG_DEFAULT, "Failed to set int32"); cv_free(cv); goto done; } break; case CGV_INT64: if (cv_int64_set(cv, *(int64_t*)value) < 0) { clixon_debug(CLIXON_DBG_DEFAULT, "Failed to set int64"); cv_free(cv); goto done; } break; case CGV_BOOL: if (cv_bool_set(cv, *(char*)value) < 0) { clixon_debug(CLIXON_DBG_DEFAULT, "Failed to set bool"); cv_free(cv); goto done; } break; case CGV_REST: if (cv_string_set(cv, (char*)value) < 0) { clixon_debug(CLIXON_DBG_DEFAULT, "Failed to set rest"); cv_free(cv); goto done; } break; default: cv_free(cv); goto done; }