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