bool prop_dictionary_set_bool(prop_dictionary_t dict, const char *key, bool val) { prop_bool_t b; int rv; b = prop_bool_create(val); if (b == NULL) return (false); rv = prop_dictionary_set(dict, key, b); prop_object_release(b); return (rv); }
/* * Configure HF results */ 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; channel = -1; while (sdp_get_attr(rec, &attr, &value)) { switch (attr) { case SDP_ATTR_PROTOCOL_DESCRIPTOR_LIST: channel = parse_pdl(&value, SDP_UUID_PROTOCOL_RFCOMM); break; default: break; } } if (channel == -1) return ENOATTR; obj = prop_string_create_cstring_nocopy("btsco"); if (obj == NULL || !prop_dictionary_set(dict, BTDEVtype, obj)) return errno; prop_object_release(obj); obj = prop_bool_create(true); if (obj == NULL || !prop_dictionary_set(dict, BTSCOlisten, obj)) return errno; prop_object_release(obj); obj = prop_number_create_integer(channel); if (obj == NULL || !prop_dictionary_set(dict, BTSCOchannel, obj)) return errno; prop_object_release(obj); return 0; }
static void parse_bool_param(prop_dictionary_t props, const char *name, const char *value) { bool boolvalue; assert(name != NULL); assert(value != NULL); if (strcasecmp(value, "1") == 0 || strcasecmp(value, "true") == 0 || strcasecmp(value, "yes") == 0) boolvalue = true; else if (strcasecmp(value, "0") == 0 || strcasecmp(value, "false") == 0 || strcasecmp(value, "no") == 0) boolvalue = false; else errx(EXIT_FAILURE, "Invalid boolean value `%s'", value); prop_dictionary_set(props, name, prop_bool_create(boolvalue)); }
/* * Configure HID results */ static int config_hid(prop_dictionary_t dict, sdp_data_t *rec) { prop_object_t obj; int32_t control_psm, interrupt_psm, reconnect_initiate, hid_length; uint8_t *hid_descriptor; sdp_data_t value; const char *mode; uint16_t attr; control_psm = -1; interrupt_psm = -1; reconnect_initiate = -1; hid_descriptor = NULL; hid_length = -1; while (sdp_get_attr(rec, &attr, &value)) { switch (attr) { case SDP_ATTR_PROTOCOL_DESCRIPTOR_LIST: control_psm = parse_pdl(&value, SDP_UUID_PROTOCOL_L2CAP); break; case SDP_ATTR_ADDITIONAL_PROTOCOL_DESCRIPTOR_LISTS: interrupt_psm = parse_apdl(&value, SDP_UUID_PROTOCOL_L2CAP); break; case 0x0205: /* HIDReconnectInitiate */ reconnect_initiate = parse_boolean(&value); break; case 0x0206: /* HIDDescriptorList */ if (parse_hid_descriptor(&value)) { hid_descriptor = value.next; hid_length = value.end - value.next; } break; default: break; } } if (control_psm == -1 || interrupt_psm == -1 || reconnect_initiate == -1 || hid_descriptor == NULL || hid_length == -1) return ENOATTR; obj = prop_string_create_cstring_nocopy("bthidev"); if (obj == NULL || !prop_dictionary_set(dict, BTDEVtype, obj)) 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)) return errno; prop_object_release(obj); obj = prop_data_create_data(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)) return errno; prop_object_release(obj); if (!reconnect_initiate) { obj = prop_bool_create(true); if (obj == NULL || !prop_dictionary_set(dict, BTHIDEVreconnect, obj)) return errno; prop_object_release(obj); } return 0; }