Release 1.25.0 -- Buddy Idle Time, RTF
[siplcs.git] / src / telepathy / telepathy-protocol.c
blobf6e533785388f06baeaebab895cb8dfb00999751
1 /**
2 * @file telepathy-protocol.c
4 * pidgin-sipe
6 * Copyright (C) 2012-2017 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/simple-password-manager.h>
34 #include <telepathy-glib/telepathy-glib.h>
36 #include "sipe-backend.h"
37 #include "sipe-common.h"
38 #include "sipe-core.h"
39 #include "sipe-nls.h"
41 #include "telepathy-private.h"
43 G_BEGIN_DECLS
45 * Protocol class - data structures
47 typedef struct _SipeProtocolClass {
48 TpBaseProtocolClass parent_class;
49 } SipeProtocolClass;
51 typedef struct _SipeProtocol {
52 TpBaseProtocol parent;
53 } SipeProtocol;
56 * Protocol class - type macros
58 static GType sipe_protocol_get_type(void) G_GNUC_CONST;
59 #define SIPE_TYPE_PROTOCOL \
60 (sipe_protocol_get_type())
61 #define SIPE_PROTOCOL(obj) \
62 (G_TYPE_CHECK_INSTANCE_CAST((obj), SIPE_TYPE_PROTOCOL, \
63 SipeProtocol))
64 G_END_DECLS
67 * Protocol class - type definition
69 G_DEFINE_TYPE(SipeProtocol,
70 sipe_protocol,
71 TP_TYPE_BASE_PROTOCOL)
74 * Protocol class - instance methods
77 * @TODO: parameter filtering doesn't seem to work: these functions aren't
78 * called at all - why?
80 static gboolean parameter_filter_account(SIPE_UNUSED_PARAMETER const TpCMParamSpec *paramspec,
81 GValue *value,
82 GError **error)
84 const gchar *str = g_value_get_string(value);
86 if ((str == NULL) ||
87 (strchr(str, '@') == NULL)) {
88 g_set_error(error, TP_ERROR, TP_ERROR_INVALID_HANDLE,
89 _("User name should be a valid SIP URI\nExample: user@company.com"));
90 return(FALSE);
92 return(TRUE);
95 static const TpCMParamSpec *get_parameters(SIPE_UNUSED_PARAMETER TpBaseProtocol *self)
97 /* ISO C99 Designated Initializers silences -Wmissing-field-initializers */
98 #define SIPE_PROTOCOL_PARAMETER(_name, _dtype, _gtype, _flags, _default, _filter) \
99 { \
100 .name = (_name), \
101 .dtype = (_dtype), \
102 .gtype = (_gtype), \
103 .flags = (_flags), \
104 .def = (_default), \
105 .offset = 0, \
106 .filter = (_filter), \
107 .filter_data = NULL, \
108 .setter_data = NULL, \
111 static const TpCMParamSpec sipe_parameters[] = {
112 SIPE_PROTOCOL_PARAMETER("account",
113 DBUS_TYPE_STRING_AS_STRING,
114 G_TYPE_STRING,
115 TP_CONN_MGR_PARAM_FLAG_REQUIRED,
116 NULL,
117 parameter_filter_account),
118 SIPE_PROTOCOL_PARAMETER("login",
119 DBUS_TYPE_STRING_AS_STRING,
120 G_TYPE_STRING,
122 NULL,
123 NULL /* can be empty */),
124 SIPE_PROTOCOL_PARAMETER("password",
125 DBUS_TYPE_STRING_AS_STRING,
126 G_TYPE_STRING,
127 TP_CONN_MGR_PARAM_FLAG_SECRET,
128 NULL,
129 NULL /* can be empty */),
130 SIPE_PROTOCOL_PARAMETER("server",
131 DBUS_TYPE_STRING_AS_STRING,
132 G_TYPE_STRING,
134 NULL,
135 NULL /* can be empty */),
136 SIPE_PROTOCOL_PARAMETER("port",
137 DBUS_TYPE_UINT16_AS_STRING,
138 G_TYPE_UINT,
139 TP_CONN_MGR_PARAM_FLAG_HAS_DEFAULT,
140 GUINT_TO_POINTER(0),
141 NULL),
142 /* @TODO: this should be combo auto/ssl/tcp */
143 SIPE_PROTOCOL_PARAMETER("transport",
144 DBUS_TYPE_STRING_AS_STRING,
145 G_TYPE_STRING,
146 TP_CONN_MGR_PARAM_FLAG_HAS_DEFAULT,
147 "auto",
148 tp_cm_param_filter_string_nonempty),
149 SIPE_PROTOCOL_PARAMETER("useragent",
150 DBUS_TYPE_STRING_AS_STRING,
151 G_TYPE_STRING,
153 NULL,
154 NULL /* can be empty */),
155 /* @TODO: this should be combo auto/ntlm/krb5/tls-dsk */
156 SIPE_PROTOCOL_PARAMETER("authentication",
157 DBUS_TYPE_STRING_AS_STRING,
158 G_TYPE_STRING,
159 TP_CONN_MGR_PARAM_FLAG_HAS_DEFAULT,
160 "auto",
161 tp_cm_param_filter_string_nonempty),
162 SIPE_PROTOCOL_PARAMETER("single-sign-on",
163 DBUS_TYPE_BOOLEAN_AS_STRING,
164 G_TYPE_BOOLEAN,
165 TP_CONN_MGR_PARAM_FLAG_HAS_DEFAULT,
166 GINT_TO_POINTER(FALSE),
167 NULL),
168 SIPE_PROTOCOL_PARAMETER("don't-publish-calendar",
169 DBUS_TYPE_BOOLEAN_AS_STRING,
170 G_TYPE_BOOLEAN,
171 TP_CONN_MGR_PARAM_FLAG_HAS_DEFAULT,
172 GINT_TO_POINTER(FALSE),
173 NULL),
174 SIPE_PROTOCOL_PARAMETER("allow-web-photo",
175 DBUS_TYPE_BOOLEAN_AS_STRING,
176 G_TYPE_BOOLEAN,
177 TP_CONN_MGR_PARAM_FLAG_HAS_DEFAULT,
178 GINT_TO_POINTER(FALSE),
179 NULL),
180 SIPE_PROTOCOL_PARAMETER(NULL, NULL, 0, 0, NULL, NULL)
183 return(sipe_parameters);
186 /* non-static, because it is re-used by connection object */
187 gchar *sipe_telepathy_protocol_normalize_contact(SIPE_UNUSED_PARAMETER TpBaseProtocol *self,
188 const gchar *contact,
189 GError **error)
191 gchar *uri = sip_uri_if_valid(contact);
193 SIPE_DEBUG_INFO_NOFORMAT("SipeProtocol::normalize_contact");
195 if (!uri)
196 g_set_error(error, TP_ERROR, TP_ERROR_INVALID_HANDLE,
197 _("User name should be a valid SIP URI\nExample: user@company.com"));
198 return(uri);
201 static gchar *identify_account(SIPE_UNUSED_PARAMETER TpBaseProtocol *self,
202 GHashTable *asv,
203 SIPE_UNUSED_PARAMETER GError **error)
205 SIPE_DEBUG_INFO_NOFORMAT("SipeProtocol::identify_account");
207 return(g_strdup(tp_asv_get_string(asv, "account")));
210 static GStrv get_interfaces(SIPE_UNUSED_PARAMETER TpBaseProtocol *base)
212 SIPE_DEBUG_INFO_NOFORMAT("SipeProtocol::get_interfaces");
214 return(g_new0(gchar *, 1));
217 static void get_connection_details(SIPE_UNUSED_PARAMETER TpBaseProtocol *self,
218 GStrv *connection_interfaces,
219 GType **channel_managers,
220 gchar **icon_name,
221 gchar **english_name,
222 gchar **vcard_field)
224 SIPE_DEBUG_INFO_NOFORMAT("SipeProtocol::get_connection_details");
226 if (connection_interfaces) {
227 static const gchar * const interfaces[] = {
228 /* @TODO */
229 NULL
231 *connection_interfaces = g_strdupv((GStrv) interfaces);
233 if (channel_managers) {
234 GType types[] = {
235 /* @TODO */
236 TP_TYPE_SIMPLE_PASSWORD_MANAGER,
237 SIPE_TYPE_SEARCH_MANAGER,
238 G_TYPE_INVALID
240 *channel_managers = g_memdup(types, sizeof(types));
242 if (icon_name)
243 *icon_name = g_strdup("im-" SIPE_TELEPATHY_DOMAIN);
244 if (english_name)
245 *english_name = g_strdup("Office Communicator");
246 if (vcard_field)
247 *vcard_field = g_strdup("x-" SIPE_TELEPATHY_DOMAIN);
250 static GStrv dup_authentication_types(SIPE_UNUSED_PARAMETER TpBaseProtocol *self)
252 static const gchar * const types[] = {
253 /* @TODO */
254 NULL
257 SIPE_DEBUG_INFO_NOFORMAT("SipeProtocol::dup_authentication_types");
259 return(g_strdupv((GStrv) types));
263 * Protocol class - type implementation
265 static void sipe_protocol_class_init(SipeProtocolClass *klass)
267 TpBaseProtocolClass *base_class = TP_BASE_PROTOCOL_CLASS(klass);
269 SIPE_DEBUG_INFO_NOFORMAT("SipeProtocol::class_init");
271 base_class->get_parameters = get_parameters;
272 base_class->new_connection = sipe_telepathy_connection_new;
273 base_class->normalize_contact = sipe_telepathy_protocol_normalize_contact;
274 base_class->identify_account = identify_account;
275 base_class->get_interfaces = get_interfaces;
276 base_class->get_connection_details = get_connection_details;
277 base_class->dup_authentication_types = dup_authentication_types;
280 static void sipe_protocol_init(SIPE_UNUSED_PARAMETER SipeProtocol *self)
282 SIPE_DEBUG_INFO_NOFORMAT("SipeProtocol::init");
285 /* add protocol to connection manager */
286 void sipe_telepathy_protocol_init(TpBaseConnectionManager *cm)
288 TpBaseProtocol *protocol = g_object_new(SIPE_TYPE_PROTOCOL,
289 "name", SIPE_TELEPATHY_DOMAIN,
290 NULL);
291 tp_base_connection_manager_add_protocol(cm, protocol);
292 g_object_unref(protocol);
297 Local Variables:
298 mode: c
299 c-file-style: "bsd"
300 indent-tabs-mode: t
301 tab-width: 8
302 End: