Lines Matching defs:nvl
119 #define NVLIST_MAGIC 0x6e766c /* "nvl" */
129 #define NVLIST_ASSERT(nvl) do { \
130 PJDLOG_ASSERT((nvl) != NULL); \
131 PJDLOG_ASSERT((nvl)->nvl_magic == NVLIST_MAGIC); \
153 nvlist_t *nvl;
157 nvl = nv_malloc(sizeof(*nvl));
158 if (nvl == NULL)
160 nvl->nvl_error = 0;
161 nvl->nvl_flags = flags;
162 nvl->nvl_parent = NULL;
163 nvl->nvl_array_next = NULL;
164 TAILQ_INIT(&nvl->nvl_head);
165 nvl->nvl_magic = NVLIST_MAGIC;
167 return (nvl);
171 nvlist_destroy(nvlist_t *nvl)
175 if (nvl == NULL)
180 NVLIST_ASSERT(nvl);
182 while ((nvp = nvlist_first_nvpair(nvl)) != NULL) {
183 nvlist_remove_nvpair(nvl, nvp);
186 if (nvl->nvl_array_next != NULL)
187 nvpair_free_structure(nvl->nvl_array_next);
188 nvl->nvl_array_next = NULL;
189 nvl->nvl_parent = NULL;
190 nvl->nvl_magic = 0;
191 nv_free(nvl);
197 nvlist_set_error(nvlist_t *nvl, int error)
206 if (nvl != NULL && error != 0 && nvl->nvl_error == 0)
207 nvl->nvl_error = error;
211 nvlist_error(const nvlist_t *nvl)
214 if (nvl == NULL)
217 NVLIST_ASSERT(nvl);
219 return (nvl->nvl_error);
223 nvlist_get_nvpair_parent(const nvlist_t *nvl)
226 NVLIST_ASSERT(nvl);
228 return (nvl->nvl_parent);
232 nvlist_get_parent(const nvlist_t *nvl, void **cookiep)
236 NVLIST_ASSERT(nvl);
238 nvp = nvl->nvl_parent;
248 nvlist_set_parent(nvlist_t *nvl, nvpair_t *parent)
251 NVLIST_ASSERT(nvl);
253 nvl->nvl_parent = parent;
257 nvlist_set_array_next(nvlist_t *nvl, nvpair_t *ele)
260 NVLIST_ASSERT(nvl);
263 nvl->nvl_flags |= NV_FLAG_IN_ARRAY;
265 nvl->nvl_flags &= ~NV_FLAG_IN_ARRAY;
266 nv_free(nvl->nvl_array_next);
269 nvl->nvl_array_next = ele;
273 nvlist_get_array_next_nvpair(nvlist_t *nvl)
276 NVLIST_ASSERT(nvl);
278 return (nvl->nvl_array_next);
282 nvlist_in_array(const nvlist_t *nvl)
285 NVLIST_ASSERT(nvl);
287 return ((nvl->nvl_flags & NV_FLAG_IN_ARRAY) != 0);
291 nvlist_get_array_next(const nvlist_t *nvl)
295 NVLIST_ASSERT(nvl);
297 nvp = nvl->nvl_array_next;
305 nvlist_get_pararr(const nvlist_t *nvl, void **cookiep)
309 ret = nvlist_get_array_next(nvl);
316 return (nvlist_get_parent(nvl, cookiep));
320 nvlist_empty(const nvlist_t *nvl)
323 NVLIST_ASSERT(nvl);
324 PJDLOG_ASSERT(nvl->nvl_error == 0);
326 return (nvlist_first_nvpair(nvl) == NULL);
330 nvlist_flags(const nvlist_t *nvl)
333 NVLIST_ASSERT(nvl);
334 PJDLOG_ASSERT(nvl->nvl_error == 0);
336 return (nvl->nvl_flags & NV_FLAG_PUBLIC_MASK);
340 nvlist_set_flags(nvlist_t *nvl, int flags)
343 NVLIST_ASSERT(nvl);
344 PJDLOG_ASSERT(nvl->nvl_error == 0);
346 nvl->nvl_flags = flags;
358 nvlist_find(const nvlist_t *nvl, int type, const char *name)
362 NVLIST_ASSERT(nvl);
363 PJDLOG_ASSERT(nvl->nvl_error == 0);
367 for (nvp = nvlist_first_nvpair(nvl); nvp != NULL;
368 nvp = nvlist_next_nvpair(nvl, nvp)) {
371 if ((nvl->nvl_flags & NV_FLAG_IGNORE_CASE) != 0) {
388 nvlist_exists_type(const nvlist_t *nvl, const char *name, int type)
391 NVLIST_ASSERT(nvl);
392 PJDLOG_ASSERT(nvl->nvl_error == 0);
396 return (nvlist_find(nvl, type, name) != NULL);
400 nvlist_free_type(nvlist_t *nvl, const char *name, int type)
404 NVLIST_ASSERT(nvl);
405 PJDLOG_ASSERT(nvl->nvl_error == 0);
409 nvp = nvlist_find(nvl, type, name);
411 nvlist_free_nvpair(nvl, nvp);
417 nvlist_clone(const nvlist_t *nvl)
422 NVLIST_ASSERT(nvl);
424 if (nvl->nvl_error != 0) {
425 ERRNO_SET(nvl->nvl_error);
429 newnvl = nvlist_create(nvl->nvl_flags & NV_FLAG_PUBLIC_MASK);
430 for (nvp = nvlist_first_nvpair(nvl); nvp != NULL;
431 nvp = nvlist_next_nvpair(nvl, nvp)) {
446 nvlist_dump_error_check(const nvlist_t *nvl, int fd, int level)
449 if (nvlist_error(nvl) != 0) {
451 nvlist_error(nvl));
462 nvlist_dump(const nvlist_t *nvl, int fd)
470 if (nvlist_dump_error_check(nvl, fd, level))
473 nvp = nvlist_first_nvpair(nvl);
501 nvl = tmpnvl;
618 nvl = tmpnvl;
629 while ((nvp = nvlist_next_nvpair(nvl, nvp)) == NULL) {
632 if (nvlist_in_array(nvl))
634 nvl = nvlist_get_pararr(nvl, &cookie);
635 if (nvl == NULL)
637 if (nvlist_in_array(nvl) && cookie == NULL) {
638 nvp = nvlist_first_nvpair(nvl);
644 if (nvlist_in_array(nvl) && cookie == NULL)
651 nvlist_fdump(const nvlist_t *nvl, FILE *fp)
655 nvlist_dump(nvl, fileno(fp));
663 nvlist_size(const nvlist_t *nvl)
672 NVLIST_ASSERT(nvl);
673 PJDLOG_ASSERT(nvl->nvl_error == 0);
676 nvp = nvlist_first_nvpair(nvl);
687 nvl = tmpnvl;
710 nvl = tmpnvl;
718 while ((nvp = nvlist_next_nvpair(nvl, nvp)) == NULL) {
721 nvl = nvlist_get_pararr(nvl, &cookie);
722 if (nvl == NULL)
724 if (nvlist_in_array(nvl) && cookie == NULL) {
725 nvp = nvlist_first_nvpair(nvl);
730 if (nvlist_in_array(nvl) && cookie == NULL)
741 nvlist_xdescriptors(const nvlist_t *nvl, int *descs)
747 NVLIST_ASSERT(nvl);
748 PJDLOG_ASSERT(nvl->nvl_error == 0);
752 while (nvlist_next(nvl, &type, &cookie) != NULL) {
774 nvl = nvpair_get_nvlist(nvp);
786 nvl = value[0];
792 } while ((nvl = nvlist_get_pararr(nvl, &cookie)) != NULL);
800 nvlist_descriptors(const nvlist_t *nvl, size_t *nitemsp)
805 nitems = nvlist_ndescriptors(nvl);
810 nvlist_xdescriptors(nvl, fds);
819 nvlist_ndescriptors(const nvlist_t *nvl)
827 NVLIST_ASSERT(nvl);
828 PJDLOG_ASSERT(nvl->nvl_error == 0);
833 while (nvlist_next(nvl, &type, &cookie) != NULL) {
840 nvl = nvpair_get_nvlist(nvp);
852 nvl = value[0];
867 } while ((nvl = nvlist_get_pararr(nvl, &cookie)) != NULL);
876 nvlist_pack_header(const nvlist_t *nvl, unsigned char *ptr, size_t *leftp)
880 NVLIST_ASSERT(nvl);
884 nvlhdr.nvlh_flags = nvl->nvl_flags;
888 nvlhdr.nvlh_descriptors = nvlist_ndescriptors(nvl);
899 nvlist_xpack(const nvlist_t *nvl, int64_t *fdidxp, size_t *sizep)
907 NVLIST_ASSERT(nvl);
909 if (nvl->nvl_error != 0) {
910 ERRNO_SET(nvl->nvl_error);
914 size = nvlist_size(nvl);
922 ptr = nvlist_pack_header(nvl, ptr, &left);
924 nvp = nvlist_first_nvpair(nvl);
952 nvl = tmpnvl;
1001 nvl = tmpnvl;
1012 while ((nvp = nvlist_next_nvpair(nvl, nvp)) == NULL) {
1015 if (nvlist_in_array(nvl)) {
1021 nvl = nvlist_get_pararr(nvl, &cookie);
1022 if (nvl == NULL)
1024 if (nvlist_in_array(nvl) && cookie == NULL) {
1025 nvp = nvlist_first_nvpair(nvl);
1026 ptr = nvlist_pack_header(nvl, ptr,
1040 if (nvlist_in_array(nvl) && cookie == NULL)
1055 nvlist_pack(const nvlist_t *nvl, size_t *sizep)
1058 NVLIST_ASSERT(nvl);
1060 if (nvl->nvl_error != 0) {
1061 ERRNO_SET(nvl->nvl_error);
1065 if (nvlist_ndescriptors(nvl) > 0) {
1070 return (nvlist_xpack(nvl, NULL, sizep));
1104 nvlist_unpack_header(nvlist_t *nvl, const unsigned char *ptr, size_t nfds,
1130 inarrayf = (nvl->nvl_flags & NV_FLAG_IN_ARRAY);
1131 nvl->nvl_flags = (nvlhdr.nvlh_flags & NV_FLAG_PUBLIC_MASK) | inarrayf;
1149 nvlist_t *nvl, *retnvl, *tmpnvl, *array;
1160 nvl = retnvl = nvlist_create(0);
1161 if (nvl == NULL)
1164 ptr = nvlist_unpack_header(nvl, ptr, nfds, &isbe, &left);
1167 if (nvl->nvl_flags != flags) {
1210 if (nvl->nvl_parent == NULL)
1212 nvl = nvpair_nvlist(nvl->nvl_parent);
1216 if (nvl->nvl_array_next == NULL) {
1217 if (nvl->nvl_parent == NULL)
1219 nvl = nvpair_nvlist(nvl->nvl_parent);
1221 nvl = __DECONST(nvlist_t *,
1222 nvlist_get_array_next(nvl));
1223 ptr = nvlist_unpack_header(nvl, ptr, nfds,
1259 if (!nvlist_move_nvpair(nvl, nvp))
1262 nvl = tmpnvl;
1282 nvlist_send(int sock, const nvlist_t *nvl)
1290 if (nvlist_error(nvl) != 0) {
1291 ERRNO_SET(nvlist_error(nvl));
1295 fds = nvlist_descriptors(nvl, &nfds);
1302 data = nvlist_xpack(nvl, &fdidx, &datasize);
1327 nvlist_t *nvl, *ret;
1361 nvl = nvlist_xunpack(buf, size, fds, nfds, flags);
1362 if (nvl == NULL) {
1370 ret = nvl;
1381 nvlist_xfer(int sock, nvlist_t *nvl, int flags)
1384 if (nvlist_send(sock, nvl) < 0) {
1385 nvlist_destroy(nvl);
1388 nvlist_destroy(nvl);
1394 nvlist_first_nvpair(const nvlist_t *nvl)
1397 NVLIST_ASSERT(nvl);
1399 return (TAILQ_FIRST(&nvl->nvl_head));
1403 nvlist_next_nvpair(const nvlist_t *nvl, const nvpair_t *nvp)
1407 NVLIST_ASSERT(nvl);
1409 PJDLOG_ASSERT(nvpair_nvlist(nvp) == nvl);
1412 PJDLOG_ASSERT(retnvp == NULL || nvpair_nvlist(retnvp) == nvl);
1419 nvlist_prev_nvpair(const nvlist_t *nvl, const nvpair_t *nvp)
1423 NVLIST_ASSERT(nvl);
1425 PJDLOG_ASSERT(nvpair_nvlist(nvp) == nvl);
1428 PJDLOG_ASSERT(nvpair_nvlist(retnvp) == nvl);
1434 nvlist_next(const nvlist_t *nvl, int *typep, void **cookiep)
1438 NVLIST_ASSERT(nvl);
1441 nvp = nvlist_first_nvpair(nvl);
1443 nvp = nvlist_next_nvpair(nvl, *cookiep);
1454 nvlist_exists(const nvlist_t *nvl, const char *name)
1457 return (nvlist_find(nvl, NV_TYPE_NONE, name) != NULL);
1462 nvlist_exists_##type(const nvlist_t *nvl, const char *name) \
1465 return (nvlist_find(nvl, NV_TYPE_##TYPE, name) != NULL); \
1486 nvlist_add_nvpair(nvlist_t *nvl, const nvpair_t *nvp)
1492 if (nvlist_error(nvl) != 0) {
1493 ERRNO_SET(nvlist_error(nvl));
1496 if ((nvl->nvl_flags & NV_FLAG_NO_UNIQUE) == 0) {
1497 if (nvlist_exists(nvl, nvpair_name(nvp))) {
1498 nvl->nvl_error = EEXIST;
1499 ERRNO_SET(nvlist_error(nvl));
1506 nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
1507 ERRNO_SET(nvlist_error(nvl));
1511 nvpair_insert(&nvl->nvl_head, newnvp, nvl);
1516 nvlist_add_stringf(nvlist_t *nvl, const char *name, const char *valuefmt, ...)
1521 nvlist_add_stringv(nvl, name, valuefmt, valueap);
1526 nvlist_add_stringv(nvlist_t *nvl, const char *name, const char *valuefmt,
1531 if (nvlist_error(nvl) != 0) {
1532 ERRNO_SET(nvlist_error(nvl));
1538 nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
1539 ERRNO_SET(nvl->nvl_error);
1541 (void)nvlist_move_nvpair(nvl, nvp);
1547 nvlist_add_null(nvlist_t *nvl
1551 if (nvlist_error(nvl) != 0) {
1552 ERRNO_SET(nvlist_error(nvl));
1558 nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
1559 ERRNO_SET(nvl->nvl_error);
1561 (void)nvlist_move_nvpair(nvl, nvp);
1566 nvlist_add_binary(nvlist_t *nvl, const char *name, const void *value,
1571 if (nvlist_error(nvl) != 0) {
1572 ERRNO_SET(nvlist_error(nvl));
1578 nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
1579 ERRNO_SET(nvl->nvl_error);
1581 (void)nvlist_move_nvpair(nvl, nvp);
1588 nvlist_add_##type(nvlist_t *nvl, const char *name, vtype value) \
1592 if (nvlist_error(nvl) != 0) { \
1593 ERRNO_SET(nvlist_error(nvl)); \
1599 nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM); \
1600 ERRNO_SET(nvl->nvl_error); \
1602 (void)nvlist_move_nvpair(nvl, nvp); \
1618 nvlist_add_##type##_array(nvlist_t *nvl, const char *name, vtype value, \
1623 if (nvlist_error(nvl) != 0) { \
1624 ERRNO_SET(nvlist_error(nvl)); \
1630 nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM); \
1631 ERRNO_SET(nvl->nvl_error); \
1633 (void)nvlist_move_nvpair(nvl, nvp); \
1649 nvlist_append_##type##_array(nvlist_t *nvl, const char *name, vtype value)\
1653 if (nvlist_error(nvl) != 0) { \
1654 ERRNO_SET(nvlist_error(nvl)); \
1657 nvp = nvlist_find(nvl, NV_TYPE_##TYPE##_ARRAY, name); \
1659 nvlist_add_##type##_array(nvl, name, &value, 1); \
1663 nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM); \
1664 ERRNO_SET(nvl->nvl_error); \
1679 nvlist_move_nvpair(nvlist_t *nvl, nvpair_t *nvp)
1685 if (nvlist_error(nvl) != 0) {
1687 ERRNO_SET(nvlist_error(nvl));
1690 if ((nvl->nvl_flags & NV_FLAG_NO_UNIQUE) == 0) {
1691 if (nvlist_exists(nvl, nvpair_name(nvp))) {
1693 nvl->nvl_error = EEXIST;
1694 ERRNO_SET(nvl->nvl_error);
1699 nvpair_insert(&nvl->nvl_head, nvp, nvl);
1704 nvlist_move_string(nvlist_t *nvl, const char *name, char *value)
1708 if (nvlist_error(nvl) != 0) {
1710 ERRNO_SET(nvlist_error(nvl));
1716 nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
1717 ERRNO_SET(nvl->nvl_error);
1719 (void)nvlist_move_nvpair(nvl, nvp);
1724 nvlist_move_nvlist(nvlist_t *nvl, const char *name, nvlist_t *value)
1728 if (nvlist_error(nvl) != 0) {
1731 ERRNO_SET(nvlist_error(nvl));
1737 nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
1738 ERRNO_SET(nvl->nvl_error);
1740 (void)nvlist_move_nvpair(nvl, nvp);
1746 nvlist_move_descriptor(nvlist_t *nvl, const char *name, int value)
1750 if (nvlist_error(nvl) != 0) {
1752 ERRNO_SET(nvlist_error(nvl));
1758 nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
1759 ERRNO_SET(nvl->nvl_error);
1761 (void)nvlist_move_nvpair(nvl, nvp);
1767 nvlist_move_binary(nvlist_t *nvl, const char *name, void *value, size_t size)
1771 if (nvlist_error(nvl) != 0) {
1773 ERRNO_SET(nvlist_error(nvl));
1779 nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
1780 ERRNO_SET(nvl->nvl_error);
1782 (void)nvlist_move_nvpair(nvl, nvp);
1787 nvlist_move_bool_array(nvlist_t *nvl, const char *name, bool *value,
1792 if (nvlist_error(nvl) != 0) {
1794 ERRNO_SET(nvlist_error(nvl));
1800 nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
1801 ERRNO_SET(nvl->nvl_error);
1803 (void)nvlist_move_nvpair(nvl, nvp);
1808 nvlist_move_string_array(nvlist_t *nvl, const char *name, char **value,
1814 if (nvlist_error(nvl) != 0) {
1820 ERRNO_SET(nvlist_error(nvl));
1826 nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
1827 ERRNO_SET(nvl->nvl_error);
1829 (void)nvlist_move_nvpair(nvl, nvp);
1834 nvlist_move_nvlist_array(nvlist_t *nvl, const char *name, nvlist_t **value,
1840 if (nvlist_error(nvl) != 0) {
1848 ERRNO_SET(nvlist_error(nvl));
1854 nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
1855 ERRNO_SET(nvl->nvl_error);
1857 (void)nvlist_move_nvpair(nvl, nvp);
1862 nvlist_move_number_array(nvlist_t *nvl, const char *name, uint64_t *value,
1867 if (nvlist_error(nvl) != 0) {
1869 ERRNO_SET(nvlist_error(nvl));
1875 nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
1876 ERRNO_SET(nvl->nvl_error);
1878 (void)nvlist_move_nvpair(nvl, nvp);
1884 nvlist_move_descriptor_array(nvlist_t *nvl, const char *name, int *value,
1890 if (nvlist_error(nvl) != 0) {
1897 ERRNO_SET(nvlist_error(nvl));
1903 nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
1904 ERRNO_SET(nvl->nvl_error);
1906 (void)nvlist_move_nvpair(nvl, nvp);
1912 nvlist_get_nvpair(const nvlist_t *nvl, const char *name)
1915 return (nvlist_find(nvl, NV_TYPE_NONE, name));
1920 nvlist_get_##type(const nvlist_t *nvl, const char *name) \
1924 nvp = nvlist_find(nvl, NV_TYPE_##TYPE, name); \
1941 nvlist_get_binary(const nvlist_t *nvl, const char *name, size_t *sizep)
1945 nvp = nvlist_find(nvl, NV_TYPE_BINARY, name);
1954 nvlist_get_##type##_array(const nvlist_t *nvl, const char *name, \
1959 nvp = nvlist_find(nvl, NV_TYPE_##TYPE##_ARRAY, name); \
1977 nvlist_take_##type(nvlist_t *nvl, const char *name) \
1982 nvp = nvlist_find(nvl, NV_TYPE_##TYPE, name); \
1986 nvlist_remove_nvpair(nvl, nvp); \
2002 nvlist_take_binary(nvlist_t *nvl, const char *name, size_t *sizep)
2007 nvp = nvlist_find(nvl, NV_TYPE_BINARY, name);
2012 nvlist_remove_nvpair(nvl, nvp);
2019 nvlist_take_##type##_array(nvlist_t *nvl, const char *name, \
2025 nvp = nvlist_find(nvl, NV_TYPE_##TYPE##_ARRAY, name); \
2029 nvlist_remove_nvpair(nvl, nvp); \
2043 nvlist_remove_nvpair(nvlist_t *nvl, nvpair_t *nvp)
2046 NVLIST_ASSERT(nvl);
2048 PJDLOG_ASSERT(nvpair_nvlist(nvp) == nvl);
2050 nvpair_remove(&nvl->nvl_head, nvp, nvl);
2054 nvlist_free(nvlist_t *nvl, const char *name)
2057 nvlist_free_type(nvl, name, NV_TYPE_NONE);
2062 nvlist_free_##type(nvlist_t *nvl, const char *name) \
2065 nvlist_free_type(nvl, name, NV_TYPE_##TYPE); \
2086 nvlist_free_nvpair(nvlist_t *nvl, nvpair_t *nvp)
2089 NVLIST_ASSERT(nvl);
2091 PJDLOG_ASSERT(nvpair_nvlist(nvp) == nvl);
2093 nvlist_remove_nvpair(nvl, nvp);