Module Name:    src
Committed By:   thorpej
Date:           Sun Jun  7 00:12:00 UTC 2020

Modified Files:
        src/usr.sbin/btdevctl: btdevctl.c db.c print.c sdp.c

Log Message:
Update for proplib(3) API changes.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/usr.sbin/btdevctl/btdevctl.c \
    src/usr.sbin/btdevctl/sdp.c
cvs rdiff -u -r1.5 -r1.6 src/usr.sbin/btdevctl/db.c
cvs rdiff -u -r1.11 -r1.12 src/usr.sbin/btdevctl/print.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/btdevctl/btdevctl.c
diff -u src/usr.sbin/btdevctl/btdevctl.c:1.10 src/usr.sbin/btdevctl/btdevctl.c:1.11
--- src/usr.sbin/btdevctl/btdevctl.c:1.10	Sat Aug 27 22:24:14 2011
+++ src/usr.sbin/btdevctl/btdevctl.c	Sun Jun  7 00:12:00 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: btdevctl.c,v 1.10 2011/08/27 22:24:14 joerg Exp $	*/
+/*	$NetBSD: btdevctl.c,v 1.11 2020/06/07 00:12:00 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2006 Itronix Inc.
@@ -35,7 +35,7 @@
 __COPYRIGHT("@(#) Copyright (c) 2006 The NetBSD Foundation, Inc.\
   @(#) Copyright (c) 2006 Itronix, Inc.\
   All rights reserved.");
-__RCSID("$NetBSD: btdevctl.c,v 1.10 2011/08/27 22:24:14 joerg Exp $");
+__RCSID("$NetBSD: btdevctl.c,v 1.11 2020/06/07 00:12:00 thorpej Exp $");
 
 #include <prop/proplib.h>
 #include <sys/ioctl.h>
@@ -62,7 +62,6 @@ int
 main(int argc, char *argv[])
 {
 	prop_dictionary_t dev;
-	prop_object_t obj;
 	bdaddr_t laddr, raddr;
 	const char *service, *mode;
 	int ch, query, verbose, attach, detach, set, none;
@@ -161,11 +160,8 @@ main(int argc, char *argv[])
 	}
 
 	if (mode != NULL) {
-		obj = prop_string_create_cstring_nocopy(mode);
-		if (obj == NULL || !prop_dictionary_set(dev, BTDEVmode, obj))
+		if (!prop_dictionary_set_string_nocopy(dev, BTDEVmode, mode))
 			errx(EXIT_FAILURE, "proplib failure (%s)", BTDEVmode);
-
-		prop_object_release(obj);
 		set = true;
 	}
 
@@ -178,26 +174,17 @@ main(int argc, char *argv[])
 		errx(EXIT_FAILURE, "service store failed");
 
 	/* add binary local-bdaddr */
-	obj = prop_data_create_data(&laddr, sizeof(laddr));
-	if (obj == NULL || !prop_dictionary_set(dev, BTDEVladdr, obj))
+	if (!prop_dictionary_set_data(dev, BTDEVladdr, &laddr, sizeof(laddr)))
 		errx(EXIT_FAILURE, "proplib failure (%s)", BTDEVladdr);
 
-	prop_object_release(obj);
-
 	/* add binary remote-bdaddr */
-	obj = prop_data_create_data(&raddr, sizeof(raddr));
-	if (obj == NULL || !prop_dictionary_set(dev, BTDEVraddr, obj))
+	if (!prop_dictionary_set_data(dev, BTDEVraddr, &raddr, sizeof(raddr)))
 		errx(EXIT_FAILURE, "proplib failure (%s)", BTDEVraddr);
 
-	prop_object_release(obj);
-
 	/* add service name */
-	obj = prop_string_create_cstring(service);
-	if (obj == NULL || !prop_dictionary_set(dev, BTDEVservice, obj))
+	if (!prop_dictionary_set_string(dev, BTDEVservice, service))
 		errx(EXIT_FAILURE, "proplib failure (%s)", BTDEVservice);
 
-	prop_object_release(obj);
-
 	if (verbose == true)
 		cfg_print(dev);
 
Index: src/usr.sbin/btdevctl/sdp.c
diff -u src/usr.sbin/btdevctl/sdp.c:1.10 src/usr.sbin/btdevctl/sdp.c:1.11
--- src/usr.sbin/btdevctl/sdp.c:1.10	Sun Dec 10 20:38:14 2017
+++ src/usr.sbin/btdevctl/sdp.c	Sun Jun  7 00:12:00 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: sdp.c,v 1.10 2017/12/10 20:38:14 bouyer Exp $	*/
+/*	$NetBSD: sdp.c,v 1.11 2020/06/07 00:12:00 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2006 Itronix Inc.
@@ -56,7 +56,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: sdp.c,v 1.10 2017/12/10 20:38:14 bouyer Exp $");
+__RCSID("$NetBSD: sdp.c,v 1.11 2020/06/07 00:12:00 thorpej Exp $");
 
 #include <sys/types.h>
 
@@ -318,43 +318,27 @@ config_hid(prop_dictionary_t dict, sdp_d
 	    || hid_length == -1)
 		return ENOATTR;
 
-	obj = prop_string_create_cstring_nocopy("bthidev");
-	if (obj == NULL || !prop_dictionary_set(dict, BTDEVtype, obj))
+	if (!prop_dictionary_set_string_nocopy(dict, BTDEVtype, "bthidev"))
 		return errno;
 
-	prop_object_release(obj);
-
-	obj = prop_number_create_integer(control_psm);
-	if (obj == NULL || !prop_dictionary_set(dict, BTHIDEVcontrolpsm, obj))
-		return errno;
-
-	prop_object_release(obj);
-
-	obj = prop_number_create_integer(interrupt_psm);
-	if (obj == NULL || !prop_dictionary_set(dict, BTHIDEVinterruptpsm, obj))
+	if (!prop_dictionary_set_int32(dict, BTHIDEVcontrolpsm, control_psm) ||
+	    !prop_dictionary_set_int32(dict, BTHIDEVinterruptpsm,
+	    			       interrupt_psm))
 		return errno;
 
-	prop_object_release(obj);
-
-	obj = prop_data_create_data(hid_descriptor, hid_length);
+	obj = prop_data_create_copy(hid_descriptor, hid_length);
 	if (obj == NULL || !prop_dictionary_set(dict, BTHIDEVdescriptor, obj))
 		return errno;
 
 	mode = hid_mode(obj);
 	prop_object_release(obj);
 
-	obj = prop_string_create_cstring_nocopy(mode);
-	if (obj == NULL || !prop_dictionary_set(dict, BTDEVmode, obj))
+	if (!prop_dictionary_set_string_nocopy(dict, BTDEVmode, mode))
 		return errno;
 
-	prop_object_release(obj);
-
 	if (!reconnect_initiate) {
-		obj = prop_bool_create(true);
-		if (obj == NULL || !prop_dictionary_set(dict, BTHIDEVreconnect, obj))
+		if (!prop_dictionary_set_bool(dict, BTHIDEVreconnect, true))
 			return errno;
-
-		prop_object_release(obj);
 	}
 
 	return 0;
@@ -366,7 +350,6 @@ config_hid(prop_dictionary_t dict, sdp_d
 static int
 config_hset(prop_dictionary_t dict, sdp_data_t *rec)
 {
-	prop_object_t obj;
 	sdp_data_t value;
 	int32_t channel;
 	uint16_t attr;
@@ -387,18 +370,12 @@ config_hset(prop_dictionary_t dict, sdp_
 	if (channel == -1)
 		return ENOATTR;
 
-	obj = prop_string_create_cstring_nocopy("btsco");
-	if (obj == NULL || !prop_dictionary_set(dict, BTDEVtype, obj))
+	if (!prop_dictionary_set_string_nocopy(dict, BTDEVtype, "btsco"))
 		return errno;
 
-	prop_object_release(obj);
-
-	obj = prop_number_create_integer(channel);
-	if (obj == NULL || !prop_dictionary_set(dict, BTSCOchannel, obj))
+	if (!prop_dictionary_set_int32(dict, BTSCOchannel, channel))
 		return errno;
 
-	prop_object_release(obj);
-
 	return 0;
 }
 
@@ -408,7 +385,6 @@ config_hset(prop_dictionary_t dict, sdp_
 static int
 config_hf(prop_dictionary_t dict, sdp_data_t *rec)
 {
-	prop_object_t obj;
 	sdp_data_t value;
 	int32_t channel;
 	uint16_t attr;
@@ -429,24 +405,15 @@ config_hf(prop_dictionary_t dict, sdp_da
 	if (channel == -1)
 		return ENOATTR;
 
-	obj = prop_string_create_cstring_nocopy("btsco");
-	if (obj == NULL || !prop_dictionary_set(dict, BTDEVtype, obj))
+	if (!prop_dictionary_set_string_nocopy(dict, BTDEVtype, "btsco"))
 		return errno;
 
-	prop_object_release(obj);
-
-	obj = prop_bool_create(true);
-	if (obj == NULL || !prop_dictionary_set(dict, BTSCOlisten, obj))
+	if (!prop_dictionary_set_bool(dict, BTSCOlisten, true))
 		return errno;
 
-	prop_object_release(obj);
-
-	obj = prop_number_create_integer(channel);
-	if (obj == NULL || !prop_dictionary_set(dict, BTSCOchannel, obj))
+	if (!prop_dictionary_set_int32(dict, BTSCOchannel, channel))
 		return errno;
 
-	prop_object_release(obj);
-
 	return 0;
 }
 
@@ -600,7 +567,7 @@ hid_mode(prop_data_t desc)
 
 	mode = BTDEVauth;	/* default */
 
