Beispiel #1
0
static int ldbus_connection_get_max_message_size(lua_State *L) {
	DBusConnection *connection = check_DBusConnection(L, 1);

	lua_pushinteger(L, dbus_connection_get_max_message_size(connection));

	return 1;
}
Beispiel #2
0
static int method_get_clipboard(LassiConnection *lc, DBusMessage *m) {
    DBusError e;
    char *type;
    gboolean primary;
    DBusMessage *n = NULL;
    gint32 f;
    gpointer p = NULL;
    int l = 0;
    DBusMessageIter iter, sub;
    gboolean b;

    dbus_error_init(&e);

    if (!(dbus_message_get_args(m, &e, DBUS_TYPE_BOOLEAN, &primary, DBUS_TYPE_STRING, &type, DBUS_TYPE_INVALID))) {
        g_warning("Received invalid message: %s", e.message);
        dbus_error_free(&e);
        return -1;
    }

    if ((primary && (lc->server->primary_connection || lc->server->primary_empty)) ||
            (!primary && (lc->server->clipboard_connection || lc->server->clipboard_empty))) {
        n = dbus_message_new_error(m, LASSI_INTERFACE ".NotOwner", "We're not the clipboard owner");
        goto finish;
    }

    if (lassi_clipboard_get(&lc->server->clipboard_info, primary, type, &f, &p, &l) < 0) {
        n = dbus_message_new_error(m, LASSI_INTERFACE ".ClipboardFailure", "Failed to read clipboard data");
        goto finish;
    }

    if (l > dbus_connection_get_max_message_size(lc->dbus_connection)*9/10) {
        n = dbus_message_new_error(m, LASSI_INTERFACE ".TooLarge", "Clipboard data too large");
        goto finish;
    }

    n = dbus_message_new_method_return(m);
    g_assert(n);

    dbus_message_iter_init_append(n, &iter);
    b = dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &f);
    g_assert(b);

    b = dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE_AS_STRING, &sub);
    g_assert(b);

    b = dbus_message_iter_append_fixed_array(&sub, DBUS_TYPE_BYTE, &p, l);
    g_assert(b);

    b = dbus_message_iter_close_container(&iter, &sub);
    g_assert(b);

finish:
    g_assert(n);

    dbus_connection_send(lc->dbus_connection, n, NULL);
    dbus_message_unref(n);

    g_free(p);

    return 0;
}