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 * See the License for the specific language governing permissions 2N/A * and limitations under the License. 2N/A * When distributing Covered Code, include this CDDL HEADER in each 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 * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved. 2N/A * XXX duplicate defines 2N/A * Generate an entry in the property database. 2N/A * Each entry has this format: 2N/A * <name> <prop0>=<val0>,...,<valn>;...;<propn>=<val0>,...,<valn>; 2N/A * Delete line if there are no properties left. 2N/A * Skip properties without values. 2N/A * This function is used to update or create an entry in the persistent db. 2N/A * process_prop_db() will first scan the db for an entry matching the 2N/A * specified name. If a match is found, this function is invoked with the 2N/A * entry's contents (buf) and its linked-list representation (listp). lsp 2N/A * holds the name and values of the property to be added or updated; this 2N/A * information will be merged with listp. Subsequently, an updated entry 2N/A * will be written to buf, which will in turn be written to disk by 2N/A * process_prop_db(). If no entry matches the specified name, listp 2N/A * will be NULL; a new entry will be generated in this case and it will 2N/A * contain only the property information in lsp. 2N/A * Find the prop we want to change. 2N/A * If the prop is not found, append it to the list. 2N/A * nlip will need to be freed later if there is no list to 2N/A * If the prop is found, delete the existing values from it. 2N/A * Fill our prop with the specified values. 2N/A * This function is used for retrieving the values for a specific property. 2N/A * It gets called if an entry matching the specified name exists in the db. 2N/A * The entry is converted into a linked-list listp. This list is then scanned 2N/A * for the specified property name; if a matching property exists, its 2N/A * associated values are copied to the array lsp->ls_propval. 2N/A * Find the prop we want to get. 2N/A * This function is meant to be called at most once for each call 2N/A * to process_prop_db(). For this reason, it's ok to overwrite 2N/A * the caller's valcnt array size with the actual number of values 2N/A * This is used for initializing properties. 2N/A * Unlike the other routines, this gets called for every entry in the 2N/A * database. lsp->ls_name is not user-specified but instead is set to 2N/A * the current name being processed. 2N/A * Construct the propval array and fill it with 2N/A * values from listp. 2N/A * We continue with initializing other properties even 2N/A * after encountering an error. This error will be 2N/A * propagated to the caller via 'statusp'. 2N/A * Move to the next character if there is no match and 2N/A * if we have not reached the last character. 2N/A * Nul-terminate the string pointed to by 'curr'. 2N/A * We get here after we have processed the "<prop>=" 2N/A * pattern. The pattern we are now interested in is 2N/A * "<val0>,<val1>,...,<valn>;". For each value we 2N/A * find, a prop_val_t will be allocated and 2N/A * added to the current 'lip'. 2N/A * lip == NULL indicates that 'curr' must be refering 2N/A * to a property name. We allocate a new prop_db_info_t 2N/A * append it to the list given by the caller. 2N/A * The list must be non-empty and the last character must be ';'. 2N/A * Skip leading spaces, blank lines, and comments. 2N/A * Skip names we're not interested in. 2N/A * Note that strncmp() and isspace() are used here 2N/A * instead of strtok() and strcmp() because we don't 2N/A * want to modify buf in case it does not contain the 2N/A * If a name is not specified, find the name 2N/A * and assign it to lsp->ls_name. 2N/A * Now find the list of properties. 2N/A * Delete corrupted line. 2N/A * This loop processes each line of the configuration file. 2N/A * buf can potentially be modified by process_prop_line(). 2N/A * If this is a write operation and buf is not truncated, buf will 2N/A * be written to disk. process_prop_line() will no longer be 2N/A * called after it returns B_FALSE; at which point the remainder 2N/A * of the file will continue to be read and, if necessary, written 2N/A * If the specified name is not found above, we add the 2N/A * name and its properties to the configuration file.