security: extract domain from username in NTLM
[siplcs.git] / src / api / sipe-core.h
blob4eac2a0ac1b4aca95b937abe222fc22a7def8945
1 /**
2 * @file sipe-core.h
4 * pidgin-sipe
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 /**
25 * Backend -> SIPE Core API - functions called by backend code
27 ***************** !!! IMPORTANT NOTE FOR BACKEND CODERS !!! *****************
29 * The SIPE core assumes atomicity and is *NOT* thread-safe.
31 * It *does not* protect any of its data structures or code paths with locks!
33 * In no circumstances it must be interrupted by another thread calling
34 * sipe_core_xxx() while the first thread has entered the SIPE core through
35 * a sipe_core_xxx() function.
37 ***************** !!! IMPORTANT NOTE FOR BACKEND CODERS !!! *****************
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
44 /**
45 * Transport type
47 #define SIPE_TRANSPORT_AUTO 0
48 #define SIPE_TRANSPORT_TLS 1
49 #define SIPE_TRANSPORT_TCP 2
51 /**
52 * Transport connection (public part)
54 * The receiver in the backend fills "buffer". The backend has to zero
55 * terminate the buffer before calling the processing function in the core.
57 * The processing function in the core can remove content from the buffer.
58 * It has to update buffer_used accordingly.
61 struct sipe_transport_connection {
62 gpointer user_data;
63 gchar *buffer;
64 gsize buffer_used; /* 0 < buffer_used < buffer_length */
65 gsize buffer_length; /* read-only */
66 guint type; /* read-only */
67 guint client_port; /* read-only */
70 /**
71 * Opaque data type for chat session
73 struct sipe_chat_session;
75 /**
76 * File transport (public part)
78 struct sipe_file_transfer {
79 struct sipe_backend_file_transfer *backend_private;
82 /**
83 * Opaque data type for backend private data.
84 * The backend is responsible to allocate and free it.
86 struct sipe_backend_private;
88 /**
89 * SIP transport authentication scheme
91 #define SIPE_AUTHENTICATION_TYPE_UNSET 0
92 #define SIPE_AUTHENTICATION_TYPE_BASIC 1 /* internal use only */
93 #define SIPE_AUTHENTICATION_TYPE_NTLM 2
94 #define SIPE_AUTHENTICATION_TYPE_KERBEROS 3
95 #define SIPE_AUTHENTICATION_TYPE_NEGOTIATE 4 /* internal use only */
96 #define SIPE_AUTHENTICATION_TYPE_TLS_DSK 5
97 #define SIPE_AUTHENTICATION_TYPE_AUTOMATIC 6 /* always last */
99 /**
100 * Flags
102 /* user disabled calendar information publishing */
103 #define SIPE_CORE_FLAG_DONT_PUBLISH 0x00000001
105 #define SIPE_CORE_FLAG_IS(flag) \
106 ((sipe_public->flags & SIPE_CORE_FLAG_ ## flag) == SIPE_CORE_FLAG_ ## flag)
107 #define SIPE_CORE_FLAG_SET(flag) \
108 (sipe_public->flags |= SIPE_CORE_FLAG_ ## flag)
109 #define SIPE_CORE_FLAG_UNSET(flag) \
110 (sipe_public->flags &= ~SIPE_CORE_FLAG_ ## flag)
113 * Public part of the Sipe data structure
115 * This part contains the information needed by the core and the backend.
117 struct sipe_core_public {
119 * This points to the private data for the backend.
120 * The backend is responsible to allocate and free it.
122 struct sipe_backend_private *backend_private;
124 /* flags (see above) */
125 guint32 flags;
127 /* user information */
128 gchar *sip_name;
129 gchar *sip_domain;
131 /* server information */
132 /* currently nothing */
136 * Initialize & destroy functions for the SIPE core
137 * Should be called on loading and unloading of the plugin.
139 void sipe_core_init(const char *locale_dir);
140 void sipe_core_destroy(void);
142 /** Utility functions exported by the core to backends ***********************/
143 gboolean sipe_strequal(const gchar *left, const gchar *right);
145 GSList *
146 sipe_utils_nameval_add(GSList *list, const gchar *name, const gchar *value);
148 const gchar *
149 sipe_utils_nameval_find(const GSList *list, const gchar *name);
151 const gchar *
152 sipe_utils_nameval_find_instance(const GSList *list, const gchar *name, int which);
154 void
155 sipe_utils_nameval_free(GSList *list);
157 gchar *sip_uri_from_name(const gchar *name);
158 gchar *sip_uri_if_valid(const gchar *string);
160 /*****************************************************************************/
163 * Other functions (need to be sorted once structure becomes clear.
166 /* Get translated about string. Must be g_free'd(). */
167 gchar *sipe_core_about(void);
169 /* Execute a scheduled action */
170 void sipe_core_schedule_execute(gpointer data);
172 /* menu actions */
173 void sipe_core_update_calendar(struct sipe_core_public *sipe_public);
174 void sipe_core_reset_status(struct sipe_core_public *sipe_public);
176 /* access levels */
177 void sipe_core_change_access_level_from_container(struct sipe_core_public *sipe_public,
178 gpointer parameter);
179 void sipe_core_change_access_level_for_domain(struct sipe_core_public *sipe_public,
180 const gchar *domain,
181 guint index);
184 * Activity
185 * - core: maps this to OCS protocol values
186 * maps this to translated descriptions
187 * - backend: maps this to backend status values
188 * backend token string can be used as "ID" in protocol
190 * This is passed back-and-forth and therefore defined as list, not as enum.
191 * Can be used as array index
193 #define SIPE_ACTIVITY_UNSET 0
194 #define SIPE_ACTIVITY_AVAILABLE 1
195 #define SIPE_ACTIVITY_ONLINE 2
196 #define SIPE_ACTIVITY_INACTIVE 3
197 #define SIPE_ACTIVITY_BUSY 4
198 #define SIPE_ACTIVITY_BUSYIDLE 5
199 #define SIPE_ACTIVITY_DND 6
200 #define SIPE_ACTIVITY_BRB 7
201 #define SIPE_ACTIVITY_AWAY 8
202 #define SIPE_ACTIVITY_LUNCH 9
203 #define SIPE_ACTIVITY_INVISIBLE 10
204 #define SIPE_ACTIVITY_OFFLINE 11
205 #define SIPE_ACTIVITY_ON_PHONE 12
206 #define SIPE_ACTIVITY_IN_CONF 13
207 #define SIPE_ACTIVITY_IN_MEETING 14
208 #define SIPE_ACTIVITY_OOF 15
209 #define SIPE_ACTIVITY_URGENT_ONLY 16
210 #define SIPE_ACTIVITY_NUM_TYPES 17 /* use to define array size */
212 const gchar *sipe_core_activity_description(guint type);
214 /* buddy actions */
216 * Get status text for buddy.
218 * @param sipe_public Sipe core public data structure.
219 * @param uri SIP URI of the buddy
220 * @param activity activity value for buddy
221 * @param status_text backend-specific buddy status text for activity.
223 * @return HTML status text for the buddy or NULL. Must be g_free()'d.
225 gchar *sipe_core_buddy_status(struct sipe_core_public *sipe_public,
226 const gchar *uri,
227 guint activity,
228 const gchar *status_text);
230 void sipe_core_buddy_got_status(struct sipe_core_public *sipe_public,
231 const gchar *uri,
232 guint activity);
235 * Trigger generation of buddy information label/text pairs
237 * @param sipe_public Sipe core public data structure.
238 * @param uri SIP URI of the buddy
239 * @param status_text backend-specific buddy status text for ID.
240 * @param is_online backend considers buddy to be online.
241 * @param tooltip opaque backend identifier for tooltip info. This is the
242 * parameter given to @c sipe_backend_buddy_tooltip_add()
244 struct sipe_backend_buddy_tooltip;
245 void sipe_core_buddy_tooltip_info(struct sipe_core_public *sipe_public,
246 const gchar *uri,
247 const gchar *status_name,
248 gboolean is_online,
249 struct sipe_backend_buddy_tooltip *tooltip);
252 * Add a buddy
254 * @param sipe_public Sipe core public data structure
255 * @param uri SIP URI of the buddy
256 * @param group_name backend-specific group name
258 void sipe_core_buddy_add(struct sipe_core_public *sipe_public,
259 const gchar *uri,
260 const gchar *group_name);
263 * Remove a buddy
265 * @param sipe_public Sipe core public data structure
266 * @param uri SIP URI of the buddy
267 * @param group_name backend-specific group name
269 void sipe_core_buddy_remove(struct sipe_core_public *sipe_public,
270 const gchar *uri,
271 const gchar *group_name);
273 void sipe_core_contact_allow_deny(struct sipe_core_public *sipe_public,
274 const gchar *who,
275 gboolean allow);
276 void sipe_core_group_set_alias(struct sipe_core_public *sipe_public,
277 const gchar *who,
278 const gchar *alias);
281 * Setup core data
283 struct sipe_core_public *sipe_core_allocate(const gchar *signin_name,
284 gboolean sso,
285 const gchar *login_domain,
286 const gchar *login_account,
287 const gchar *password,
288 const gchar *email,
289 const gchar *email_url,
290 const gchar **errmsg);
291 void sipe_core_deallocate(struct sipe_core_public *sipe_public);
294 * Check if SIP authentication scheme requires a password
296 * NOTE: this can be called *BEFORE* @c sipe_core_allocate()!
298 * @param authentication SIP transport authentication type
299 * @param sso TRUE if user selected Single-Sign On
301 * @return TRUE if password is required
303 gboolean sipe_core_transport_sip_requires_password(guint authentication,
304 gboolean sso);
307 * Connect to SIP server
309 void sipe_core_transport_sip_connect(struct sipe_core_public *sipe_public,
310 guint transport,
311 guint authentication,
312 const gchar *server,
313 const gchar *port);
316 * Get SIP server host name
318 * @param sipe_public Sipe core public data structure
320 * @return server host name (may be @c NULL if not fully connected yet)
322 const gchar *sipe_core_transport_sip_server_name(struct sipe_core_public *sipe_public);
325 * Get chat ID, f.ex. group chat URI
327 const gchar *sipe_core_chat_id(struct sipe_core_public *sipe_public,
328 struct sipe_chat_session *chat_session);
331 * Invite to chat
333 void sipe_core_chat_invite(struct sipe_core_public *sipe_public,
334 struct sipe_chat_session *chat_session,
335 const char *name);
338 * Rejoin a chat after connection re-establishment
340 void sipe_core_chat_rejoin(struct sipe_core_public *sipe_public,
341 struct sipe_chat_session *chat_session);
344 * Leave a chat
346 void sipe_core_chat_leave(struct sipe_core_public *sipe_public,
347 struct sipe_chat_session *chat_session);
350 * Send message to chat
352 void sipe_core_chat_send(struct sipe_core_public *sipe_public,
353 struct sipe_chat_session *chat_session,
354 const char *what);
357 * Check chat lock status
359 typedef enum {
360 SIPE_CHAT_LOCK_STATUS_NOT_ALLOWED = 0,
361 SIPE_CHAT_LOCK_STATUS_UNLOCKED,
362 SIPE_CHAT_LOCK_STATUS_LOCKED
363 } sipe_chat_lock_status;
364 sipe_chat_lock_status sipe_core_chat_lock_status(struct sipe_core_public *sipe_public,
365 struct sipe_chat_session *chat_session);
368 * Lock chat
370 void sipe_core_chat_modify_lock(struct sipe_core_public *sipe_public,
371 struct sipe_chat_session *chat_session,
372 const gboolean locked);
375 * Create new session with Focus URI
377 * @param sipe_public (in) SIPE core data.
378 * @param focus_uri (in) focus URI string
380 * @return new SIP session
382 struct sip_session *
383 sipe_core_conf_create(struct sipe_core_public *sipe_public,
384 const gchar *focus_uri);
386 /* buddy menu callback: parameter == chat_session */
387 void sipe_core_conf_make_leader(struct sipe_core_public *sipe_public,
388 gpointer parameter,
389 const gchar *buddy_name);
390 void sipe_core_conf_remove_from(struct sipe_core_public *sipe_public,
391 gpointer parameter,
392 const gchar *buddy_name);
394 /* call control (CSTA) */
395 void sipe_core_buddy_make_call(struct sipe_core_public *sipe_public,
396 const gchar *phone);
398 /* media */
399 void sipe_core_media_initiate_call(struct sipe_core_public *sipe_public,
400 const char *participant,
401 gboolean with_video);
403 * Connects to a conference call specified by given chat session
405 * @param sipe_public (in) SIPE core data.
406 * @param chat_session (in) chat session structure
408 void sipe_core_media_connect_conference(struct sipe_core_public *sipe_public,
409 struct sipe_chat_session *chat_session);
412 * Checks whether there is a media call in progress
414 * @param sipe_public (in) SIPE core data.
416 * @return @c TRUE if media call is in progress
418 gboolean sipe_core_media_in_call(struct sipe_core_public *sipe_public);
421 * Initiates a call with given phone number
423 * @param sipe_public (in) SIPE core data.
424 * @parem phone_number (in) a mobile or landline phone number, i.e. +46123456
426 void sipe_core_media_phone_call(struct sipe_core_public *sipe_public,
427 const gchar *phone_number);
430 * Checks voice quality by making a call to the test service
432 * @param sipe_public (in) SIPE core data.
434 void sipe_core_media_test_call(struct sipe_core_public *sipe_public);
436 /* file transfer */
437 struct sipe_file_transfer *sipe_core_ft_allocate(struct sipe_core_public *sipe_public);
438 void sipe_core_ft_deallocate(struct sipe_file_transfer *ft);
439 void sipe_core_ft_cancel(struct sipe_file_transfer *ft);
440 void sipe_core_ft_incoming_init(struct sipe_file_transfer *ft);
441 void sipe_core_ft_outgoing_init(struct sipe_file_transfer *ft,
442 const gchar *filename, gsize size,
443 const gchar *who);
445 void sipe_core_tftp_incoming_start(struct sipe_file_transfer *ft,
446 gsize total_size);
447 gboolean sipe_core_tftp_incoming_stop(struct sipe_file_transfer *ft);
448 void sipe_core_tftp_outgoing_start(struct sipe_file_transfer *ft,
449 gsize total_size);
450 gboolean sipe_core_tftp_outgoing_stop(struct sipe_file_transfer *ft);
451 gssize sipe_core_tftp_read(struct sipe_file_transfer *ft, guchar **buffer,
452 gsize bytes_remaining, gsize bytes_available);
453 gssize sipe_core_tftp_write(struct sipe_file_transfer *ft, const guchar *buffer,
454 gsize size);
455 /* group chat */
456 gboolean sipe_core_groupchat_query_rooms(struct sipe_core_public *sipe_public);
457 void sipe_core_groupchat_join(struct sipe_core_public *sipe_public,
458 const gchar *uri);
460 /* IM */
461 void sipe_core_im_send(struct sipe_core_public *sipe_public,
462 const gchar *who,
463 const gchar *what);
464 void sipe_core_im_close(struct sipe_core_public *sipe_public,
465 const gchar *who);
467 /* user */
468 void sipe_core_user_feedback_typing(struct sipe_core_public *sipe_public,
469 const gchar *to,
470 gboolean typing);
472 void sipe_core_user_ask_cb(gpointer key, gboolean accepted);
474 /* groups */
475 void sipe_core_group_rename(struct sipe_core_public *sipe_public,
476 const gchar *old_name,
477 const gchar *new_name);
479 void sipe_core_group_remove(struct sipe_core_public *sipe_public,
480 const gchar *name);
482 /* buddies */
483 void sipe_core_buddy_group(struct sipe_core_public *sipe_public,
484 const gchar *who,
485 const gchar *old_group_name,
486 const gchar *new_group_name);
488 struct sipe_backend_search_token;
489 void sipe_core_buddy_search(struct sipe_core_public *sipe_public,
490 struct sipe_backend_search_token *token,
491 const gchar *given_name,
492 const gchar *surname,
493 const gchar *email,
494 const gchar *sipid,
495 const gchar *company,
496 const gchar *country);
498 void sipe_core_buddy_get_info(struct sipe_core_public *sipe_public,
499 const gchar *who);
501 void sipe_core_buddy_new_chat(struct sipe_core_public *sipe_public,
502 const gchar *who);
503 void sipe_core_buddy_send_email(struct sipe_core_public *sipe_public,
504 const gchar *who);
506 struct sipe_backend_buddy_menu;
507 struct sipe_backend_buddy_menu *sipe_core_buddy_create_menu(struct sipe_core_public *sipe_public,
508 const gchar *buddy_name,
509 struct sipe_backend_buddy_menu *menu);
511 void sipe_core_buddy_menu_free(struct sipe_core_public *sipe_public);
513 /* status */
514 void sipe_core_status_set(struct sipe_core_public *sipe_public,
515 guint activity,
516 const gchar *note);
517 void sipe_core_status_idle(struct sipe_core_public *sipe_public);
519 #ifdef __cplusplus
521 #endif
524 Local Variables:
525 mode: c
526 c-file-style: "bsd"
527 indent-tabs-mode: t
528 tab-width: 8
529 End: