telepathy: don't copy parameters as properties
[siplcs.git] / src / telepathy / telepathy-protocol.c
blobacb18ea97238b18f6dac85ed30ddad2bf7c7a461
1 /**
2 * @file telepathy-protocol.c
4 * pidgin-sipe
6 * Copyright (C) 2012 SIPE Project <http://sipe.sourceforge.net/>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
27 #include <string.h>
29 #include <dbus/dbus-protocol.h>
30 #include <glib-object.h>
31 #include <telepathy-glib/base-connection-manager.h>
32 #include <telepathy-glib/base-protocol.h>
33 #include <telepathy-glib/telepathy-glib.h>
35 #include "sipe-backend.h"
36 #include "sipe-common.h"
37 #include "sipe-core.h"
38 #include "sipe-nls.h"
39 #include "telepathy-private.h"
41 G_BEGIN_DECLS
43 * Protocol class - data structures
45 typedef struct _SipeProtocolClass {
46 TpBaseProtocolClass parent_class;
47 } SipeProtocolClass;
49 typedef struct _SipeProtocol {
50 TpBaseProtocol parent;
51 } SipeProtocol;
54 * Protocol class - type macros
56 static GType sipe_protocol_get_type(void) G_GNUC_CONST;
57 #define SIPE_TYPE_PROTOCOL \
58 (sipe_protocol_get_type())
59 #define SIPE_PROTOCOL(obj) \
60 (G_TYPE_CHECK_INSTANCE_CAST((obj), SIPE_TYPE_PROTOCOL, \
61 SipeProtocol))
62 #define SIPE_PROTOCOL_CLASS(klass) \
63 (G_TYPE_CHECK_CLASS_CAST((klass), SIPE_TYPE_PROTOCOL, \
64 SipeProtocolClass))
65 #define SIPE_IS_PROTOCOL(obj) \
66 (G_TYPE_CHECK_INSTANCE_TYPE((obj), SIPE_TYPE_PROTOCOL))
67 #define SIPE_IS_PROTOCOL_CLASS(klass) \
68 (G_TYPE_CHECK_CLASS_TYPE((klass), SIPE_TYPE_PROTOCOL))
69 #define SIPE_PROTOCOL_GET_CLASS(obj) \
70 (G_TYPE_INSTANCE_GET_CLASS((obj), SIPE_TYPE_PROTOCOL, \
71 SipeProtocolClass))
72 G_END_DECLS
75 * Protocol class - type definition
77 G_DEFINE_TYPE(SipeProtocol,
78 sipe_protocol,
79 TP_TYPE_BASE_PROTOCOL)
82 * Protocol class - instance methods
85 * @TODO: parameter filtering doesn't seem to work: these functions aren't
86 * called at all - why?
88 static gboolean parameter_filter_account(SIPE_UNUSED_PARAMETER const TpCMParamSpec *paramspec,
89 GValue *value,
90 GError **error)
92 const gchar *str = g_value_get_string(value);
94 if ((str == NULL) ||
95 (strchr(str, '@') == NULL)) {
96 g_set_error(error, TP_ERROR, TP_ERROR_INVALID_HANDLE,
97 _("User name should be a valid SIP URI\nExample: user@company.com"));
98 return(FALSE);
100 return(TRUE);
103 static const TpCMParamSpec *get_parameters(SIPE_UNUSED_PARAMETER TpBaseProtocol *self)
105 /* ISO C99 Designated Initializers silences -Wmissing-field-initializers */
106 #define SIPE_PROTOCOL_PARAMETER(_name, _dtype, _gtype, _flags, _default, _filter) \
108 .name = (_name), \
109 .dtype = (_dtype), \
110 .gtype = (_gtype), \
111 .flags = (_flags), \
112 .def = (_default), \
113 .filter = (_filter), \
116 static const TpCMParamSpec const sipe_parameters[] = {
117 SIPE_PROTOCOL_PARAMETER("account",
118 DBUS_TYPE_STRING_AS_STRING,
119 G_TYPE_STRING,
120 TP_CONN_MGR_PARAM_FLAG_REQUIRED | TP_CONN_MGR_PARAM_FLAG_REGISTER,
121 NULL,
122 parameter_filter_account),
123 SIPE_PROTOCOL_PARAMETER("login",
124 DBUS_TYPE_STRING_AS_STRING,
125 G_TYPE_STRING,
126 TP_CONN_MGR_PARAM_FLAG_REQUIRED | TP_CONN_MGR_PARAM_FLAG_REGISTER,
127 NULL,
128 tp_cm_param_filter_string_nonempty),
129 SIPE_PROTOCOL_PARAMETER("password",
130 DBUS_TYPE_STRING_AS_STRING,
131 G_TYPE_STRING,
132 TP_CONN_MGR_PARAM_FLAG_REQUIRED | TP_CONN_MGR_PARAM_FLAG_REGISTER | TP_CONN_MGR_PARAM_FLAG_SECRET,
133 NULL,
134 tp_cm_param_filter_string_nonempty),
135 SIPE_PROTOCOL_PARAMETER("server",
136 DBUS_TYPE_STRING_AS_STRING,
137 G_TYPE_STRING,
139 NULL,
140 NULL /* can be empty */),
141 SIPE_PROTOCOL_PARAMETER("port",
142 DBUS_TYPE_UINT16_AS_STRING,
143 G_TYPE_UINT,
144 TP_CONN_MGR_PARAM_FLAG_HAS_DEFAULT,
145 GUINT_TO_POINTER(0),
146 NULL),
147 /* @TODO: this should be combo auto/ssl/tcp */
148 SIPE_PROTOCOL_PARAMETER("transport",
149 DBUS_TYPE_STRING_AS_STRING,
150 G_TYPE_STRING,
151 TP_CONN_MGR_PARAM_FLAG_HAS_DEFAULT,
152 "auto",
153 tp_cm_param_filter_string_nonempty),
154 SIPE_PROTOCOL_PARAMETER(NULL, NULL, 0, 0, NULL, NULL)
157 return(sipe_parameters);
160 /* non-static, because it is re-used by connection object */
161 gchar *sipe_telepathy_protocol_normalize_contact(SIPE_UNUSED_PARAMETER TpBaseProtocol *self,
162 const gchar *contact,
163 GError **error)
165 gchar *uri = sip_uri_if_valid(contact);
167 SIPE_DEBUG_INFO_NOFORMAT("SipeProtocol::normalize_contact");
169 if (!uri)
170 g_set_error(error, TP_ERROR, TP_ERROR_INVALID_HANDLE,
171 _("User name should be a valid SIP URI\nExample: user@company.com"));
172 return(uri);
175 static gchar *identify_account(SIPE_UNUSED_PARAMETER TpBaseProtocol *self,
176 GHashTable *asv,
177 SIPE_UNUSED_PARAMETER GError **error)
179 SIPE_DEBUG_INFO_NOFORMAT("SipeProtocol::identify_account");
181 return(g_strdup(tp_asv_get_string(asv, "account")));
184 static GStrv get_interfaces(SIPE_UNUSED_PARAMETER TpBaseProtocol *base)
186 SIPE_DEBUG_INFO_NOFORMAT("SipeProtocol::get_interfaces");
188 return(g_new0(gchar *, 1));
191 static void get_connection_details(SIPE_UNUSED_PARAMETER TpBaseProtocol *self,
192 GStrv *connection_interfaces,
193 GType **channel_managers,
194 gchar **icon_name,
195 gchar **english_name,
196 gchar **vcard_field)
198 SIPE_DEBUG_INFO_NOFORMAT("SipeProtocol::get_connection_details");
200 if (connection_interfaces) {
201 static const gchar * const interfaces[] = {
202 /* @TODO */
203 NULL
205 *connection_interfaces = g_strdupv((GStrv) interfaces);
207 if (channel_managers) {
208 static const GType const types[] = {
209 /* @TODO */
210 G_TYPE_INVALID
212 *channel_managers = g_memdup(types, sizeof(types));
214 if (icon_name)
215 *icon_name = g_strdup("im-" SIPE_TELEPATHY_DOMAIN);
216 if (english_name)
217 *english_name = g_strdup("Office Communicator");
218 if (vcard_field)
219 *vcard_field = g_strdup("x-" SIPE_TELEPATHY_DOMAIN);
222 static GStrv dup_authentication_types(SIPE_UNUSED_PARAMETER TpBaseProtocol *self)
224 static const gchar * const types[] = {
225 /* @TODO */
226 NULL
229 SIPE_DEBUG_INFO_NOFORMAT("SipeProtocol::dup_authentication_types");
231 return(g_strdupv((GStrv) types));
235 * Protocol class - type implementation
237 static void sipe_protocol_class_init(SipeProtocolClass *klass)
239 TpBaseProtocolClass *base_class = (TpBaseProtocolClass *) klass;
241 SIPE_DEBUG_INFO_NOFORMAT("SipeProtocol::class_init");
243 base_class->get_parameters = get_parameters;
244 base_class->new_connection = sipe_telepathy_connection_new;
245 base_class->normalize_contact = sipe_telepathy_protocol_normalize_contact;
246 base_class->identify_account = identify_account;
247 base_class->get_interfaces = get_interfaces;
248 base_class->get_connection_details = get_connection_details;
249 base_class->dup_authentication_types = dup_authentication_types;
252 static void sipe_protocol_init(SIPE_UNUSED_PARAMETER SipeProtocol *self)
254 SIPE_DEBUG_INFO_NOFORMAT("SipeProtocol::init");
257 /* add protocol to connection manager */
258 void sipe_telepathy_protocol_init(TpBaseConnectionManager *cm)
260 TpBaseProtocol *protocol = g_object_new(SIPE_TYPE_PROTOCOL,
261 "name", SIPE_TELEPATHY_DOMAIN,
262 NULL);
263 tp_base_connection_manager_add_protocol(cm, protocol);
264 g_object_unref(protocol);
269 Local Variables:
270 mode: c
271 c-file-style: "bsd"
272 indent-tabs-mode: t
273 tab-width: 8
274 End: