Move the tlm dbus interface under org.01
[platform/core/system/tlm.git] / src / common / tlm-account-plugin.c
1 /* vi: set et sw=4 ts=4 cino=t0,(0: */
2 /* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 /*
4  * This file is part of tlm (Tiny Login Manager)
5  *
6  * Copyright (C) 2013 Intel Corporation.
7  *
8  * Contact: Amarnath Valluri <amarnath.valluri@linux.intel.com>
9  *
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 2.1 of the License, or (at your option) any later version.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with this library; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
23  * 02110-1301 USA
24  */
25
26 #include "tlm-account-plugin.h"
27
28 /**
29  * SECTION:tlm-account-plugin
30  * @short_description: an interface for implementing tlm account plugins
31  * @include: tlm-account-plugin.h
32  *
33  * #TlmAccountPlugin is an interface for implementing tlm account plugins.
34  *
35  * <refsect1><title>The plugin API</title></refsect1>
36  *
37  * Tlm account plugins provide an API for system-specific account operations:
38  * setting up and cleaning up guest user account, and checking username validity.
39  * They should implement the plugin interface specified here.
40  *
41  * <refsect1><title>Example plugins</title></refsect1>
42  *
43  * See example plugin implementation here:
44  * <ulink url="https://github.com/01org/tlm/tree/master/src/plugins/default">
45  * https://github.com/01org/tlm/tree/master/src/plugins/default</ulink> and here:
46  * <ulink url="https://github.com/01org/tlm/tree/master/src/plugins/gumd">
47  * https://github.com/01org/tlm/tree/master/src/plugins/gumd</ulink>.
48  *
49  */
50
51
52 /**
53  * TlmAccountPluginInterface:
54  * @parent: parent interface type.
55  * @setup_guest_user_account: implementation of tlm_account_plugin_setup_guest_user_account()
56  * @is_valid_user: implementation of tlm_account_plugin_is_valid_user()
57  * @cleanup_guest_user: implementation of tlm_account_plugin_cleanup_guest_user()
58  *
59  * #TlmAccountPluginInterface interface containing pointers to methods that all
60  * plugin implementations should provide.
61  */
62
63 /**
64  * TlmAccountPlugin:
65  *
66  * Opaque #TlmAccountPlugin data structure.
67  */
68 G_DEFINE_INTERFACE (TlmAccountPlugin, tlm_account_plugin, 0)
69
70 static void
71 tlm_account_plugin_default_init (TlmAccountPluginInterface *g_class)
72 {
73     /**
74      * TlmAccountPlugin:config:
75      * 
76      * This property holds a list of key-value pairs of plugin configuration
77      * taken from tlm.conf configuration file.
78      */
79     g_object_interface_install_property (g_class, g_param_spec_boxed (
80             "config", "Config", "Config parameters",
81             G_TYPE_HASH_TABLE, G_PARAM_CONSTRUCT_ONLY 
82                 | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
83 }
84
85 /**
86  * tlm_account_plugin_setup_guest_user_account
87  * @self: plugin instance
88  * @user_name: the user name
89  *
90  * This method creates and sets up a guest user account with a provided
91  * @user_name.
92  *
93  * Returns: whether the operation succeeded.
94  */
95 gboolean
96 tlm_account_plugin_setup_guest_user_account (TlmAccountPlugin   *self,
97                                      const gchar *user_name)
98 {
99     g_return_val_if_fail(self && TLM_IS_PLUGIN (self), FALSE);
100     g_return_val_if_fail(
101         TLM_ACCOUNT_PLUGIN_GET_IFACE(self)->setup_guest_user_account, FALSE);
102     
103     return TLM_ACCOUNT_PLUGIN_GET_IFACE (self)->setup_guest_user_account (
104                     self, user_name);
105 }
106
107
108 /**
109  * tlm_account_plugin_is_valid_user:
110  * @self: plugin instance
111  * @user_name: user name to check
112  *
113  * Checks if the user with a given @user_name exists.
114  */
115 gboolean
116 tlm_account_plugin_is_valid_user (TlmAccountPlugin   *self,
117                                   const gchar *user_name)
118 {
119     g_return_val_if_fail (self && TLM_IS_PLUGIN (self), FALSE);
120     g_return_val_if_fail (TLM_ACCOUNT_PLUGIN_GET_IFACE(self)->is_valid_user,
121                           FALSE);
122
123     return TLM_ACCOUNT_PLUGIN_GET_IFACE(self)->is_valid_user (self, user_name);
124 }
125
126 /**
127  * tlm_account_plugin_cleanup_guest_user:
128  * @self: plugin instance
129  * @user_name: user name to clean up
130  * @delete_account: whether the user account should be deleted
131  *
132  * When a guest user logs out, this method is called. It should clean up the
133  * home directory of the user, and, if delete_user is set, delete the user
134  * account.
135  */
136 gboolean
137 tlm_account_plugin_cleanup_guest_user (TlmAccountPlugin   *self,
138                                        const gchar *user_name,
139                                        gboolean     delete_account)
140 {
141     g_return_val_if_fail(self && TLM_IS_PLUGIN (self), FALSE);
142     g_return_val_if_fail(TLM_ACCOUNT_PLUGIN_GET_IFACE(self)->cleanup_guest_user,
143                          FALSE);
144
145     return TLM_ACCOUNT_PLUGIN_GET_IFACE (self)->cleanup_guest_user (
146                     self, user_name, delete_account);
147 }
148