1eb686149SLandon J. Fuller /*- 2eb686149SLandon J. Fuller * Copyright (c) 2015-2016 Landon Fuller <landon@landonf.org> 3eb686149SLandon J. Fuller * All rights reserved. 4eb686149SLandon J. Fuller * 5eb686149SLandon J. Fuller * Redistribution and use in source and binary forms, with or without 6eb686149SLandon J. Fuller * modification, are permitted provided that the following conditions 7eb686149SLandon J. Fuller * are met: 8eb686149SLandon J. Fuller * 1. Redistributions of source code must retain the above copyright 9eb686149SLandon J. Fuller * notice, this list of conditions and the following disclaimer, 10eb686149SLandon J. Fuller * without modification. 11eb686149SLandon J. Fuller * 2. Redistributions in binary form must reproduce at minimum a disclaimer 12eb686149SLandon J. Fuller * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any 13eb686149SLandon J. Fuller * redistribution must be conditioned upon including a substantially 14eb686149SLandon J. Fuller * similar Disclaimer requirement for further binary redistribution. 15eb686149SLandon J. Fuller * 16eb686149SLandon J. Fuller * NO WARRANTY 17eb686149SLandon J. Fuller * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18eb686149SLandon J. Fuller * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19eb686149SLandon J. Fuller * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY 20eb686149SLandon J. Fuller * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21eb686149SLandon J. Fuller * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, 22eb686149SLandon J. Fuller * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23eb686149SLandon J. Fuller * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24eb686149SLandon J. Fuller * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 25eb686149SLandon J. Fuller * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26eb686149SLandon J. Fuller * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 27eb686149SLandon J. Fuller * THE POSSIBILITY OF SUCH DAMAGES. 28eb686149SLandon J. Fuller * 29eb686149SLandon J. Fuller */ 30eb686149SLandon J. Fuller 31eb686149SLandon J. Fuller #ifndef _BHND_NVRAM_BHND_NVRAM_PLIST_H_ 32eb686149SLandon J. Fuller #define _BHND_NVRAM_BHND_NVRAM_PLIST_H_ 33eb686149SLandon J. Fuller 34eb686149SLandon J. Fuller #ifdef _KERNEL 35eb686149SLandon J. Fuller #include <sys/types.h> 36eb686149SLandon J. Fuller #else /* !_KERNEL */ 37eb686149SLandon J. Fuller #include <stdbool.h> 38eb686149SLandon J. Fuller #include <stdint.h> 39eb686149SLandon J. Fuller #endif /* _KERNEL */ 40eb686149SLandon J. Fuller 41eb686149SLandon J. Fuller #include "bhnd_nvram.h" 42eb686149SLandon J. Fuller #include "bhnd_nvram_value.h" 43eb686149SLandon J. Fuller 44eb686149SLandon J. Fuller typedef struct bhnd_nvram_prop bhnd_nvram_prop; 45eb686149SLandon J. Fuller typedef struct bhnd_nvram_plist bhnd_nvram_plist; 46eb686149SLandon J. Fuller 47eb686149SLandon J. Fuller bhnd_nvram_plist *bhnd_nvram_plist_new(void); 48eb686149SLandon J. Fuller bhnd_nvram_plist *bhnd_nvram_plist_retain(bhnd_nvram_plist *plist); 49eb686149SLandon J. Fuller void bhnd_nvram_plist_release(bhnd_nvram_plist *plist); 50eb686149SLandon J. Fuller 51eb686149SLandon J. Fuller bhnd_nvram_plist *bhnd_nvram_plist_copy(bhnd_nvram_plist *plist); 52eb686149SLandon J. Fuller 53eb686149SLandon J. Fuller size_t bhnd_nvram_plist_count(bhnd_nvram_plist *plist); 54eb686149SLandon J. Fuller 55eb686149SLandon J. Fuller int bhnd_nvram_plist_append_list(bhnd_nvram_plist *plist, 56eb686149SLandon J. Fuller bhnd_nvram_plist *tail); 57eb686149SLandon J. Fuller 58eb686149SLandon J. Fuller int bhnd_nvram_plist_append(bhnd_nvram_plist *plist, 59eb686149SLandon J. Fuller bhnd_nvram_prop *prop); 60eb686149SLandon J. Fuller int bhnd_nvram_plist_append_val(bhnd_nvram_plist *plist, 61eb686149SLandon J. Fuller const char *name, bhnd_nvram_val *val); 62eb686149SLandon J. Fuller int bhnd_nvram_plist_append_bytes(bhnd_nvram_plist *plist, 63eb686149SLandon J. Fuller const char *name, const void *inp, size_t ilen, 64eb686149SLandon J. Fuller bhnd_nvram_type itype); 65eb686149SLandon J. Fuller int bhnd_nvram_plist_append_string(bhnd_nvram_plist *plist, 66eb686149SLandon J. Fuller const char *name, const char *val); 67eb686149SLandon J. Fuller 68eb686149SLandon J. Fuller int bhnd_nvram_plist_replace(bhnd_nvram_plist *plist, 69eb686149SLandon J. Fuller bhnd_nvram_prop *prop); 70eb686149SLandon J. Fuller int bhnd_nvram_plist_replace_val(bhnd_nvram_plist *plist, 71eb686149SLandon J. Fuller const char *name, bhnd_nvram_val *val); 72eb686149SLandon J. Fuller int bhnd_nvram_plist_replace_bytes(bhnd_nvram_plist *plist, 73eb686149SLandon J. Fuller const char *name, const void *inp, size_t ilen, 74eb686149SLandon J. Fuller bhnd_nvram_type itype); 75eb686149SLandon J. Fuller int bhnd_nvram_plist_replace_string(bhnd_nvram_plist *plist, 76eb686149SLandon J. Fuller const char *name, const char *val); 77eb686149SLandon J. Fuller 78eb686149SLandon J. Fuller void bhnd_nvram_plist_remove(bhnd_nvram_plist *plist, 79eb686149SLandon J. Fuller const char *name); 80eb686149SLandon J. Fuller 81eb686149SLandon J. Fuller bool bhnd_nvram_plist_contains(bhnd_nvram_plist *plist, 82eb686149SLandon J. Fuller const char *name); 83eb686149SLandon J. Fuller bhnd_nvram_prop *bhnd_nvram_plist_next(bhnd_nvram_plist *plist, 84eb686149SLandon J. Fuller bhnd_nvram_prop *prop); 85eb686149SLandon J. Fuller 86eb686149SLandon J. Fuller bhnd_nvram_prop *bhnd_nvram_plist_get_prop(bhnd_nvram_plist *plist, 87eb686149SLandon J. Fuller const char *name); 88eb686149SLandon J. Fuller bhnd_nvram_val *bhnd_nvram_plist_get_val(bhnd_nvram_plist *plist, 89eb686149SLandon J. Fuller const char *name); 90eb686149SLandon J. Fuller int bhnd_nvram_plist_get_encoded(bhnd_nvram_plist *plist, 91eb686149SLandon J. Fuller const char *name, void *outp, size_t olen, 92eb686149SLandon J. Fuller bhnd_nvram_type otype); 93eb686149SLandon J. Fuller 94eb686149SLandon J. Fuller int bhnd_nvram_plist_get_char(bhnd_nvram_plist *plist, 95eb686149SLandon J. Fuller const char *name, u_char *val); 96eb686149SLandon J. Fuller int bhnd_nvram_plist_get_uint8(bhnd_nvram_plist *plist, 97eb686149SLandon J. Fuller const char *name, uint8_t *val); 98eb686149SLandon J. Fuller int bhnd_nvram_plist_get_uint16(bhnd_nvram_plist *plist, 99eb686149SLandon J. Fuller const char *name, uint16_t *val); 100eb686149SLandon J. Fuller int bhnd_nvram_plist_get_uint32(bhnd_nvram_plist *plist, 101eb686149SLandon J. Fuller const char *name, uint32_t *val); 102eb686149SLandon J. Fuller int bhnd_nvram_plist_get_uint64(bhnd_nvram_plist *plist, 103eb686149SLandon J. Fuller const char *name, uint64_t *val); 104eb686149SLandon J. Fuller int bhnd_nvram_plist_get_string(bhnd_nvram_plist *plist, 105eb686149SLandon J. Fuller const char *name, const char **val); 106*6cffadf0SLandon J. Fuller int bhnd_nvram_plist_get_bool(bhnd_nvram_plist *plist, 107*6cffadf0SLandon J. Fuller const char *name, bool *val); 108eb686149SLandon J. Fuller 109eb686149SLandon J. Fuller bhnd_nvram_prop *bhnd_nvram_prop_new(const char *name, 110eb686149SLandon J. Fuller bhnd_nvram_val *val); 111eb686149SLandon J. Fuller bhnd_nvram_prop *bhnd_nvram_prop_bytes_new(const char *name, 112eb686149SLandon J. Fuller const void *inp, size_t ilen, 113eb686149SLandon J. Fuller bhnd_nvram_type itype); 114eb686149SLandon J. Fuller 115eb686149SLandon J. Fuller bhnd_nvram_prop *bhnd_nvram_prop_retain(bhnd_nvram_prop *prop); 116eb686149SLandon J. Fuller void bhnd_nvram_prop_release(bhnd_nvram_prop *prop); 117eb686149SLandon J. Fuller 118eb686149SLandon J. Fuller const char *bhnd_nvram_prop_name(bhnd_nvram_prop *prop); 119eb686149SLandon J. Fuller bhnd_nvram_val *bhnd_nvram_prop_val(bhnd_nvram_prop *prop); 120eb686149SLandon J. Fuller bhnd_nvram_type bhnd_nvram_prop_type(bhnd_nvram_prop *prop); 121eb686149SLandon J. Fuller 122*6cffadf0SLandon J. Fuller bool bhnd_nvram_prop_is_null(bhnd_nvram_prop *prop); 123*6cffadf0SLandon J. Fuller 124eb686149SLandon J. Fuller const void *bhnd_nvram_prop_bytes(bhnd_nvram_prop *prop, 125eb686149SLandon J. Fuller size_t *olen, bhnd_nvram_type *otype); 126eb686149SLandon J. Fuller int bhnd_nvram_prop_encode(bhnd_nvram_prop *prop, 127eb686149SLandon J. Fuller void *outp, size_t *olen, bhnd_nvram_type otype); 128eb686149SLandon J. Fuller 129eb686149SLandon J. Fuller #endif /* _BHND_NVRAM_BHND_NVRAM_PLIST_H_ */ 130