2 This file is part of PulseAudio.
4 Copyright 2008 Joao Paulo Rechi Vita
6 PulseAudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as
8 published by the Free Software Foundation; either version 2.1 of the
9 License, or (at your option) any later version.
11 PulseAudio is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with PulseAudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
26 #include <pulsecore/core-util.h>
27 #include <modules/dbus-util.h>
29 #include "bluetooth-util.h"
37 struct pa_bluetooth_discovery
{
38 DBusConnection
*connection
;
39 PA_LLIST_HEAD(pa_dbus_pending
, pending
);
43 /* If mode == MODE_FIND look for a specific device by its address.
44 If mode == MODE_GET look for a specific device by its path. */
45 const char *looking_for
;
46 pa_bluetooth_device
*found_device
;
48 /* If looking_for is NULL we do long-time discovery */
50 pa_bluetooth_device_callback_t callback
;
51 struct userdata
*userdata
;
54 static pa_bluetooth_uuid
*uuid_new(const char *uuid
) {
57 u
= pa_xnew(pa_bluetooth_uuid
, 1);
58 u
->uuid
= pa_xstrdup(uuid
);
59 PA_LLIST_INIT(pa_bluetooth_uuid
, u
);
64 static void uuid_free(pa_bluetooth_uuid
*u
) {
71 static pa_bluetooth_device
* device_new(const char *path
) {
72 pa_bluetooth_device
*d
;
74 d
= pa_xnew(pa_bluetooth_device
, 1);
76 d
->device_info_valid
= d
->audio_sink_info_valid
= d
->headset_info_valid
= 0;
81 d
->path
= pa_xstrdup(path
);
84 d
->device_connected
= -1;
85 PA_LLIST_HEAD_INIT(pa_bluetooth_uuid
, d
->uuids
);
90 d
->audio_sink_connected
= -1;
92 d
->headset_connected
= -1;
97 void pa_bluetooth_device_free(pa_bluetooth_device
*d
) {
102 while ((u
= d
->uuids
)) {
103 PA_LLIST_REMOVE(pa_bluetooth_uuid
, d
->uuids
, u
);
110 pa_xfree(d
->address
);
114 static pa_bool_t
device_is_loaded(pa_bluetooth_device
*d
) {
118 d
->device_info_valid
&&
119 d
->audio_sink_info_valid
&&
120 d
->headset_info_valid
;
123 static pa_bool_t
device_is_audio(pa_bluetooth_device
*d
) {
126 pa_assert(d
->device_info_valid
);
127 pa_assert(d
->audio_sink_info_valid
);
128 pa_assert(d
->headset_info_valid
);
130 return d
->device_info_valid
> 0 &&
131 (d
->audio_sink_info_valid
> 0 || d
->headset_info_valid
> 0);
134 static int parse_device_property(pa_bluetooth_discovery
*y
, pa_bluetooth_device
*d
, DBusMessageIter
*i
) {
136 DBusMessageIter variant_i
;
142 if (dbus_message_iter_get_arg_type(i
) != DBUS_TYPE_STRING
) {
143 pa_log("Property name not a string.");
147 dbus_message_iter_get_basic(i
, &key
);
149 if (!dbus_message_iter_next(i
)) {
150 pa_log("Property value missing");
154 if (dbus_message_iter_get_arg_type(i
) != DBUS_TYPE_VARIANT
) {
155 pa_log("Property value not a variant.");
159 dbus_message_iter_recurse(i
, &variant_i
);
161 /* pa_log_debug("Parsing property org.bluez.Device.%s", key); */
163 switch (dbus_message_iter_get_arg_type(&variant_i
)) {
165 case DBUS_TYPE_STRING
: {
168 dbus_message_iter_get_basic(&variant_i
, &value
);
170 if (pa_streq(key
, "Name")) {
172 d
->name
= pa_xstrdup(value
);
173 } else if (pa_streq(key
, "Alias")) {
175 d
->alias
= pa_xstrdup(value
);
176 } else if (pa_streq(key
, "Address")) {
177 pa_xfree(d
->address
);
178 d
->address
= pa_xstrdup(value
);
181 /* pa_log_debug("Value %s", value); */
186 case DBUS_TYPE_BOOLEAN
: {
189 dbus_message_iter_get_basic(&variant_i
, &value
);
191 if (pa_streq(key
, "Paired"))
193 else if (pa_streq(key
, "Connected"))
194 d
->device_connected
= !!value
;
195 else if (pa_streq(key
, "Trusted"))
196 d
->trusted
= !!value
;
198 /* pa_log_debug("Value %s", pa_yes_no(value)); */
203 case DBUS_TYPE_UINT32
: {
206 dbus_message_iter_get_basic(&variant_i
, &value
);
208 if (pa_streq(key
, "Class"))
209 d
->class = (int) value
;
211 /* pa_log_debug("Value %u", (unsigned) value); */
216 case DBUS_TYPE_ARRAY
: {
219 dbus_message_iter_recurse(&variant_i
, &ai
);
221 if (dbus_message_iter_get_arg_type(&ai
) == DBUS_TYPE_STRING
&&
222 pa_streq(key
, "UUIDs")) {
224 while (dbus_message_iter_get_arg_type(&ai
) != DBUS_TYPE_INVALID
) {
225 pa_bluetooth_uuid
*node
;
228 dbus_message_iter_get_basic(&ai
, &value
);
229 node
= uuid_new(value
);
230 PA_LLIST_PREPEND(pa_bluetooth_uuid
, d
->uuids
, node
);
232 if (!dbus_message_iter_next(&ai
))
244 static int parse_audio_property(pa_bluetooth_discovery
*u
, int *connected
, DBusMessageIter
*i
) {
246 DBusMessageIter variant_i
;
249 pa_assert(connected
);
252 if (dbus_message_iter_get_arg_type(i
) != DBUS_TYPE_STRING
) {
253 pa_log("Property name not a string.");
257 dbus_message_iter_get_basic(i
, &key
);
259 if (!dbus_message_iter_next(i
)) {
260 pa_log("Property value missing");
264 if (dbus_message_iter_get_arg_type(i
) != DBUS_TYPE_VARIANT
) {
265 pa_log("Property value not a variant.");
269 dbus_message_iter_recurse(i
, &variant_i
);
271 /* pa_log_debug("Parsing property org.bluez.{AudioSink|Headset}.%s", key); */
273 switch (dbus_message_iter_get_arg_type(&variant_i
)) {
275 case DBUS_TYPE_BOOLEAN
: {
278 dbus_message_iter_get_basic(&variant_i
, &value
);
280 if (pa_streq(key
, "Connected"))
281 *connected
= !!value
;
283 /* pa_log_debug("Value %s", pa_yes_no(value)); */
292 static void run_callback(pa_bluetooth_discovery
*y
, pa_bluetooth_device
*d
, pa_bool_t good
) {
296 if (y
->mode
!= MODE_DISCOVER
)
299 if (!device_is_loaded(d
))
302 if (!device_is_audio(d
))
305 y
->callback(y
->userdata
, d
, good
);
308 static void get_properties_reply(DBusPendingCall
*pending
, void *userdata
) {
310 DBusMessageIter arg_i
, element_i
;
312 pa_bluetooth_device
*d
;
313 pa_bluetooth_discovery
*y
;
316 pa_assert_se(p
= userdata
);
317 pa_assert_se(y
= p
->context_data
);
318 pa_assert_se(r
= dbus_pending_call_steal_reply(pending
));
320 /* pa_log_debug("Got %s.GetProperties response for %s", */
321 /* dbus_message_get_interface(p->message), */
322 /* dbus_message_get_path(p->message)); */
326 valid
= dbus_message_get_type(r
) == DBUS_MESSAGE_TYPE_ERROR
? -1 : 1;
328 if (dbus_message_is_method_call(p
->message
, "org.bluez.Device", "GetProperties"))
329 d
->device_info_valid
= valid
;
330 else if (dbus_message_is_method_call(p
->message
, "org.bluez.Headset", "GetProperties"))
331 d
->headset_info_valid
= valid
;
332 else if (dbus_message_is_method_call(p
->message
, "org.bluez.AudioSink", "GetProperties"))
333 d
->audio_sink_info_valid
= valid
;
335 if (dbus_message_get_type(r
) == DBUS_MESSAGE_TYPE_ERROR
) {
337 if (!dbus_message_is_error(r
, DBUS_ERROR_UNKNOWN_METHOD
))
338 pa_log("Error from GetProperties reply: %s", dbus_message_get_error_name(r
));
343 if (!dbus_message_iter_init(r
, &arg_i
)) {
344 pa_log("GetProperties reply has no arguments.");
348 if (dbus_message_iter_get_arg_type(&arg_i
) != DBUS_TYPE_ARRAY
) {
349 pa_log("GetProperties argument is not an array.");
353 dbus_message_iter_recurse(&arg_i
, &element_i
);
354 while (dbus_message_iter_get_arg_type(&element_i
) != DBUS_TYPE_INVALID
) {
356 if (dbus_message_iter_get_arg_type(&element_i
) == DBUS_TYPE_DICT_ENTRY
) {
357 DBusMessageIter dict_i
;
359 dbus_message_iter_recurse(&element_i
, &dict_i
);
361 if (dbus_message_has_interface(p
->message
, "org.bluez.Device")) {
362 if (parse_device_property(y
, d
, &dict_i
) < 0)
365 } else if (dbus_message_has_interface(p
->message
, "org.bluez.Headset")) {
366 if (parse_audio_property(y
, &d
->headset_connected
, &dict_i
) < 0)
369 } else if (dbus_message_has_interface(p
->message
, "org.bluez.AudioSink")) {
370 if (parse_audio_property(y
, &d
->audio_sink_connected
, &dict_i
) < 0)
375 if (!dbus_message_iter_next(&element_i
))
380 run_callback(y
, d
, TRUE
);
382 dbus_message_unref(r
);
384 PA_LLIST_REMOVE(pa_dbus_pending
, y
->pending
, p
);
385 pa_dbus_pending_free(p
);
388 static pa_dbus_pending
* send_and_add_to_pending(pa_bluetooth_discovery
*y
, pa_bluetooth_device
*d
, DBusMessage
*m
, DBusPendingCallNotifyFunction func
) {
390 DBusPendingCall
*call
;
395 pa_assert_se(dbus_connection_send_with_reply(y
->connection
, m
, &call
, -1));
397 p
= pa_dbus_pending_new(y
->connection
, m
, call
, y
, d
);
398 PA_LLIST_PREPEND(pa_dbus_pending
, y
->pending
, p
);
399 dbus_pending_call_set_notify(call
, func
, p
, NULL
);
404 static void found_device(pa_bluetooth_discovery
*y
, const char* path
) {
406 pa_bluetooth_device
*d
;
411 d
= device_new(path
);
413 if (y
->mode
== MODE_DISCOVER
) {
414 pa_assert(y
->devices
);
415 pa_hashmap_put(y
->devices
, d
->path
, d
);
417 pa_assert(!y
->found_device
);
421 pa_assert_se(m
= dbus_message_new_method_call("org.bluez", path
, "org.bluez.Device", "GetProperties"));
422 send_and_add_to_pending(y
, d
, m
, get_properties_reply
);
424 pa_assert_se(m
= dbus_message_new_method_call("org.bluez", path
, "org.bluez.Headset", "GetProperties"));
425 send_and_add_to_pending(y
, d
, m
, get_properties_reply
);
427 pa_assert_se(m
= dbus_message_new_method_call("org.bluez", path
, "org.bluez.AudioSink", "GetProperties"));
428 send_and_add_to_pending(y
, d
, m
, get_properties_reply
);
431 static void list_devices_reply(DBusPendingCall
*pending
, void *userdata
) {
437 pa_bluetooth_discovery
*y
;
443 pa_assert_se(p
= userdata
);
444 pa_assert_se(y
= p
->context_data
);
445 pa_assert_se(r
= dbus_pending_call_steal_reply(pending
));
447 if (dbus_message_get_type(r
) == DBUS_MESSAGE_TYPE_ERROR
) {
448 pa_log("Error from ListDevices reply: %s", dbus_message_get_error_name(r
));
452 if (!dbus_message_get_args(r
, &e
, DBUS_TYPE_ARRAY
, DBUS_TYPE_OBJECT_PATH
, &paths
, &num
, DBUS_TYPE_INVALID
)) {
453 pa_log("org.bluez.Adapter.ListDevices returned an error: '%s'\n", e
.message
);
458 for (i
= 0; i
< num
; ++i
)
459 found_device(y
, paths
[i
]);
464 dbus_free_string_array (paths
);
466 dbus_message_unref(r
);
468 PA_LLIST_REMOVE(pa_dbus_pending
, y
->pending
, p
);
469 pa_dbus_pending_free(p
);
472 static void find_device_reply(DBusPendingCall
*pending
, void *userdata
) {
477 pa_bluetooth_discovery
*y
;
483 pa_assert_se(p
= userdata
);
484 pa_assert_se(y
= p
->context_data
);
485 pa_assert_se(r
= dbus_pending_call_steal_reply(pending
));
487 if (dbus_message_get_type(r
) == DBUS_MESSAGE_TYPE_ERROR
) {
488 pa_log("Error from FindDevice reply: %s", dbus_message_get_error_name(r
));
492 if (!dbus_message_get_args(r
, &e
, DBUS_TYPE_OBJECT_PATH
, &path
, DBUS_TYPE_INVALID
)) {
493 pa_log("org.bluez.Adapter.FindDevice returned an error: '%s'\n", e
.message
);
496 found_device(y
, path
);
499 dbus_message_unref(r
);
501 PA_LLIST_REMOVE(pa_dbus_pending
, y
->pending
, p
);
502 pa_dbus_pending_free(p
);
505 static void found_adapter(pa_bluetooth_discovery
*y
, const char *path
) {
508 if (y
->mode
== MODE_FIND
) {
509 pa_assert_se(m
= dbus_message_new_method_call("org.bluez", path
, "org.bluez.Adapter", "FindDevice"));
511 pa_assert_se(dbus_message_append_args(m
,
512 DBUS_TYPE_STRING
, &y
->looking_for
,
515 send_and_add_to_pending(y
, NULL
, m
, find_device_reply
);
518 pa_assert(y
->mode
== MODE_DISCOVER
);
520 pa_assert_se(m
= dbus_message_new_method_call("org.bluez", path
, "org.bluez.Adapter", "ListDevices"));
521 send_and_add_to_pending(y
, NULL
, m
, list_devices_reply
);
525 static void list_adapters_reply(DBusPendingCall
*pending
, void *userdata
) {
531 pa_bluetooth_discovery
*y
;
537 pa_assert_se(p
= userdata
);
538 pa_assert_se(y
= p
->context_data
);
539 pa_assert_se(r
= dbus_pending_call_steal_reply(pending
));
541 if (dbus_message_get_type(r
) == DBUS_MESSAGE_TYPE_ERROR
) {
542 pa_log("Error from ListAdapters reply: %s", dbus_message_get_error_name(r
));
546 if (!dbus_message_get_args(r
, &e
, DBUS_TYPE_ARRAY
, DBUS_TYPE_OBJECT_PATH
, &paths
, &num
, DBUS_TYPE_INVALID
)) {
547 pa_log("org.bluez.Manager.ListAdapters returned an error: %s", e
.message
);
552 for (i
= 0; i
< num
; ++i
)
553 found_adapter(y
, paths
[i
]);
558 dbus_free_string_array (paths
);
560 dbus_message_unref(r
);
562 PA_LLIST_REMOVE(pa_dbus_pending
, y
->pending
, p
);
563 pa_dbus_pending_free(p
);
566 static void list_adapters(pa_bluetooth_discovery
*y
) {
570 pa_assert_se(m
= dbus_message_new_method_call("org.bluez", "/", "org.bluez.Manager", "ListAdapters"));
571 send_and_add_to_pending(y
, NULL
, m
, list_adapters_reply
);
574 static DBusHandlerResult
filter_cb(DBusConnection
*bus
, DBusMessage
*m
, void *userdata
) {
576 pa_bluetooth_discovery
*y
;
581 pa_assert_se(y
= userdata
);
583 dbus_error_init(&err
);
585 pa_log_debug("dbus: interface=%s, path=%s, member=%s\n",
586 dbus_message_get_interface(m
),
587 dbus_message_get_path(m
),
588 dbus_message_get_member(m
));
590 if (dbus_message_is_signal(m
, "org.bluez.Adapter", "DeviceRemoved")) {
592 pa_bluetooth_device
*d
;
594 if (!dbus_message_get_args(m
, &err
, DBUS_TYPE_OBJECT_PATH
, &path
, DBUS_TYPE_INVALID
)) {
595 pa_log("Failed to parse org.bluez.Adapter.DeviceRemoved: %s", err
.message
);
599 pa_log_debug("Device %s removed", path
);
601 if ((d
= pa_hashmap_remove(y
->devices
, path
))) {
603 pa_assert_se(y
->mode
== MODE_DISCOVER
);
604 run_callback(y
, d
, FALSE
);
606 pa_bluetooth_device_free(d
);
609 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED
;
611 } else if (dbus_message_is_signal(m
, "org.bluez.Adapter", "DeviceCreated")) {
614 if (!dbus_message_get_args(m
, &err
, DBUS_TYPE_OBJECT_PATH
, &path
, DBUS_TYPE_INVALID
)) {
615 pa_log("Failed to parse org.bluez.Adapter.DeviceCreated: %s", err
.message
);
619 pa_log_debug("Device %s created", path
);
621 found_device(y
, path
);
622 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED
;
624 } else if (dbus_message_is_signal(m
, "org.bluez.Manager", "AdapterAdded")) {
627 if (!dbus_message_get_args(m
, &err
, DBUS_TYPE_OBJECT_PATH
, &path
, DBUS_TYPE_INVALID
)) {
628 pa_log("Failed to parse org.bluez.Manager.AdapterAdded: %s", err
.message
);
632 pa_log_debug("Adapter %s created", path
);
634 found_adapter(y
, path
);
635 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED
;
637 } else if (dbus_message_is_signal(m
, "org.bluez.Headset", "PropertyChanged") ||
638 dbus_message_is_signal(m
, "org.bluez.AudioSink", "PropertyChanged") ||
639 dbus_message_is_signal(m
, "org.bluez.Device", "PropertyChanged")) {
641 pa_bluetooth_device
*d
;
643 if ((d
= pa_hashmap_get(y
->devices
, dbus_message_get_path(m
)))) {
644 DBusMessageIter arg_i
;
646 if (!dbus_message_iter_init(m
, &arg_i
)) {
647 pa_log("Failed to parse PropertyChanged: %s", err
.message
);
651 if (dbus_message_has_interface(m
, "org.bluez.Device")) {
652 if (parse_device_property(y
, d
, &arg_i
) < 0)
655 } else if (dbus_message_has_interface(m
, "org.bluez.Headset")) {
656 if (parse_audio_property(y
, &d
->headset_connected
, &arg_i
) < 0)
659 } else if (dbus_message_has_interface(m
, "org.bluez.AudioSink")) {
660 if (parse_audio_property(y
, &d
->audio_sink_connected
, &arg_i
) < 0)
664 pa_assert_se(y
->mode
== MODE_DISCOVER
);
665 run_callback(y
, d
, TRUE
);
668 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED
;
672 dbus_error_free(&err
);
674 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED
;
677 pa_bluetooth_device
* pa_bluetooth_find_device(DBusConnection
*c
, const char* address
) {
678 pa_bluetooth_discovery y
;
680 memset(&y
, 0, sizeof(y
));
682 y
.looking_for
= address
;
684 PA_LLIST_HEAD_INIT(pa_dbus_pending
, y
.pending
);
688 pa_dbus_sync_pending_list(&y
.pending
);
689 pa_assert(!y
.pending
);
691 if (y
.found_device
) {
692 pa_assert(device_is_loaded(y
.found_device
));
694 if (!device_is_audio(y
.found_device
)) {
695 pa_bluetooth_device_free(y
.found_device
);
700 return y
.found_device
;
703 pa_bluetooth_device
* pa_bluetooth_get_device(DBusConnection
*c
, const char* path
) {
704 pa_bluetooth_discovery y
;
706 memset(&y
, 0, sizeof(y
));
709 PA_LLIST_HEAD_INIT(pa_dbus_pending
, y
.pending
);
711 found_device(&y
, path
);
713 pa_dbus_sync_pending_list(&y
.pending
);
714 pa_assert(!y
.pending
);
716 if (y
.found_device
) {
717 pa_assert(device_is_loaded(y
.found_device
));
719 if (!device_is_audio(y
.found_device
)) {
720 pa_bluetooth_device_free(y
.found_device
);
725 return y
.found_device
;
728 pa_bluetooth_discovery
* pa_bluetooth_discovery_new(DBusConnection
*c
, pa_bluetooth_device_callback_t cb
, struct userdata
*u
) {
730 pa_bluetooth_discovery
*y
;
735 dbus_error_init(&err
);
737 y
= pa_xnew0(pa_bluetooth_discovery
, 1);
738 y
->mode
= MODE_DISCOVER
;
742 y
->devices
= pa_hashmap_new(pa_idxset_string_hash_func
, pa_idxset_string_compare_func
);
743 PA_LLIST_HEAD_INIT(pa_dbus_pending
, y
->pending
);
745 /* dynamic detection of bluetooth audio devices */
746 if (!dbus_connection_add_filter(c
, filter_cb
, y
, NULL
)) {
747 pa_log_error("Failed to add filter function");
751 if (pa_dbus_add_matches(
753 "type='signal',sender='org.bluez',interface='org.bluez.Manager',member='AdapterAdded'",
754 "type='signal',sender='org.bluez',interface='org.bluez.Adapter',member='DeviceRemoved'",
755 "type='signal',sender='org.bluez',interface='org.bluez.Adapter',member='DeviceCreated'",
756 "type='signal',sender='org.bluez',interface='org.bluez.Device',member='PropertyChanged'",
757 "type='signal',sender='org.bluez',interface='org.bluez.Headset',member='PropertyChanged'",
758 "type='signal',sender='org.bluez',interface='org.bluez.AudioSink',member='PropertyChanged'", NULL
) < 0) {
759 pa_log("Failed to add D-Bus matches: %s", err
.message
);
768 dbus_error_free(&err
);
772 void pa_bluetooth_discovery_free(pa_bluetooth_discovery
*y
) {
773 pa_bluetooth_device
*d
;
777 pa_dbus_free_pending_list(&y
->pending
);
780 while ((d
= pa_hashmap_steal_first(y
->devices
))) {
781 run_callback(y
, d
, FALSE
);
782 pa_bluetooth_device_free(d
);
785 pa_hashmap_free(y
->devices
, NULL
, NULL
);
789 pa_dbus_remove_matches(y
->connection
,
790 "type='signal',sender='org.bluez',interface='org.bluez.Manager',member='AdapterAdded'",
791 "type='signal',sender='org.bluez',interface='org.bluez.Manager',member='AdapterRemoved'",
792 "type='signal',sender='org.bluez',interface='org.bluez.Adapter',member='DeviceRemoved'",
793 "type='signal',sender='org.bluez',interface='org.bluez.Adapter',member='DeviceCreated'",
794 "type='signal',sender='org.bluez',interface='org.bluez.Device',member='PropertyChanged'",
795 "type='signal',sender='org.bluez',interface='org.bluez.Headset',member='PropertyChanged'",
796 "type='signal',sender='org.bluez',interface='org.bluez.AudioSink',member='PropertyChanged'", NULL
);
798 dbus_connection_remove_filter(y
->connection
, filter_cb
, y
);
802 void pa_bluetooth_discovery_sync(pa_bluetooth_discovery
*y
) {
805 pa_dbus_sync_pending_list(&y
->pending
);
808 const char*pa_bluetooth_get_form_factor(uint32_t class) {
812 static const char * const table
[] = {
823 if (((class >> 8) & 31) != 4)
826 if ((i
= (class >> 2) & 63) > PA_ELEMENTSOF(table
))
832 pa_log_debug("Unknown Bluetooth minor device class %u", i
);
837 char *pa_bluetooth_cleanup_name(const char *name
) {
839 pa_bool_t space
= FALSE
;
843 while ((*name
>= 1 && *name
<= 32) || *name
>= 127)
846 t
= pa_xstrdup(name
);
848 for (s
= d
= t
; *s
; s
++) {
850 if (*s
<= 32 || *s
>= 127 || *s
== '_') {