Пример #1
0
static bool properties_to_info(DBusMessage* properties, SynceInfo* info)
{
  DBusMessageIter iter;
  DBusMessageIter iter_dict;

  dbus_message_iter_init(properties, &iter);

  for (dbus_message_iter_init_dict_iterator(&iter, &iter_dict);
      ;
      dbus_message_iter_next(&iter_dict))
  {
    char* str_value = NULL;
    char* key      = dbus_message_iter_get_dict_key(&iter_dict);
    int   type     = dbus_message_iter_get_arg_type(&iter_dict);
    int   int_value;

    synce_debug("Key = %s", key);

    if (!key)
      continue;

    switch (type)
    {
      case DBUS_TYPE_STRING:
        str_value = dbus_message_iter_get_string(&iter_dict);

        if (STR_EQUAL(key, "address"))
          info->ip = STRDUP(str_value);
        else if (STR_EQUAL(key, "password"))
          info->password = STRDUP(str_value);

        /* TODO: handle more string properties */

        dbus_free(str_value);
        break;

      case DBUS_TYPE_INT32:
        int_value = dbus_message_iter_get_int32(&iter_dict);

        if (STR_EQUAL(key, "key"))
          info->key = int_value;

        /* TODO: handle more int32 properties */

        break;
    }

    dbus_free(key);

    if (!dbus_message_iter_has_next(&iter_dict))
      break;
  }

  /* Fake dccm PID! */
  info->dccm_pid = getpid();

  return info->ip != NULL;
}
Пример #2
0
static void reply_handler_function(DBusPendingCall *call, void *user_data)
{
	struct pin_request *req = (struct pin_request *) user_data;
	pin_code_reply_cp pr;
	DBusMessage *message;
	DBusMessageIter iter;
	int type;
	size_t len;
	char *pin;

	message = dbus_pending_call_get_reply(call);

	if (dbus_message_is_error(message, WRONG_ARGS_ERROR))
		goto error;

	dbus_message_iter_init(message, &iter);

	type = dbus_message_iter_get_arg_type(&iter);
	if (type != DBUS_TYPE_STRING)
		goto error;

	pin = dbus_message_iter_get_string(&iter);
	len = strlen(pin);

	memset(&pr, 0, sizeof(pr));
	bacpy(&pr.bdaddr, &req->bda);
	memcpy(pr.pin_code, pin, len);
	pr.pin_len = len;
	hci_send_cmd(req->dev, OGF_LINK_CTL, OCF_PIN_CODE_REPLY,
						PIN_CODE_REPLY_CP_SIZE, &pr);

	return;

error:
	hci_send_cmd(req->dev, OGF_LINK_CTL, OCF_PIN_CODE_NEG_REPLY,
							6, &req->bda);
}