2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License (the "License").
2N/A * You may not use this file except in compliance with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A
2N/A/*
2N/A * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
2N/A */
2N/A
2N/A#include <string.h>
2N/A#include <errno.h>
2N/A#include <sys/nvpair.h>
2N/A#include "libxprop.h"
2N/A
2N/Aint
2N/Axprop_encode(nvlist_t *xprops, const char *name, const char *type,
2N/A boolean_t boolean_default, const char *string_default,
2N/A boolean_t inheritable, const char *values, char *const *values_list,
2N/A uint_t nvalues, const char *colname, boolean_t rightalign,
2N/A boolean_t visible)
2N/A{
2N/A nvlist_t *fields = NULL;
2N/A int err = 0;
2N/A
2N/A if ((err = nvlist_alloc(&fields, NV_UNIQUE_NAME, 0)) != 0)
2N/A goto error;
2N/A
2N/A if ((err = nvlist_add_string(fields, XPROP_TYPE, type)) != 0)
2N/A goto error;
2N/A if (strcmp(type, XPROP_TYPE_BOOLEAN) == 0) {
2N/A if ((err = nvlist_add_boolean_value(fields,
2N/A XPROP_BOOLEAN_DEFAULT, boolean_default)) != 0)
2N/A goto error;
2N/A } else if (string_default != NULL) {
2N/A if ((err = nvlist_add_string(fields,
2N/A XPROP_STRING_DEFAULT, string_default)) != 0)
2N/A goto error;
2N/A }
2N/A if ((err = nvlist_add_boolean_value(fields, XPROP_INHERITABLE,
2N/A inheritable)) != 0)
2N/A goto error;
2N/A if (values != NULL) {
2N/A if ((err = nvlist_add_string(fields, XPROP_VALUES,
2N/A values)) != 0)
2N/A goto error;
2N/A }
2N/A if (values_list != NULL) {
2N/A if ((err = nvlist_add_string_array(fields, XPROP_VALUES_LIST,
2N/A values_list, nvalues)) != 0)
2N/A goto error;
2N/A }
2N/A if (colname != NULL) {
2N/A if ((err = nvlist_add_string(fields, XPROP_COLNAME,
2N/A colname)) != 0)
2N/A goto error;
2N/A }
2N/A if ((err = nvlist_add_boolean_value(fields, XPROP_RIGHTALIGN,
2N/A rightalign)) != 0)
2N/A goto error;
2N/A if ((err = nvlist_add_boolean_value(fields, XPROP_VISIBLE,
2N/A visible)) != 0)
2N/A goto error;
2N/A
2N/A err = nvlist_add_nvlist(xprops, name, fields);
2N/Aerror:
2N/A nvlist_free(fields);
2N/A return (err);
2N/A}
2N/A
2N/Aint
2N/Axprop_encode_string(nvlist_t *props, const char *name,
2N/A const char *string_default, boolean_t inheritable, const char *values,
2N/A char *const *values_list, uint_t nvalues, const char *colname)
2N/A{
2N/A return (xprop_encode(props, name, XPROP_TYPE_STRING, B_FALSE,
2N/A string_default, inheritable, values, values_list, nvalues, colname,
2N/A B_FALSE, B_TRUE));
2N/A}
2N/A
2N/Aint
2N/Axprop_encode_boolean(nvlist_t *props, const char *name,
2N/A boolean_t boolean_default, boolean_t inheritable, const char *colname)
2N/A{
2N/A return (xprop_encode(props, name, XPROP_TYPE_BOOLEAN, boolean_default,
2N/A NULL, inheritable, NULL, NULL, 0, colname, B_TRUE, B_TRUE));
2N/A}