/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
*/
#ifndef _LIBNETCFG_H
#define _LIBNETCFG_H
#ifdef __cplusplus
extern "C" {
#endif
#include <libnvpair.h>
#include <paths.h>
/* Name of directory containing the door */
/*
* libnetcfg error codes
*/
typedef enum {
/*
* Return the currently active profile.
*/
/*
* netcfg_*_object() functions:
*
* Arguments:
* - nvlist of object identifiers, including a NETCFG_OBJECT_DB_NAME value
* - flags
* - nvlist specifiying object properties (excluded for remove function)
*
* netcfg_read_object: returns the object specified in the idlist in the
* passed-in object list pointer. If idlist only contains a db name,
* returns an nvlist with just one pair, named NETCFG_OBJECT_ID_LIST,
* whose value is an array of nvlists. Each nvlist is the idlist of an
* object in the db.
*
* netcfg_update_object: writes the object identified by idlist and specified
* in objlist to the specified db. Replaces an existing entry, if present.
*
* netcfg_rename_object: in this case, the second nvlist is not an objlist;
* instead, it is the new idlist. Finds the object identified by idlist,
* and rewrites it in the file with its existing object list and the new
* idlist.
*
* netcfg_remove_object: removes the object identified by idlist from the db.
*
* netcvg_get_object_prop: reads the object identified by idlist and fetches
* the value[s] of the property or properties included in the object list,
* updating the object list with the values. If a particular property is
* not present, it is removed from the object list.
*/
nvlist_t **);
nvlist_t **);
nvlist_t **);
/*
* netcfg_*_db() functions:
*
* Common arguments:
* - nvlist containing NETCFG_OBJECT_DB_NAME and, optionally,
* NETCFG_OBJECT_DB_ZONE.
* - flags
*
* netcfg_walk_db: first calls the select callback for each entry in the
* specified db, passing the idlist and objlist for the entry, as well
* as the flags passed to it. Select function returns 0 if the callback
* should be called for this object, non-zero otherwise. Select function
* may also return an object argument which will be passed to the callback;
* if this argument is not specified, the object list will be passed. To
* free the object argument returned by the select function, netcfg_freecb_t
* will be called.
*
* netcfg_walk_db_raw: calls the specified callback for each entry in the
* specified db, passing a string buffer containing the "raw" line from
* the db file.
*
* netcfg_create_db: creates the specified database, and populates it with
* the provided object list. The object list should be an nvlist with one
* pair for each database entry. For each pair, the name is the string
* equivalent of its idlist (produced by calling netcfg_idl2idstr()), and
* the value is the object nvlist. If the specified database already exists,
* it will be overwritten.
*
* netcfg_destroy_db: destroys the specified database, by unlinking the file.
*
*/
typedef int (netcfg_walkcb_t)(void *, void *);
typedef void (netcfg_freecb_t)(void **);
typedef int (netcfg_rawcb_t)(char *, void *);
void *, netcfg_selectcb_t *, netcfg_freecb_t *,
int *);
netcfg_rawcb_t *, void *);
/*
* Functions to manipulate idlists:
*
* netcfg_init_idlist: allocates an nvlist, and adds a NETCFG_OBJECT_DB_NAME
* pair to it with the specified name string.
*
* netcfg_add_idlist: adds the name-value pair specified by the two string
* arguments (name followed by value) to the given idlist.
*
* netcfg_idl2idstr: produces the string representation of the given idlist.
* Memory is allocated for the string; it is the caller's responsibility
* to free that memory.
*
* dbname_from_idlist: returns a pointer to the string value of the
* NETCFG_OBJECT_DB_NAME pair, if present; NULL if not.
*
* zoneid_from_idlist: returns a pointer to the string value of the
* NETCFG_OBJECT_DB_ZONE pair, if present; NULL if not.
*/
const char *);
extern char *dbname_from_idlist(nvlist_t *);
/*
* All properties are stored as arrays, regardless of the number of elements.
* nvpair in cases where there is known to be a single value in the array.
*/
extern int netcfg_nvl_get_one_boolean(nvlist_t *, const char *,
boolean_t *);
extern int netcfg_nvl_get_one_string(nvlist_t *, const char *, char **);
extern int netcfg_nvp_get_one_string(nvpair_t *, char **);
extern int netcfg_nvl_add_one_string(nvlist_t *, const char *, char *);
extern const char *netcfg_strerror(netcfg_error_t);
extern int netcfg_error2errno(netcfg_error_t);
extern char *netcfg_tokenize_by_unescaped_delim(char *, char,
char **);
#ifdef __cplusplus
}
#endif
#endif /* _LIBNETCFG_H */