1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19  
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 /*
25  * Conversion parameters:
26  * inFile  = GCredentials.html
27  * outPack = gio
28  * outFile = Credentials
29  * strct   = GCredentials
30  * realStrct=
31  * ctorStrct=
32  * clss    = Credentials
33  * interf  = 
34  * class Code: No
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- g_credentials_
41  * omit structs:
42  * omit prefixes:
43  * omit code:
44  * omit signals:
45  * imports:
46  * 	- glib.Str
47  * 	- glib.ErrorG
48  * 	- glib.GException
49  * structWrap:
50  * 	- GCredentials* -> Credentials
51  * module aliases:
52  * local aliases:
53  * overrides:
54  * 	- toString
55  */
56 
57 module gio.Credentials;
58 
59 public  import gtkc.giotypes;
60 
61 private import gtkc.gio;
62 private import glib.ConstructionException;
63 private import gobject.ObjectG;
64 
65 
66 private import glib.Str;
67 private import glib.ErrorG;
68 private import glib.GException;
69 
70 
71 
72 private import gobject.ObjectG;
73 
74 /**
75  * Description
76  * The GCredentials type is a reference-counted wrapper for native
77  * credentials. This information is typically used for identifying,
78  * authenticating and authorizing other processes.
79  * Some operating systems supports looking up the credentials of the
80  * remote peer of a communication endpoint - see e.g.
81  * g_socket_get_credentials().
82  * Some operating systems supports securely sending and receiving
83  * credentials over a Unix Domain Socket, see
84  * GUnixCredentialsMessage, g_unix_connection_send_credentials() and
85  * g_unix_connection_receive_credentials() for details.
86  * On Linux, the native credential type is a struct ucred
87  * - see the
88  * unix(7)
89  * man page for details. This corresponds to
90  * G_CREDENTIALS_TYPE_LINUX_UCRED.
91  * On FreeBSD, the native credential type is a struct cmsgcred.
92  * This corresponds to G_CREDENTIALS_TYPE_FREEBSD_CMSGCRED.
93  */
94 public class Credentials : ObjectG
95 {
96 	
97 	/** the main Gtk struct */
98 	protected GCredentials* gCredentials;
99 	
100 	
101 	public GCredentials* getCredentialsStruct()
102 	{
103 		return gCredentials;
104 	}
105 	
106 	
107 	/** the main Gtk struct as a void* */
108 	protected override void* getStruct()
109 	{
110 		return cast(void*)gCredentials;
111 	}
112 	
113 	/**
114 	 * Sets our main struct and passes it to the parent class
115 	 */
116 	public this (GCredentials* gCredentials)
117 	{
118 		super(cast(GObject*)gCredentials);
119 		this.gCredentials = gCredentials;
120 	}
121 	
122 	protected override void setStruct(GObject* obj)
123 	{
124 		super.setStruct(obj);
125 		gCredentials = cast(GCredentials*)obj;
126 	}
127 	
128 	/**
129 	 */
130 	
131 	/**
132 	 * Creates a new GCredentials object with credentials matching the
133 	 * the current process.
134 	 * Since 2.26
135 	 * Throws: ConstructionException GTK+ fails to create the object.
136 	 */
137 	public this ()
138 	{
139 		// GCredentials * g_credentials_new (void);
140 		auto p = g_credentials_new();
141 		if(p is null)
142 		{
143 			throw new ConstructionException("null returned by g_credentials_new()");
144 		}
145 		this(cast(GCredentials*) p);
146 	}
147 	
148 	/**
149 	 * Creates a human-readable textual representation of credentials
150 	 * that can be used in logging and debug messages. The format of the
151 	 * returned string may change in future GLib release.
152 	 * Since 2.26
153 	 * Returns: A string that should be freed with g_free().
154 	 */
155 	public override string toString()
156 	{
157 		// gchar * g_credentials_to_string (GCredentials *credentials);
158 		return Str.toString(g_credentials_to_string(gCredentials));
159 	}
160 	
161 	/**
162 	 * Gets a pointer to native credentials of type native_type from
163 	 * credentials.
164 	 * It is a programming error (which will cause an warning to be
165 	 * logged) to use this method if there is no GCredentials support for
166 	 * the OS or if native_type isn't supported by the OS.
167 	 * Since 2.26
168 	 * Params:
169 	 * nativeType = The type of native credentials to get.
170 	 * Returns: The pointer to native credentials or NULL if the operation there is no GCredentials support for the OS or if native_type isn't supported by the OS. Do not free the returned data, it is owned by credentials.
171 	 */
172 	public void* getNative(GCredentialsType nativeType)
173 	{
174 		// gpointer g_credentials_get_native (GCredentials *credentials,  GCredentialsType native_type);
175 		return g_credentials_get_native(gCredentials, nativeType);
176 	}
177 	
178 	/**
179 	 * Copies the native credentials of type native_type from native
180 	 * into credentials.
181 	 * It is a programming error (which will cause an warning to be
182 	 * logged) to use this method if there is no GCredentials support for
183 	 * the OS or if native_type isn't supported by the OS.
184 	 * Since 2.26
185 	 * Params:
186 	 * nativeType = The type of native credentials to set.
187 	 * native = A pointer to native credentials.
188 	 */
189 	public void setNative(GCredentialsType nativeType, void* native)
190 	{
191 		// void g_credentials_set_native (GCredentials *credentials,  GCredentialsType native_type,  gpointer native);
192 		g_credentials_set_native(gCredentials, nativeType, native);
193 	}
194 	
195 	/**
196 	 * Checks if credentials and other_credentials is the same user.
197 	 * This operation can fail if GCredentials is not supported on the
198 	 * the OS.
199 	 * Since 2.26
200 	 * Params:
201 	 * otherCredentials = A GCredentials.
202 	 * Returns: TRUE if credentials and other_credentials has the same user, FALSE otherwise or if error is set.
203 	 * Throws: GException on failure.
204 	 */
205 	public int isSameUser(Credentials otherCredentials)
206 	{
207 		// gboolean g_credentials_is_same_user (GCredentials *credentials,  GCredentials *other_credentials,  GError **error);
208 		GError* err = null;
209 		
210 		auto p = g_credentials_is_same_user(gCredentials, (otherCredentials is null) ? null : otherCredentials.getCredentialsStruct(), &err);
211 		
212 		if (err !is null)
213 		{
214 			throw new GException( new ErrorG(err) );
215 		}
216 		
217 		return p;
218 	}
219 	
220 	/**
221 	 * Tries to get the UNIX user identifier from credentials. This
222 	 * method is only available on UNIX platforms.
223 	 * This operation can fail if GCredentials is not supported on the
224 	 * OS or if the native credentials type does not contain information
225 	 * about the UNIX user.
226 	 * Since 2.26
227 	 * Returns: The UNIX user identifier or -1 if error is set.
228 	 * Throws: GException on failure.
229 	 */
230 	public uid_t getUnixUser()
231 	{
232 		// uid_t g_credentials_get_unix_user (GCredentials *credentials,  GError **error);
233 		GError* err = null;
234 		
235 		auto p = g_credentials_get_unix_user(gCredentials, &err);
236 		
237 		if (err !is null)
238 		{
239 			throw new GException( new ErrorG(err) );
240 		}
241 		
242 		return p;
243 	}
244 	
245 	/**
246 	 * Tries to set the UNIX user identifier on credentials. This method
247 	 * is only available on UNIX platforms.
248 	 * This operation can fail if GCredentials is not supported on the
249 	 * OS or if the native credentials type does not contain information
250 	 * about the UNIX user.
251 	 * Since 2.26
252 	 * Params:
253 	 * uid = The UNIX user identifier to set.
254 	 * Returns: TRUE if uid was set, FALSE if error is set.
255 	 * Throws: GException on failure.
256 	 */
257 	public int setUnixUser(uid_t uid)
258 	{
259 		// gboolean g_credentials_set_unix_user (GCredentials *credentials,  uid_t uid,  GError **error);
260 		GError* err = null;
261 		
262 		auto p = g_credentials_set_unix_user(gCredentials, uid, &err);
263 		
264 		if (err !is null)
265 		{
266 			throw new GException( new ErrorG(err) );
267 		}
268 		
269 		return p;
270 	}
271 }