-	r = hid_use_report_desc(prop_data_data_nocopy(desc),
+	r = hid_use_report_desc(prop_data_value(desc),
 				prop_data_size(desc));
 	if (r == NULL)
 		err(EXIT_FAILURE, "hid_use_report_desc");

Index: src/usr.sbin/btdevctl/db.c
diff -u src/usr.sbin/btdevctl/db.c:1.5 src/usr.sbin/btdevctl/db.c:1.6
--- src/usr.sbin/btdevctl/db.c:1.5	Sun Feb  3 03:19:30 2019
+++ src/usr.sbin/btdevctl/db.c	Sun Jun  7 00:12:00 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: db.c,v 1.5 2019/02/03 03:19:30 mrg Exp $	*/
+/*	$NetBSD: db.c,v 1.6 2020/06/07 00:12:00 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2006 Itronix Inc.
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: db.c,v 1.5 2019/02/03 03:19:30 mrg Exp $");
+__RCSID("$NetBSD: db.c,v 1.6 2020/06/07 00:12:00 thorpej Exp $");
 
 #include <bluetooth.h>
 #include <err.h>
@@ -75,7 +75,7 @@ db_get(bdaddr_t *laddr, bdaddr_t *raddr,
 			return NULL;
 		} else {
 			obj = prop_dictionary_get(db, "btdevctl-version");
-			switch(prop_number_integer_value(obj)) {
+			switch(prop_number_signed_value(obj)) {
 			case 0: db_update0();
 				/* FALLTHROUGH */
 			case 1: db_update1();
@@ -111,7 +111,6 @@ int
 db_set(prop_dictionary_t dev, bdaddr_t *laddr, bdaddr_t *raddr, const char *service)
 {
 	prop_dictionary_t ldev, rdev;
-	prop_number_t version;
 
 	ldev = prop_dictionary_get(db, bt_ntoa(laddr, NULL));
 	if (ldev == NULL) {
@@ -141,14 +140,9 @@ db_set(prop_dictionary_t dev, bdaddr_t *
 		return 0;
 
 	if (db_flush == true) {
-		version = prop_number_create_integer(BTDEVCTL_VERSION);
-		if (version == NULL)
-			err(EXIT_FAILURE, "prop_number_create_integer");
-
-		if (!prop_dictionary_set(db, "btdevctl-version", version))
-			err(EXIT_FAILURE, "prop_dictionary_set");
-
-		prop_object_release(version);
+		if (!prop_dictionary_set_int(db, "btdevctl-version",
+					     BTDEVCTL_VERSION))
+			err(EXIT_FAILURE, "prop_dictionary_set_int");
 
 		if (!prop_dictionary_externalize_to_file(db, BTDEVCTL_PLIST))
 			warn("%s", BTDEVCTL_PLIST);
@@ -194,20 +188,20 @@ db_update0(void)
 		if (prop_data_size(obj) != sizeof(laddr))
 			errx(EXIT_FAILURE, "invalid %s", BTDEVladdr);
 
-		bdaddr_copy(&laddr, prop_data_data_nocopy(obj));
+		bdaddr_copy(&laddr, prop_data_value(obj));
 		prop_dictionary_remove(dev, BTDEVladdr);
 
 		obj = prop_dictionary_get(dev, BTDEVraddr);
 		if (prop_data_size(obj) != sizeof(raddr))
 			errx(EXIT_FAILURE, "invalid %s", BTDEVraddr);
 
-		bdaddr_copy(&raddr, prop_data_data_nocopy(obj));
+		bdaddr_copy(&raddr, prop_data_value(obj));
 		prop_dictionary_remove(dev, BTDEVraddr);
 
 		obj = prop_dictionary_get(dev, BTDEVtype);
-		if (prop_string_equals_cstring(obj, "bthidev"))
+		if (prop_string_equals_string(obj, "bthidev"))
 			service = "HID";
-		else if (prop_string_equals_cstring(obj, "btsco")) {
+		else if (prop_string_equals_string(obj, "btsco")) {
 			obj = prop_dictionary_get(dev, BTSCOlisten);
 			if (prop_bool_true(obj))
 				service = "HF";
@@ -247,7 +241,7 @@ db_update1(void)
 	while ((key = prop_object_iterator_next(iter0)) != NULL) {
 		ldev = prop_dictionary_get_keysym(db, key);
 		if (prop_object_type(ldev) != PROP_TYPE_DICTIONARY
-		    || !bt_aton(prop_dictionary_keysym_cstring_nocopy(key), &bdaddr))
+		    || !bt_aton(prop_dictionary_keysym_value(key), &bdaddr))
 			continue;
 
 		iter1 = prop_dictionary_iterator(ldev);
@@ -257,7 +251,7 @@ db_update1(void)
 		while ((key = prop_object_iterator_next(iter1)) != NULL) {
 			rdev = prop_dictionary_get_keysym(ldev, key);
 			if (prop_object_type(rdev) != PROP_TYPE_DICTIONARY
-			    || !bt_aton(prop_dictionary_keysym_cstring_nocopy(key), &bdaddr))
+			    || !bt_aton(prop_dictionary_keysym_value(key), &bdaddr))
 				continue;
 
 			srv = prop_dictionary_get(rdev, "HID");
@@ -268,11 +262,9 @@ db_update1(void)
 			if (prop_object_type(obj) != PROP_TYPE_DATA)
 				continue;
 
-			obj = prop_string_create_cstring_nocopy(hid_mode(obj));
-			if (obj == NULL || !prop_dictionary_set(srv, BTDEVmode, obj))
+			if (!prop_dictionary_set_string_nocopy(srv, BTDEVmode,
+							       hid_mode(obj)))
 				err(EXIT_FAILURE, "Cannot set %s", BTDEVmode);
-
-			prop_object_release(obj);
 		}
 
 		prop_object_iterator_release(iter1);

Index: src/usr.sbin/btdevctl/print.c
diff -u src/usr.sbin/btdevctl/print.c:1.11 src/usr.sbin/btdevctl/print.c:1.12
--- src/usr.sbin/btdevctl/print.c:1.11	Sun Dec 10 20:38:14 2017
+++ src/usr.sbin/btdevctl/print.c	Sun Jun  7 00:12:00 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: print.c,v 1.11 2017/12/10 20:38:14 bouyer Exp $	*/
+/*	$NetBSD: print.c,v 1.12 2020/06/07 00:12:00 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2006 Itronix Inc.
@@ -58,7 +58,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: print.c,v 1.11 2017/12/10 20:38:14 bouyer Exp $");
+__RCSID("$NetBSD: print.c,v 1.12 2020/06/07 00:12:00 thorpej Exp $");
 
 #include <sys/types.h>
 
@@ -92,17 +92,17 @@ cfg_print(prop_dictionary_t dict)
 	if (prop_object_type(obj) != PROP_TYPE_DATA) {
 		return;
 	}
-	printf("local bdaddr: %s\n", bt_ntoa(prop_data_data_nocopy(obj), NULL));
+	printf("local bdaddr: %s\n", bt_ntoa(prop_data_value(obj), NULL));
 
 	obj = prop_dictionary_get(dict, BTDEVraddr);
 	if (prop_object_type(obj) != PROP_TYPE_DATA) {
 		return;
 	}
-	printf("remote bdaddr: %s\n", bt_ntoa(prop_data_data_nocopy(obj), NULL));
+	printf("remote bdaddr: %s\n", bt_ntoa(prop_data_value(obj), NULL));
 
 	obj = prop_dictionary_get(dict, BTDEVmode);
 	if (prop_object_type(obj) == PROP_TYPE_STRING)
-		printf("link mode: %s\n", prop_string_cstring_nocopy(obj));
+		printf("link mode: %s\n", prop_string_value(obj));
 
 	if (prop_dictionary_get_uint16(dict, BTDEVvendor, &v))
 		printf("vendor id: 0x%04x\n", v);
@@ -115,14 +115,14 @@ cfg_print(prop_dictionary_t dict)
 		printf("No device type!\n");
 		return;
 	}
-	printf("device type: %s\n", prop_string_cstring_nocopy(obj));
+	printf("device type: %s\n", prop_string_value(obj));
 
-	if (prop_string_equals_cstring(obj, "bthidev")) {
+	if (prop_string_equals_string(obj, "bthidev")) {
 		cfg_bthidev(dict);
 		return;
 	}
 
-	if (prop_string_equals_cstring(obj, "btsco")) {
+	if (prop_string_equals_string(obj, "btsco")) {
 		cfg_btsco(dict);
 		return;
 	}
@@ -138,12 +138,12 @@ cfg_bthidev(prop_dictionary_t dict)
 	obj = prop_dictionary_get(dict, BTHIDEVcontrolpsm);
 	if (prop_object_type(obj) == PROP_TYPE_NUMBER)
 		printf("control psm: 0x%4.4" PRIx64 "\n",
-			prop_number_integer_value(obj));
+			prop_number_signed_value(obj));
 
 	obj = prop_dictionary_get(dict, BTHIDEVinterruptpsm);
 	if (prop_object_type(obj) == PROP_TYPE_NUMBER)
 		printf("interrupt psm: 0x%4.4" PRIx64 "\n",
-			prop_number_integer_value(obj));
+			prop_number_signed_value(obj));
 
 	obj = prop_dictionary_get(dict, BTHIDEVreconnect);
 	if (prop_bool_true(obj))
@@ -165,7 +165,7 @@ cfg_btsco(prop_dictionary_t dict)
 	obj = prop_dictionary_get(dict, BTSCOchannel);
 	if (prop_object_type(obj) == PROP_TYPE_NUMBER)
 		printf("channel: %" PRId64 "\n",
-			prop_number_integer_value(obj));
+			prop_number_signed_value(obj));
 }
 
 static void
@@ -177,7 +177,7 @@ hid_parse(prop_data_t desc)
 
 	hid_init(NULL);
 
-	r = hid_use_report_desc(prop_data_data_nocopy(desc),
+	r = hid_use_report_desc(prop_data_value(desc),
 				prop_data_size(desc));
 	if (r == NULL)
 		return;

Reply via email to