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 private import glib.Str;
66 private import glib.ErrorG;
67 private import glib.GException;
68 
69 
70 private import gobject.ObjectG;
71 
72 /**
73  * The GCredentials type is a reference-counted wrapper for native
74  * credentials. This information is typically used for identifying,
75  * authenticating and authorizing other processes.
76  *
77  * Some operating systems supports looking up the credentials of the
78  * remote peer of a communication endpoint - see e.g.
79  * g_socket_get_credentials().
80  *
81  * Some operating systems supports securely sending and receiving
82  * credentials over a Unix Domain Socket, see
83  * GUnixCredentialsMessage, g_unix_connection_send_credentials() and
84  * g_unix_connection_receive_credentials() for details.
85  *
86  * On Linux, the native credential type is a struct ucred
87  *
88  * see the
89  * unix(7)
90  * man page for details. This corresponds to
91  * G_CREDENTIALS_TYPE_LINUX_UCRED.
92  *
93  * On FreeBSD, the native credential type is a struct cmsgcred.
94  * This corresponds to G_CREDENTIALS_TYPE_FREEBSD_CMSGCRED.
95  *
96  * On OpenBSD, the native credential type is a struct sockpeercred.
97  * This corresponds to G_CREDENTIALS_TYPE_OPENBSD_SOCKPEERCRED.
98  */
99 public class Credentials : ObjectG
100 {
101 	
102 	/** the main Gtk struct */
103 	protected GCredentials* gCredentials;
104 	
105 	
106 	/** Get the main Gtk struct */
107 	public GCredentials* getCredentialsStruct()
108 	{
109 		return gCredentials;
110 	}
111 	
112 	
113 	/** the main Gtk struct as a void* */
114 	protected override void* getStruct()
115 	{
116 		return cast(void*)gCredentials;
117 	}
118 	
119 	/**
120 	 * Sets our main struct and passes it to the parent class
121 	 */
122 	public this (GCredentials* gCredentials)
123 	{
124 		super(cast(GObject*)gCredentials);
125 		this.gCredentials = gCredentials;
126 	}
127 	
128 	protected override void setStruct(GObject* obj)
129 	{
130 		super.setStruct(obj);
131 		gCredentials = cast(GCredentials*)obj;
132 	}
133 	
134 	/**
135 	 */
136 	
137 	/**
138 	 * Creates a new GCredentials object with credentials matching the
139 	 * the current process.
140 	 * Since 2.26
141 	 * Throws: ConstructionException GTK+ fails to create the object.
142 	 */
143 	public this ()
144 	{
145 		// GCredentials * g_credentials_new (void);
146 		auto p = g_credentials_new();
147 		if(p is null)
148 		{
149 			throw new ConstructionException("null returned by g_credentials_new()");
150 		}
151 		this(cast(GCredentials*) p);
152 	}
153 	
154 	/**
155 	 * Creates a human-readable textual representation of credentials
156 	 * that can be used in logging and debug messages. The format of the
157 	 * returned string may change in future GLib release.
158 	 * Since 2.26
159 	 * Returns: A string that should be freed with g_free().
160 	 */
161 	public override string toString()
162 	{
163 		// gchar * g_credentials_to_string (GCredentials *credentials);
164 		return Str.toString(g_credentials_to_string(gCredentials));
165 	}
166 	
167 	/**
168 	 * Gets a pointer to native credentials of type native_type from
169 	 * credentials.
170 	 * It is a programming error (which will cause an warning to be
171 	 * logged) to use this method if there is no GCredentials support for
172 	 * the OS or if native_type isn't supported by the OS.
173 	 * Since 2.26
174 	 * Params:
175 	 * nativeType = The type of native credentials to get.
176 	 * 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.
177 	 */
178 	public void* getNative(GCredentialsType nativeType)
179 	{
180 		// gpointer g_credentials_get_native (GCredentials *credentials,  GCredentialsType native_type);
181 		return g_credentials_get_native(gCredentials, nativeType);
182 	}
183 	
184 	/**
185 	 * Copies the native credentials of type native_type from native
186 	 * into credentials.
187 	 * It is a programming error (which will cause an warning to be
188 	 * logged) to use this method if there is no GCredentials support for
189 	 * the OS or if native_type isn't supported by the OS.
190 	 * Since 2.26
191 	 * Params:
192 	 * nativeType = The type of native credentials to set.
193 	 * native = A pointer to native credentials.
194 	 */
195 	public void setNative(GCredentialsType nativeType, void* native)
196 	{
197 		// void g_credentials_set_native (GCredentials *credentials,  GCredentialsType native_type,  gpointer native);
198 		g_credentials_set_native(gCredentials, nativeType, native);
199 	}
200 	
201 	/**
202 	 * Checks if credentials and other_credentials is the same user.
203 	 * This operation can fail if GCredentials is not supported on the
204 	 * the OS.
205 	 * Since 2.26
206 	 * Params:
207 	 * otherCredentials = A GCredentials.
208 	 * Returns: TRUE if credentials and other_credentials has the same user, FALSE otherwise or if error is set.
209 	 * Throws: GException on failure.
210 	 */
211 	public int isSameUser(Credentials otherCredentials)
212 	{
213 		// gboolean g_credentials_is_same_user (GCredentials *credentials,  GCredentials *other_credentials,  GError **error);
214 		GError* err = null;
215 		
216 		auto p = g_credentials_is_same_user(gCredentials, (otherCredentials is null) ? null : otherCredentials.getCredentialsStruct(), &err);
217 		
218 		if (err !is null)
219 		{
220 			throw new GException( new ErrorG(err) );
221 		}
222 		
223 		return p;
224 	}
225 	
226 	/**
227 	 * Tries to get the UNIX user identifier from credentials. This
228 	 * method is only available on UNIX platforms.
229 	 * This operation can fail if GCredentials is not supported on the
230 	 * OS or if the native credentials type does not contain information
231 	 * about the UNIX user.
232 	 * Since 2.26
233 	 * Returns: The UNIX user identifier or -1 if error is set.
234 	 * Throws: GException on failure.
235 	 */
236 	public uid_t getUnixUser()
237 	{
238 		// uid_t g_credentials_get_unix_user (GCredentials *credentials,  GError **error);
239 		GError* err = null;
240 		
241 		auto p = g_credentials_get_unix_user(gCredentials, &err);
242 		
243 		if (err !is null)
244 		{
245 			throw new GException( new ErrorG(err) );
246 		}
247 		
248 		return p;
249 	}
250 	
251 	/**
252 	 * Tries to set the UNIX user identifier on credentials. This method
253 	 * is only available on UNIX platforms.
254 	 * This operation can fail if GCredentials is not supported on the
255 	 * OS or if the native credentials type does not contain information
256 	 * about the UNIX user.
257 	 * Since 2.26
258 	 * Params:
259 	 * uid = The UNIX user identifier to set.
260 	 * Returns: TRUE if uid was set, FALSE if error is set.
261 	 * Throws: GException on failure.
262 	 */
263 	public int setUnixUser(uid_t uid)
264 	{
265 		// gboolean g_credentials_set_unix_user (GCredentials *credentials,  uid_t uid,  GError **error);
266 		GError* err = null;
267 		
268 		auto p = g_credentials_set_unix_user(gCredentials, uid, &err);
269 		
270 		if (err !is null)
271 		{
272 			throw new GException( new ErrorG(err) );
273 		}
274 		
275 		return p;
276 	}
277 	
278 	/**
279 	 * Tries to get the UNIX process identifier from credentials. This
280 	 * method is only available on UNIX platforms.
281 	 * This operation can fail if GCredentials is not supported on the
282 	 * OS or if the native credentials type does not contain information
283 	 * about the UNIX process ID.
284 	 * Since 2.36
285 	 * Returns: The UNIX process ID, or -1 if error is set.
286 	 * Throws: GException on failure.
287 	 */
288 	public pid_t getUnixPid()
289 	{
290 		// pid_t g_credentials_get_unix_pid (GCredentials *credentials,  GError **error);
291 		GError* err = null;
292 		
293 		auto p = g_credentials_get_unix_pid(gCredentials, &err);
294 		
295 		if (err !is null)
296 		{
297 			throw new GException( new ErrorG(err) );
298 		}
299 		
300 		return p;
301 	}
302 }