1 module soup.AuthDomainDigest;
2 
3 private import glib.ConstructionException;
4 private import glib.Str;
5 private import gobject.ObjectG;
6 private import soup.AuthDomain;
7 private import soup.c.functions;
8 public  import soup.c.types;
9 
10 
11 /**
12  * #SoupAuthDomainDigest handles the server side of HTTP "Digest"
13  * authentication.
14  */
15 public class AuthDomainDigest : AuthDomain
16 {
17 	/** the main Gtk struct */
18 	protected SoupAuthDomainDigest* soupAuthDomainDigest;
19 
20 	/** Get the main Gtk struct */
21 	public SoupAuthDomainDigest* getAuthDomainDigestStruct(bool transferOwnership = false)
22 	{
23 		if (transferOwnership)
24 			ownedRef = false;
25 		return soupAuthDomainDigest;
26 	}
27 
28 	/** the main Gtk struct as a void* */
29 	protected override void* getStruct()
30 	{
31 		return cast(void*)soupAuthDomainDigest;
32 	}
33 
34 	/**
35 	 * Sets our main struct and passes it to the parent class.
36 	 */
37 	public this (SoupAuthDomainDigest* soupAuthDomainDigest, bool ownedRef = false)
38 	{
39 		this.soupAuthDomainDigest = soupAuthDomainDigest;
40 		super(cast(SoupAuthDomain*)soupAuthDomainDigest, ownedRef);
41 	}
42 
43 
44 	/** */
45 	public static GType getType()
46 	{
47 		return soup_auth_domain_digest_get_type();
48 	}
49 
50 	/**
51 	 * Encodes the username/realm/password triplet for Digest
52 	 * authentication. (That is, it returns a stringified MD5 hash of
53 	 * @username, @realm, and @password concatenated together). This is
54 	 * the form that is needed as the return value of
55 	 * #SoupAuthDomainDigest's auth handler.
56 	 *
57 	 * For security reasons, you should store the encoded hash, rather
58 	 * than storing the cleartext password itself and calling this method
59 	 * only when you need to verify it. This way, if your server is
60 	 * compromised, the attackers will not gain access to cleartext
61 	 * passwords which might also be usable at other sites. (Note also
62 	 * that the encoded password returned by this method is identical to
63 	 * the encoded password stored in an Apache .htdigest file.)
64 	 *
65 	 * Params:
66 	 *     username = a username
67 	 *     realm = an auth realm name
68 	 *     password = the password for @username in @realm
69 	 *
70 	 * Returns: the encoded password
71 	 */
72 	public static string encodePassword(string username, string realm, string password)
73 	{
74 		auto retStr = soup_auth_domain_digest_encode_password(Str.toStringz(username), Str.toStringz(realm), Str.toStringz(password));
75 
76 		scope(exit) Str.freeString(retStr);
77 		return Str.toString(retStr);
78 	}
79 
80 	/**
81 	 * Sets the callback that @domain will use to authenticate incoming
82 	 * requests. For each request containing authorization, @domain will
83 	 * invoke the callback, and then either accept or reject the request
84 	 * based on @callback's return value.
85 	 *
86 	 * You can also set the auth callback by setting the
87 	 * %SOUP_AUTH_DOMAIN_DIGEST_AUTH_CALLBACK and
88 	 * %SOUP_AUTH_DOMAIN_DIGEST_AUTH_DATA properties, which can also be
89 	 * used to set the callback at construct time.
90 	 *
91 	 * Params:
92 	 *     callback = the callback
93 	 *     userData = data to pass to @auth_callback
94 	 *     dnotify = destroy notifier to free @user_data when @domain
95 	 *         is destroyed
96 	 */
97 	public void setAuthCallback(SoupAuthDomainDigestAuthCallback callback, void* userData, GDestroyNotify dnotify)
98 	{
99 		soup_auth_domain_digest_set_auth_callback(cast(SoupAuthDomain*)soupAuthDomainDigest, callback, userData, dnotify);
100 	}
101 }