6 * Copyright (C) 2010-2015 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 * Some notes on the history of this project/code/copyrights:
25 * - the project is called SIPE, but originally the code was only written
26 * for the libpurple framework, i.e. Pidgin. Hence the package name is
29 * - in the beginning almost all of the code was located in a module
30 * called "sipe.c". During the effort to remove the libpurple
31 * dependencies from the SIPE core, thousands of lines of code got
32 * shifted out of sipe.c, mostly to newly created modules and sipe.c
35 * - it would have been tedious to track down the original author or
36 * copyright and preserve them for each line of code that was moved.
37 * Therefore the new modules started with a fresh copyright notice
38 * (like the one above).
40 * - the original copyright notices from sipe.c have been moved to this
41 * file (see below) and *MUST* be preserved!
43 * - if necessary the author of a line of code in question can still be
44 * reconstructed from the git repository information.
45 * See also "man git-blame"
47 * - if you think your copyright should be restored for a piece of code,
48 * then please contact the SIPE project to fix the source files ASAP.
50 *------------------- Copyright notices from "sipe.c" ---------------
51 * Copyright (C) 2010-11 SIPE Project <http://sipe.sourceforge.net/>
52 * Copyright (C) 2009-10 pier11 <pier11@operamail.com>
53 * Copyright (C) 2008 Novell, Inc.
54 * Copyright (C) 2007-09 Anibal Avelar <debianmx@gmail.com>
55 * Copyright (C) 2005 Thomas Butter <butter@uni-mannheim.de>
58 * Thanks to Google's Summer of Code Program and the helpful mentors
60 *------------------- Copyright notices from "sipe.c" ---------------
72 #include "sipe-common.h"
75 #include "sip-transport.h"
76 #include "sipe-backend.h"
77 #include "sipe-buddy.h"
79 #include "sipe-certificate.h"
80 #include "sipe-chat.h"
81 #include "sipe-conf.h"
82 #include "sipe-core.h"
83 #include "sipe-core-private.h"
84 #include "sipe-crypt.h"
85 #include "sipe-ews-autodiscover.h"
86 #include "sipe-group.h"
87 #include "sipe-groupchat.h"
88 #include "sipe-http.h"
89 #include "sipe-media.h"
90 #include "sipe-mime.h"
92 #include "sipe-ocs2007.h"
93 #include "sipe-schedule.h"
94 #include "sipe-session.h"
95 #include "sipe-status.h"
96 #include "sipe-subscriptions.h"
99 #include "sipe-utils.h"
100 #include "sipe-webticket.h"
102 #ifdef PACKAGE_GIT_COMMIT
103 #define SIPE_CORE_VERSION PACKAGE_VERSION " (git commit " PACKAGE_GIT_COMMIT ")"
105 #define SIPE_CORE_VERSION PACKAGE_VERSION
108 /* locale_dir is unused if ENABLE_NLS is not defined */
109 void sipe_core_init(SIPE_UNUSED_PARAMETER
const char *locale_dir
)
115 SIPE_DEBUG_INFO("bindtextdomain = %s",
116 bindtextdomain(PACKAGE_NAME
, locale_dir
));
117 SIPE_DEBUG_INFO("bind_textdomain_codeset = %s",
118 bind_textdomain_codeset(PACKAGE_NAME
, "UTF-8"));
119 textdomain(PACKAGE_NAME
);
121 /* Initialization for crypto backend (production mode) */
122 sipe_crypto_init(TRUE
);
127 void sipe_core_destroy(void)
130 sipe_status_shutdown();
131 sipe_mime_shutdown();
132 sipe_crypto_shutdown();
136 gchar
*sipe_core_about(void)
138 return g_strdup_printf(
140 * Non-translatable parts, like markup, are hard-coded
141 * into the format string. This requires more translatable
142 * texts but it makes the translations less error prone.
144 "<b><font size=\"+1\">SIPE " SIPE_CORE_VERSION
" </font></b><br/>"
147 " - Skype for Business<br/>"
148 " - Microsoft Office 365<br/>"
149 " - Microsoft Business Productivity Online Suite (BPOS)<br/>"
150 " - Microsoft Lync Server<br/>"
151 " - Microsoft Office Communications Server 2007 R2<br/>"
152 " - Microsoft Office Communications Server 2007<br/>"
153 " - Microsoft Live Communications Server 2005<br/>"
154 " - Microsoft Live Communications Server 2003<br/>"
155 " - Reuters Messaging<br/>"
157 /* 2 */ "%s: <a href=\"" PACKAGE_URL
"\">" PACKAGE_URL
"</a><br/>"
158 /* 3,4 */ "%s: <a href=\"http://sourceforge.net/p/sipe/discussion/688534/\">%s</a><br/>"
159 /* 5,6 */ "%s: <a href=\"" PACKAGE_BUGREPORT
"\">%s</a><br/>"
160 /* 7 */ "%s: <a href=\"" SIPE_TRANSLATIONS_URL
"\">Transifex.com</a><br/>"
161 /* 8 */ "%s: GPLv2+<br/>"
164 /* 10,11 */ "%s<a href=\"" SIPE_TRANSLATIONS_URL
"\">Transifex.com</a>%s.<br/>"
166 /* 12 */ "<b>%s:</b><br/>"
167 " - Stefan Becker<br/>"
169 " - Jochen De Smet (retired, Miranda port)<br/>"
170 " - Michael Lamb (retired, Adium port)<br/>"
171 " - Anibal Avelar (retired)<br/>"
172 " - Gabriel Burt (retired)<br/>"
173 " - pier11 (retired)<br/>"
174 " - Tomáš Hrabčík (retired)<br/>"
178 /* The next 13 texts make up the SIPE about note text */
179 /* About note, part 1/13: introduction */
180 _("A third-party plugin implementing extended version of SIP/SIMPLE used by various products"),
181 /* About note, part 2/13: home page URL (label) */
183 /* About note, part 3/13: support forum URL (label) */
185 /* About note, part 4/13: support forum name (hyperlink text) */
187 /* About note, part 5/13: bug tracker URL (label) */
188 _("Report Problems"),
189 /* About note, part 6/13: bug tracker URL (hyperlink text) */
191 /* About note, part 7/13: translation service URL (label) */
193 /* About note, part 8/13: license type (label) */
195 /* About note, part 9/13: (REMOVED) */
196 /* About note, part 10/13: translation request, text before Transifex.com URL */
197 /* append a space if text is not empty */
198 _("Please help us to translate SIPE to your native language here at "),
199 /* About note, part 11/13: translation request, text after Transifex.com URL */
200 /* start with a space if text is not empty */
201 _(" using convenient web interface"),
202 /* About note, part 12/13: author list (header) */
204 /* About note, part 13/13: Localization credit */
205 /* PLEASE NOTE: do *NOT* simply translate the english original */
206 /* but write something similar to the following sentence: */
207 /* "Localization for <language name> (<language code>): <name>" */
208 _("Original texts in English (en): SIPE developers")
212 struct sipe_core_public
*sipe_core_allocate(const gchar
*signin_name
,
214 const gchar
*login_account
,
215 const gchar
*password
,
217 const gchar
*email_url
,
218 const gchar
**errmsg
)
220 struct sipe_core_private
*sipe_private
;
223 SIPE_DEBUG_INFO("sipe_core_allocate: SIPE version " SIPE_CORE_VERSION
" signin_name '%s'", signin_name
);
225 /* ensure that sign-in name doesn't contain invalid characters */
226 if (strpbrk(signin_name
, "\t\v\r\n") != NULL
) {
227 *errmsg
= _("SIP Exchange user name contains invalid characters");
231 /* ensure that sign-in name format is name@domain */
232 if (!strchr(signin_name
, '@') ||
233 g_str_has_prefix(signin_name
, "@") ||
234 g_str_has_suffix(signin_name
, "@")) {
235 *errmsg
= _("User name should be a valid SIP URI\nExample: user@company.com");
240 /* ensure that Password is valid when SSO is not selected */
241 if (!sso
&& is_empty(password
)) {
242 *errmsg
= _("Password is required when Single Sign-On is not enabled");
246 /* ensure that email format is name@domain (if provided) */
247 if (!is_empty(email
) &&
248 (!strchr(email
, '@') ||
249 g_str_has_prefix(email
, "@") ||
250 g_str_has_suffix(email
, "@")))
252 *errmsg
= _("Email address should be valid if provided\nExample: user@company.com");
256 /* ensure that user name doesn't contain spaces */
257 user_domain
= g_strsplit(signin_name
, "@", 2);
258 SIPE_DEBUG_INFO("sipe_core_allocate: user '%s' domain '%s'", user_domain
[0], user_domain
[1]);
259 if (strchr(user_domain
[0], ' ') != NULL
) {
260 g_strfreev(user_domain
);
261 *errmsg
= _("SIP Exchange user name contains whitespace");
265 /* ensure that email_url is in proper format if enabled (if provided).
266 * Example (Exchange): https://server.company.com/EWS/Exchange.asmx
267 * Example (Domino) : https://[domino_server]/[mail_database_name].nsf
269 if (!is_empty(email_url
)) {
270 char *tmp
= g_ascii_strdown(email_url
, -1);
271 if (!g_str_has_prefix(tmp
, "https://"))
274 g_strfreev(user_domain
);
275 *errmsg
= _("Email services URL should be valid if provided\n"
276 "Example: https://exchange.corp.com/EWS/Exchange.asmx\n"
277 "Example: https://domino.corp.com/maildatabase.nsf");
283 /* re-use sign-in name if login is empty */
284 if (is_empty(login_account
))
285 login_account
= signin_name
;
287 sipe_private
= g_new0(struct sipe_core_private
, 1);
288 SIPE_CORE_PRIVATE_FLAG_UNSET(SUBSCRIBED_BUDDIES
);
289 SIPE_CORE_PRIVATE_FLAG_UNSET(INITIAL_PUBLISH
);
290 SIPE_CORE_PRIVATE_FLAG_UNSET(SSO
);
292 SIPE_CORE_PRIVATE_FLAG_SET(SSO
);
293 sipe_private
->username
= g_strdup(signin_name
);
294 sipe_private
->email
= is_empty(email
) ? g_strdup(signin_name
) : g_strdup(email
);
295 sipe_private
->authuser
= sso
? NULL
: g_strdup(login_account
);
296 sipe_private
->password
= sso
? NULL
: g_strdup(password
);
297 sipe_private
->public.sip_name
= g_strdup(user_domain
[0]);
298 sipe_private
->public.sip_domain
= g_strdup(user_domain
[1]);
299 g_strfreev(user_domain
);
301 sipe_group_init(sipe_private
);
302 sipe_buddy_init(sipe_private
);
303 sipe_private
->our_publications
= g_hash_table_new_full(g_str_hash
, g_str_equal
,
304 g_free
, (GDestroyNotify
)g_hash_table_destroy
);
305 sipe_subscriptions_init(sipe_private
);
306 sipe_ews_autodiscover_init(sipe_private
);
307 sipe_status_set_activity(sipe_private
, SIPE_ACTIVITY_UNSET
);
309 return((struct sipe_core_public
*)sipe_private
);
312 void sipe_core_backend_initialized(struct sipe_core_private
*sipe_private
,
313 guint authentication
)
317 sipe_private
->authentication_type
= authentication
;
319 /* user specified email login? */
320 value
= sipe_backend_setting(SIPE_CORE_PUBLIC
, SIPE_SETTING_EMAIL_LOGIN
);
321 if (!is_empty(value
)) {
322 sipe_private
->email_authuser
= g_strdup(value
);
323 sipe_private
->email_password
= g_strdup(sipe_backend_setting(SIPE_CORE_PUBLIC
,
324 SIPE_SETTING_EMAIL_PASSWORD
));
328 void sipe_core_connection_cleanup(struct sipe_core_private
*sipe_private
)
330 g_free(sipe_private
->epid
);
331 sipe_private
->epid
= NULL
;
333 sipe_http_free(sipe_private
);
334 sip_transport_disconnect(sipe_private
);
336 sipe_schedule_cancel_all(sipe_private
);
338 if (sipe_private
->allowed_events
)
339 sipe_utils_slist_free_full(sipe_private
->allowed_events
, g_free
);
341 sipe_ocs2007_free(sipe_private
);
343 sipe_core_buddy_menu_free(SIPE_CORE_PUBLIC
);
345 if (sipe_private
->contact
)
346 g_free(sipe_private
->contact
);
347 sipe_private
->contact
= NULL
;
348 if (sipe_private
->register_callid
)
349 g_free(sipe_private
->register_callid
);
350 sipe_private
->register_callid
= NULL
;
352 if (sipe_private
->focus_factory_uri
)
353 g_free(sipe_private
->focus_factory_uri
);
354 sipe_private
->focus_factory_uri
= NULL
;
356 sipe_groupchat_free(sipe_private
);
359 void sipe_core_deallocate(struct sipe_core_public
*sipe_public
)
361 struct sipe_core_private
*sipe_private
= SIPE_CORE_PRIVATE
;
364 if (sipe_private
->media_call
) {
365 sipe_media_handle_going_offline(sipe_private
->media_call
);
369 /* leave all conversations */
370 if (sipe_private
->sessions
) {
372 while ((entry
= sipe_private
->sessions
) != NULL
) {
373 sipe_session_close(sipe_private
, entry
->data
);
377 sipe_conf_cancel_unaccepted(sipe_private
, NULL
);
379 if (sipe_private
->csta
) {
380 sip_csta_close(sipe_private
);
383 /* pending service requests must be cancelled first */
384 sipe_svc_free(sipe_private
);
385 sipe_webticket_free(sipe_private
);
386 sipe_ucs_free(sipe_private
);
388 if (sipe_backend_connection_is_valid(SIPE_CORE_PUBLIC
)) {
389 sipe_subscriptions_unsubscribe(sipe_private
);
390 sip_transport_deregister(sipe_private
);
393 sipe_core_connection_cleanup(sipe_private
);
394 sipe_ews_autodiscover_free(sipe_private
);
395 sipe_cal_calendar_free(sipe_private
->calendar
);
396 sipe_certificate_free(sipe_private
);
398 g_free(sipe_private
->public.sip_name
);
399 g_free(sipe_private
->public.sip_domain
);
400 g_free(sipe_private
->username
);
401 g_free(sipe_private
->email_password
);
402 g_free(sipe_private
->email_authuser
);
403 g_free(sipe_private
->email
);
404 g_free(sipe_private
->password
);
405 g_free(sipe_private
->authuser
);
406 g_free(sipe_private
->status
);
407 g_free(sipe_private
->note
);
408 g_free(sipe_private
->ocs2005_user_states
);
410 sipe_buddy_free(sipe_private
);
411 g_hash_table_destroy(sipe_private
->our_publications
);
412 g_hash_table_destroy(sipe_private
->user_state_publications
);
413 sipe_subscriptions_destroy(sipe_private
);
414 sipe_group_free(sipe_private
);
416 if (sipe_private
->our_publication_keys
)
417 sipe_utils_slist_free_full(sipe_private
->our_publication_keys
, g_free
);
420 g_free(sipe_private
->test_call_bot_uri
);
421 g_free(sipe_private
->uc_line_uri
);
422 g_free(sipe_private
->mras_uri
);
423 g_free(sipe_private
->media_relay_username
);
424 g_free(sipe_private
->media_relay_password
);
425 sipe_media_relay_list_free(sipe_private
->media_relays
);
428 g_free(sipe_private
->persistentChatPool_uri
);
429 g_free(sipe_private
->addressbook_uri
);
430 g_free(sipe_private
->dlx_uri
);
431 sipe_utils_slist_free_full(sipe_private
->conf_mcu_types
, g_free
);
432 g_free(sipe_private
);
435 void sipe_core_email_authentication(struct sipe_core_private
*sipe_private
,
436 struct sipe_http_request
*request
)
438 if (sipe_private
->email_authuser
) {
439 sipe_http_request_authentication(request
,
440 sipe_private
->email_authuser
,
441 sipe_private
->email_password
);