2 * @file telepathy-protocol.c
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
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"
39 #include "telepathy-private.h"
43 * Protocol class - data structures
45 typedef struct _SipeProtocolClass
{
46 TpBaseProtocolClass parent_class
;
49 typedef struct _SipeProtocol
{
50 TpBaseProtocol parent
;
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, \
62 #define SIPE_PROTOCOL_CLASS(klass) \
63 (G_TYPE_CHECK_CLASS_CAST((klass), SIPE_TYPE_PROTOCOL, \
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, \
75 * Protocol class - type definition
77 G_DEFINE_TYPE(SipeProtocol
,
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
,
92 const gchar
*str
= g_value_get_string(value
);
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"));
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) \
113 .filter = (_filter), \
116 static const TpCMParamSpec
const sipe_parameters
[] = {
117 SIPE_PROTOCOL_PARAMETER("account",
118 DBUS_TYPE_STRING_AS_STRING
,
120 TP_CONN_MGR_PARAM_FLAG_REQUIRED
| TP_CONN_MGR_PARAM_FLAG_REGISTER
,
122 parameter_filter_account
),
123 SIPE_PROTOCOL_PARAMETER("login",
124 DBUS_TYPE_STRING_AS_STRING
,
126 TP_CONN_MGR_PARAM_FLAG_REQUIRED
| TP_CONN_MGR_PARAM_FLAG_REGISTER
,
128 tp_cm_param_filter_string_nonempty
),
129 SIPE_PROTOCOL_PARAMETER("password",
130 DBUS_TYPE_STRING_AS_STRING
,
132 TP_CONN_MGR_PARAM_FLAG_REQUIRED
| TP_CONN_MGR_PARAM_FLAG_REGISTER
| TP_CONN_MGR_PARAM_FLAG_SECRET
,
134 tp_cm_param_filter_string_nonempty
),
135 SIPE_PROTOCOL_PARAMETER("server",
136 DBUS_TYPE_STRING_AS_STRING
,
140 NULL
/* can be empty */),
141 SIPE_PROTOCOL_PARAMETER("port",
142 DBUS_TYPE_UINT16_AS_STRING
,
144 TP_CONN_MGR_PARAM_FLAG_HAS_DEFAULT
,
147 /* @TODO: this should be combo auto/ssl/tcp */
148 SIPE_PROTOCOL_PARAMETER("transport",
149 DBUS_TYPE_STRING_AS_STRING
,
151 TP_CONN_MGR_PARAM_FLAG_HAS_DEFAULT
,
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
,
165 gchar
*uri
= sip_uri_if_valid(contact
);
167 SIPE_DEBUG_INFO_NOFORMAT("SipeProtocol::normalize_contact");
170 g_set_error(error
, TP_ERROR
, TP_ERROR_INVALID_HANDLE
,
171 _("User name should be a valid SIP URI\nExample: user@company.com"));
175 static gchar
*identify_account(SIPE_UNUSED_PARAMETER TpBaseProtocol
*self
,
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
,
195 gchar
**english_name
,
198 SIPE_DEBUG_INFO_NOFORMAT("SipeProtocol::get_connection_details");
200 if (connection_interfaces
) {
201 static const gchar
* const interfaces
[] = {
205 *connection_interfaces
= g_strdupv((GStrv
) interfaces
);
207 if (channel_managers
) {
208 static const GType
const types
[] = {
212 *channel_managers
= g_memdup(types
, sizeof(types
));
215 *icon_name
= g_strdup("im-" SIPE_TELEPATHY_DOMAIN
);
217 *english_name
= g_strdup("Office Communicator");
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
[] = {
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
,
263 tp_base_connection_manager_add_protocol(cm
, protocol
);
264 g_object_unref(protocol
);