org.gnome.soup.AuthDomainGenericAuthCallback Maven / Gradle / Ivy
Show all versions of soup Show documentation
// Java-GI - Java language bindings for GObject-Introspection-based libraries
// Copyright (C) 2022-2024 Jan-Willem Harmannij
//
// SPDX-License-Identifier: LGPL-2.1-or-later
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, see .
//
// This file has been generated with Java-GI.
// Do not edit this file directly!
// Visit for more information.
//
package org.gnome.soup;
import io.github.jwharm.javagi.gobject.InstanceCache;
import io.github.jwharm.javagi.interop.Interop;
import java.lang.FunctionalInterface;
import java.lang.String;
import java.lang.foreign.Arena;
import java.lang.foreign.FunctionDescriptor;
import java.lang.foreign.Linker;
import java.lang.foreign.MemorySegment;
import java.lang.foreign.ValueLayout;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import javax.annotation.processing.Generated;
/**
* Functional interface declaration of the {@code AuthDomainGenericAuthCallback} callback.
*/
@FunctionalInterface
@Generated("io.github.jwharm.JavaGI")
public interface AuthDomainGenericAuthCallback {
/**
* The prototype for a {@code SoupAuthDomain} generic authentication callback.
*
* The callback should look up the user's password, call
* {@link AuthDomain#checkPassword}, and use the return value from that method
* as its own return value.
*
* In general, for security reasons, it is preferable to use the
* auth-domain-specific auth callbacks (eg,
* {@code AuthDomainBasicAuthCallback} and
* {@code AuthDomainDigestAuthCallback}), because they don't require
* keeping a cleartext password database. Most users will use the same
* password for many different sites, meaning if any site with a
* cleartext password database is compromised, accounts on other
* servers might be compromised as well. For many of the cases where
* {@link Server} is used, this is not really relevant, but it may still
* be worth considering.
*/
boolean run(AuthDomain domain, ServerMessage msg, String username);
/**
* The {@code upcall} method is called from native code. The parameters
* are marshaled and {@link #run} is executed.
*/
default int upcall(MemorySegment domain, MemorySegment msg, MemorySegment username,
MemorySegment userData) {
Arena _arena = Arena.ofAuto();
var _result = run((AuthDomain) InstanceCache.getForType(domain, AuthDomain.AuthDomainImpl::new, false), (ServerMessage) InstanceCache.getForType(msg, ServerMessage::new, false), Interop.getStringFrom(username, false));
return _result ? 1 : 0;
}
/**
* Creates a native function pointer to the {@link #upcall} method.
*
* @return the native function pointer
*/
default MemorySegment toCallback(Arena arena) {
FunctionDescriptor _fdesc = FunctionDescriptor.of(ValueLayout.JAVA_INT, ValueLayout.ADDRESS,
ValueLayout.ADDRESS, ValueLayout.ADDRESS, ValueLayout.ADDRESS);
MethodHandle _handle = Interop.upcallHandle(MethodHandles.lookup(), AuthDomainGenericAuthCallback.class, _fdesc);
return Linker.nativeLinker().upcallStub(_handle.bindTo(this), _fdesc, arena);
}
}