OBS: sync with latest versions
[siplcs.git] / src / api / sipe-core.h
blob955af24ee7f8abcb5bae0b939bed11327d6d4428
1 /**
2 * @file sipe-core.h
4 * pidgin-sipe
6 * Copyright (C) 2010-2013 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
98 /**
99 * Flags
101 /* user disabled calendar information publishing */
102 #define SIPE_CORE_FLAG_DONT_PUBLISH 0x00000001
104 #define SIPE_CORE_FLAG_IS(flag) \
105 ((sipe_public->flags & SIPE_CORE_FLAG_ ## flag) == SIPE_CORE_FLAG_ ## flag)
106 #define SIPE_CORE_FLAG_SET(flag) \
107 (sipe_public->flags |= SIPE_CORE_FLAG_ ## flag)
108 #define SIPE_CORE_FLAG_UNSET(flag) \
109 (sipe_public->flags &= ~SIPE_CORE_FLAG_ ## flag)
112 * Public part of the Sipe data structure
114 * This part contains the information needed by the core and the backend.
116 struct sipe_core_public {
118 * This points to the private data for the backend.
119 * The backend is responsible to allocate and free it.
121 struct sipe_backend_private *backend_private;
123 /* flags (see above) */
124 guint32 flags;
126 /* user information */
127 gchar *sip_name;
128 gchar *sip_domain;
130 /* server information */
131 guint keepalive_timeout;
135 * Initialize & destroy functions for the SIPE core
136 * Should be called on loading and unloading of the plugin.
138 void sipe_core_init(const char *locale_dir);
139 void sipe_core_destroy(void);
141 /** Utility functions exported by the core to backends ***********************/
142 gboolean sipe_strequal(const gchar *left, const gchar *right);
144 GSList *
145 sipe_utils_nameval_add(GSList *list, const gchar *name, const gchar *value);
147 const gchar *
148 sipe_utils_nameval_find(const GSList *list, const gchar *name);
150 const gchar *
151 sipe_utils_nameval_find_instance(const GSList *list, const gchar *name, int which);
153 void
154 sipe_utils_nameval_free(GSList *list);
156 gchar *sip_uri_from_name(const gchar *name);
157 gchar *sip_uri_if_valid(const gchar *string);
159 /*****************************************************************************/
162 * Other functions (need to be sorted once structure becomes clear.
165 /* Get translated about string. Must be g_free'd(). */
166 gchar *sipe_core_about(void);
168 /* Execute a scheduled action */
169 void sipe_core_schedule_execute(gpointer data);
171 /* menu actions */
172 void sipe_core_update_calendar(struct sipe_core_public *sipe_public);
173 void sipe_core_reset_status(struct sipe_core_public *sipe_public);
175 /* access levels */
176 void sipe_core_change_access_level_from_container(struct sipe_core_public *sipe_public,
177 gpointer parameter);
178 void sipe_core_change_access_level_for_domain(struct sipe_core_public *sipe_public,
179 const gchar *domain,
180 guint index);
183 * Activity
184 * - core: maps this to OCS protocol values
185 * maps this to translated descriptions
186 * - backend: maps this to backend status values
187 * backend token string can be used as "ID" in protocol
189 * This is passed back-and-forth and therefore defined as list, not as enum.
190 * Can be used as array index
192 #define SIPE_ACTIVITY_UNSET 0
193 #define SIPE_ACTIVITY_AVAILABLE 1
194 #define SIPE_ACTIVITY_ONLINE 2
195 #define SIPE_ACTIVITY_INACTIVE 3
196 #define SIPE_ACTIVITY_BUSY 4
197 #define SIPE_ACTIVITY_BUSYIDLE 5
198 #define SIPE_ACTIVITY_DND 6
199 #define SIPE_ACTIVITY_BRB 7
200 #define SIPE_ACTIVITY_AWAY 8
201 #define SIPE_ACTIVITY_LUNCH 9
202 #define SIPE_ACTIVITY_INVISIBLE 10
203 #define SIPE_ACTIVITY_OFFLINE 11
204 #define SIPE_ACTIVITY_ON_PHONE 12
205 #define SIPE_ACTIVITY_IN_CONF 13
206 #define SIPE_ACTIVITY_IN_MEETING 14
207 #define SIPE_ACTIVITY_OOF 15
208 #define SIPE_ACTIVITY_URGENT_ONLY 16
209 #define SIPE_ACTIVITY_NUM_TYPES 17 /* use to define array size */
211 const gchar *sipe_core_activity_description(guint type);
213 /* buddy actions */
215 * Get status text for buddy.
217 * @param sipe_public Sipe core public data structure.
218 * @param uri SIP URI of the buddy
219 * @param activity activity value for buddy
220 * @param status_text backend-specific buddy status text for activity.
222 * @return HTML status text for the buddy or NULL. Must be g_free()'d.
224 gchar *sipe_core_buddy_status(struct sipe_core_public *sipe_public,
225 const gchar *uri,
226 guint activity,
227 const gchar *status_text);
229 void sipe_core_buddy_got_status(struct sipe_core_public *sipe_public,
230 const gchar *uri,
231 guint activity);
234 * Trigger generation of buddy information label/text pairs
236 * @param sipe_public Sipe core public data structure.
237 * @param uri SIP URI of the buddy
238 * @param status_text backend-specific buddy status text for ID.
239 * @param is_online backend considers buddy to be online.
240 * @param tooltip opaque backend identifier for tooltip info. This is the
241 * parameter given to @c sipe_backend_buddy_tooltip_add()
243 struct sipe_backend_buddy_tooltip;
244 void sipe_core_buddy_tooltip_info(struct sipe_core_public *sipe_public,
245 const gchar *uri,
246 const gchar *status_name,
247 gboolean is_online,
248 struct sipe_backend_buddy_tooltip *tooltip);
251 * Add a buddy
253 * @param sipe_public Sipe core public data structure
254 * @param uri SIP URI of the buddy
255 * @param group_name backend-specific group name
257 void sipe_core_buddy_add(struct sipe_core_public *sipe_public,
258 const gchar *uri,
259 const gchar *group_name);
262 * Remove a buddy
264 * @param sipe_public Sipe core public data structure
265 * @param uri SIP URI of the buddy
266 * @param group_name backend-specific group name
268 void sipe_core_buddy_remove(struct sipe_core_public *sipe_public,
269 const gchar *uri,
270 const gchar *group_name);
272 void sipe_core_contact_allow_deny(struct sipe_core_public *sipe_public,
273 const gchar *who,
274 gboolean allow);
275 void sipe_core_group_set_alias(struct sipe_core_public *sipe_public,
276 const gchar *who,
277 const gchar *alias);
280 * Setup core data
282 struct sipe_core_public *sipe_core_allocate(const gchar *signin_name,
283 gboolean sso,
284 const gchar *login_domain,
285 const gchar *login_account,
286 const gchar *password,
287 const gchar *email,
288 const gchar *email_url,
289 const gchar **errmsg);
290 void sipe_core_deallocate(struct sipe_core_public *sipe_public);
293 * Check if SIP authentication scheme requires a password
295 * NOTE: this can be called *BEFORE* @c sipe_core_allocate()!
297 * @param authentication SIP transport authentication type
298 * @param sso TRUE if user selected Single-Sign On
300 * @return TRUE if password is required
302 gboolean sipe_core_transport_sip_requires_password(guint authentication,
303 gboolean sso);
306 * Connect to SIP server
308 void sipe_core_transport_sip_connect(struct sipe_core_public *sipe_public,
309 guint transport,
310 guint authentication,
311 const gchar *server,
312 const gchar *port);
313 void sipe_core_transport_sip_keepalive(struct sipe_core_public *sipe_public);
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 * Invite to chat
327 void sipe_core_chat_invite(struct sipe_core_public *sipe_public,
328 struct sipe_chat_session *chat_session,
329 const char *name);
332 * Rejoin a chat after connection re-establishment
334 void sipe_core_chat_rejoin(struct sipe_core_public *sipe_public,
335 struct sipe_chat_session *chat_session);
338 * Leave a chat
340 void sipe_core_chat_leave(struct sipe_core_public *sipe_public,
341 struct sipe_chat_session *chat_session);
344 * Send message to chat
346 void sipe_core_chat_send(struct sipe_core_public *sipe_public,
347 struct sipe_chat_session *chat_session,
348 const char *what);
351 * Check chat lock status
353 typedef enum {
354 SIPE_CHAT_LOCK_STATUS_NOT_ALLOWED = 0,
355 SIPE_CHAT_LOCK_STATUS_UNLOCKED,
356 SIPE_CHAT_LOCK_STATUS_LOCKED
357 } sipe_chat_lock_status;
358 sipe_chat_lock_status sipe_core_chat_lock_status(struct sipe_core_public *sipe_public,
359 struct sipe_chat_session *chat_session);
362 * Lock chat
364 void sipe_core_chat_modify_lock(struct sipe_core_public *sipe_public,
365 struct sipe_chat_session *chat_session,
366 const gboolean locked);
369 * Create new session with Focus URI
371 * @param sipe_public (in) SIPE core data.
372 * @param focus_uri (in) focus URI string
374 * @return new SIP session
376 struct sip_session *
377 sipe_core_conf_create(struct sipe_core_public *sipe_public,
378 const gchar *focus_uri);
380 /* buddy menu callback: parameter == chat_session */
381 void sipe_core_conf_make_leader(struct sipe_core_public *sipe_public,
382 gpointer parameter,
383 const gchar *buddy_name);
384 void sipe_core_conf_remove_from(struct sipe_core_public *sipe_public,
385 gpointer parameter,
386 const gchar *buddy_name);
388 /* call control (CSTA) */
389 void sipe_core_buddy_make_call(struct sipe_core_public *sipe_public,
390 const gchar *phone);
392 /* media */
393 void sipe_core_media_initiate_call(struct sipe_core_public *sipe_public,
394 const char *participant,
395 gboolean with_video);
397 * Connects to a conference call specified by given chat session
399 * @param sipe_public (in) SIPE core data.
400 * @param chat_session (in) chat session structure
402 void sipe_core_media_connect_conference(struct sipe_core_public *sipe_public,
403 struct sipe_chat_session *chat_session);
406 * Checks whether there is a media call in progress
408 * @param sipe_public (in) SIPE core data.
410 * @return @c TRUE if media call is in progress
412 gboolean sipe_core_media_in_call(struct sipe_core_public *sipe_public);
415 * Initiates a call with given phone number
417 * @param sipe_public (in) SIPE core data.
418 * @parem phone_number (in) a mobile or landline phone number, i.e. +46123456
420 void sipe_core_media_phone_call(struct sipe_core_public *sipe_public,
421 const gchar *phone_number);
424 * Checks voice quality by making a call to the test service
426 * @param sipe_public (in) SIPE core data.
428 void sipe_core_media_test_call(struct sipe_core_public *sipe_public);
430 /* file transfer */
431 struct sipe_file_transfer *sipe_core_ft_allocate(struct sipe_core_public *sipe_public);
432 void sipe_core_ft_deallocate(struct sipe_file_transfer *ft);
433 void sipe_core_ft_cancel(struct sipe_file_transfer *ft);
434 void sipe_core_ft_incoming_init(struct sipe_file_transfer *ft);
435 void sipe_core_ft_outgoing_init(struct sipe_file_transfer *ft,
436 const gchar *filename, gsize size,
437 const gchar *who);
439 void sipe_core_tftp_incoming_start(struct sipe_file_transfer *ft,
440 gsize total_size);
441 gboolean sipe_core_tftp_incoming_stop(struct sipe_file_transfer *ft);
442 void sipe_core_tftp_outgoing_start(struct sipe_file_transfer *ft,
443 gsize total_size);
444 gboolean sipe_core_tftp_outgoing_stop(struct sipe_file_transfer *ft);
445 gssize sipe_core_tftp_read(struct sipe_file_transfer *ft, guchar **buffer,
446 gsize bytes_remaining, gsize bytes_available);
447 gssize sipe_core_tftp_write(struct sipe_file_transfer *ft, const guchar *buffer,
448 gsize size);
449 /* group chat */
450 gboolean sipe_core_groupchat_query_rooms(struct sipe_core_public *sipe_public);
451 void sipe_core_groupchat_join(struct sipe_core_public *sipe_public,
452 const gchar *uri);
454 /* IM */
455 void sipe_core_im_send(struct sipe_core_public *sipe_public,
456 const gchar *who,
457 const gchar *what);
458 void sipe_core_im_close(struct sipe_core_public *sipe_public,
459 const gchar *who);
461 /* user */
462 void sipe_core_user_feedback_typing(struct sipe_core_public *sipe_public,
463 const gchar *to);
465 void sipe_core_user_ask_cb(gpointer key, gboolean accepted);
467 /* groups */
468 void sipe_core_group_rename(struct sipe_core_public *sipe_public,
469 const gchar *old_name,
470 const gchar *new_name);
472 void sipe_core_group_remove(struct sipe_core_public *sipe_public,
473 const gchar *name);
475 /* buddies */
476 void sipe_core_buddy_group(struct sipe_core_public *sipe_public,
477 const gchar *who,
478 const gchar *old_group_name,
479 const gchar *new_group_name);
481 struct sipe_backend_search_token;
482 void sipe_core_buddy_search(struct sipe_core_public *sipe_public,
483 struct sipe_backend_search_token *token,
484 const gchar *given_name,
485 const gchar *surname,
486 const gchar *email,
487 const gchar *company,
488 const gchar *country);
490 void sipe_core_buddy_get_info(struct sipe_core_public *sipe_public,
491 const gchar *who);
493 void sipe_core_buddy_new_chat(struct sipe_core_public *sipe_public,
494 const gchar *who);
495 void sipe_core_buddy_send_email(struct sipe_core_public *sipe_public,
496 const gchar *who);
498 struct sipe_backend_buddy_menu;
499 struct sipe_backend_buddy_menu *sipe_core_buddy_create_menu(struct sipe_core_public *sipe_public,
500 const gchar *buddy_name,
501 struct sipe_backend_buddy_menu *menu);
503 void sipe_core_buddy_menu_free(struct sipe_core_public *sipe_public);
505 /* status */
506 void sipe_core_status_set(struct sipe_core_public *sipe_public,
507 guint activity,
508 const gchar *note);
509 void sipe_core_status_idle(struct sipe_core_public *sipe_public);
511 #ifdef __cplusplus
513 #endif
516 Local Variables:
517 mode: c
518 c-file-style: "bsd"
519 indent-tabs-mode: t
520 tab-width: 8
521 End: