media: allow to make a call to Audio Test Service when it is available
[siplcs.git] / src / api / sipe-core.h
blob1e9d82e52ed869710367eaf11d3034aff7d2a0e4
1 /**
2 * @file sipe-core.h
4 * pidgin-sipe
6 * Copyright (C) 2010-12 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 * Flags
91 #define SIPE_CORE_FLAG_KRB5 0x00000001 /* user enabled Kerberos 5 */
92 #define SIPE_CORE_FLAG_SSO 0x00000002 /* user enabled Single-Sign On */
93 #define SIPE_CORE_FLAG_TLS_DSK 0x00000004 /* user enabled TLS-DSK */
95 #define SIPE_CORE_FLAG_IS(flag) \
96 ((sipe_public->flags & SIPE_CORE_FLAG_ ## flag) == SIPE_CORE_FLAG_ ## flag)
97 #define SIPE_CORE_FLAG_SET(flag) \
98 (sipe_public->flags |= SIPE_CORE_FLAG_ ## flag)
99 #define SIPE_CORE_FLAG_UNSET(flag) \
100 (sipe_public->flags &= ~SIPE_CORE_FLAG_ ## flag)
103 * Public part of the Sipe data structure
105 * This part contains the information needed by the core and the backend.
107 struct sipe_core_public {
109 * This points to the private data for the backend.
110 * The backend is responsible to allocate and free it.
112 struct sipe_backend_private *backend_private;
114 /* flags (see above) */
115 guint32 flags;
117 /* user information */
118 gchar *sip_name;
119 gchar *sip_domain;
121 /* server information */
122 guint keepalive_timeout;
126 * Initialize & destroy functions for the SIPE core
127 * Should be called on loading and unloading of the plugin.
129 void sipe_core_init(const char *locale_dir);
130 void sipe_core_destroy(void);
132 /** Utility functions exported by the core to backends ***********************/
133 gboolean sipe_strequal(const gchar *left, const gchar *right);
135 GSList *
136 sipe_utils_nameval_add(GSList *list, const gchar *name, const gchar *value);
138 const gchar *
139 sipe_utils_nameval_find(const GSList *list, const gchar *name);
141 const gchar *
142 sipe_utils_nameval_find_instance(const GSList *list, const gchar *name, int which);
144 void
145 sipe_utils_nameval_free(GSList *list);
147 gboolean sipe_utils_is_avconf_uri(const gchar *uri);
149 gchar *sip_uri_from_name(const gchar *name);
150 gchar *sip_uri_if_valid(const gchar *string);
152 /*****************************************************************************/
155 * Other functions (need to be sorted once structure becomes clear.
158 /* Get translated about string. Must be g_free'd(). */
159 gchar *sipe_core_about(void);
161 /* Execute a scheduled action */
162 void sipe_core_schedule_execute(gpointer data);
164 /* menu actions */
165 void sipe_core_update_calendar(struct sipe_core_public *sipe_public);
166 void sipe_core_reset_status(struct sipe_core_public *sipe_public);
168 /* access levels */
169 void sipe_core_change_access_level_from_container(struct sipe_core_public *sipe_public,
170 gpointer parameter);
171 void sipe_core_change_access_level_for_domain(struct sipe_core_public *sipe_public,
172 const gchar *domain,
173 guint index);
176 * Activity
177 * - core: maps this to OCS protocol values
178 * maps this to translated descriptions
179 * - backend: maps this to backend status values
180 * backend token string can be used as "ID" in protocol
182 * This is passed back-and-forth and therefore defined as list, not as enum.
183 * Can be used as array index
185 #define SIPE_ACTIVITY_UNSET 0
186 #define SIPE_ACTIVITY_AVAILABLE 1
187 #define SIPE_ACTIVITY_ONLINE 2
188 #define SIPE_ACTIVITY_INACTIVE 3
189 #define SIPE_ACTIVITY_BUSY 4
190 #define SIPE_ACTIVITY_BUSYIDLE 5
191 #define SIPE_ACTIVITY_DND 6
192 #define SIPE_ACTIVITY_BRB 7
193 #define SIPE_ACTIVITY_AWAY 8
194 #define SIPE_ACTIVITY_LUNCH 9
195 #define SIPE_ACTIVITY_INVISIBLE 10
196 #define SIPE_ACTIVITY_OFFLINE 11
197 #define SIPE_ACTIVITY_ON_PHONE 12
198 #define SIPE_ACTIVITY_IN_CONF 13
199 #define SIPE_ACTIVITY_IN_MEETING 14
200 #define SIPE_ACTIVITY_OOF 15
201 #define SIPE_ACTIVITY_URGENT_ONLY 16
202 #define SIPE_ACTIVITY_NUM_TYPES 17 /* use to define array size */
204 const gchar *sipe_core_activity_description(guint type);
206 /* buddy actions */
208 * Get status text for buddy.
210 * @param sipe_public Sipe core public data structure.
211 * @param uri SIP URI of the buddy
212 * @param activity activity value for buddy
213 * @param status_text backend-specific buddy status text for activity.
215 * @return HTML status text for the buddy or NULL. Must be g_free()'d.
217 gchar *sipe_core_buddy_status(struct sipe_core_public *sipe_public,
218 const gchar *uri,
219 guint activity,
220 const gchar *status_text);
222 void sipe_core_buddy_got_status(struct sipe_core_public *sipe_public,
223 const gchar *uri,
224 guint activity);
227 * Trigger generation of buddy information label/text pairs
229 * @param sipe_public Sipe core public data structure.
230 * @param uri SIP URI of the buddy
231 * @param status_text backend-specific buddy status text for ID.
232 * @param is_online backend considers buddy to be online.
233 * @param tooltip opaque backend identifier for tooltip info. This is the
234 * parameter given to @c sipe_backend_buddy_tooltip_add()
236 struct sipe_backend_buddy_tooltip;
237 void sipe_core_buddy_tooltip_info(struct sipe_core_public *sipe_public,
238 const gchar *uri,
239 const gchar *status_name,
240 gboolean is_online,
241 struct sipe_backend_buddy_tooltip *tooltip);
244 * Add a buddy
246 * @param sipe_public Sipe core public data structure
247 * @param uri SIP URI of the buddy
248 * @param group_name backend-specific group name
250 void sipe_core_buddy_add(struct sipe_core_public *sipe_public,
251 const gchar *uri,
252 const gchar *group_name);
255 * Remove a buddy
257 * @param sipe_public Sipe core public data structure
258 * @param uri SIP URI of the buddy
259 * @param group_name backend-specific group name
261 void sipe_core_buddy_remove(struct sipe_core_public *sipe_public,
262 const gchar *uri,
263 const gchar *group_name);
265 void sipe_core_contact_allow_deny(struct sipe_core_public *sipe_public,
266 const gchar *who,
267 gboolean allow);
268 void sipe_core_group_set_user(struct sipe_core_public *sipe_public,
269 const gchar * who);
272 * Setup core data
274 struct sipe_core_public *sipe_core_allocate(const gchar *signin_name,
275 const gchar *login_domain,
276 const gchar *login_account,
277 const gchar *password,
278 const gchar *email,
279 const gchar *email_url,
280 const gchar **errmsg);
281 void sipe_core_deallocate(struct sipe_core_public *sipe_public);
284 * Connect to SIP server
286 void sipe_core_transport_sip_connect(struct sipe_core_public *sipe_public,
287 guint transport,
288 const gchar *server,
289 const gchar *port);
290 void sipe_core_transport_sip_keepalive(struct sipe_core_public *sipe_public);
293 * Invite to chat
295 void sipe_core_chat_invite(struct sipe_core_public *sipe_public,
296 struct sipe_chat_session *chat_session,
297 const char *name);
300 * Rejoin a chat after connection re-establishment
302 void sipe_core_chat_rejoin(struct sipe_core_public *sipe_public,
303 struct sipe_chat_session *chat_session);
306 * Leave a chat
308 void sipe_core_chat_leave(struct sipe_core_public *sipe_public,
309 struct sipe_chat_session *chat_session);
312 * Send message to chat
314 void sipe_core_chat_send(struct sipe_core_public *sipe_public,
315 struct sipe_chat_session *chat_session,
316 const char *what);
319 * Check chat lock status
321 typedef enum {
322 SIPE_CHAT_LOCK_STATUS_NOT_ALLOWED = 0,
323 SIPE_CHAT_LOCK_STATUS_UNLOCKED,
324 SIPE_CHAT_LOCK_STATUS_LOCKED
325 } sipe_chat_lock_status;
326 sipe_chat_lock_status sipe_core_chat_lock_status(struct sipe_core_public *sipe_public,
327 struct sipe_chat_session *chat_session);
330 * Lock chat
332 void sipe_core_chat_modify_lock(struct sipe_core_public *sipe_public,
333 struct sipe_chat_session *chat_session,
334 const gboolean locked);
337 * Create new session with Focus URI
339 * @param sipe_public (in) SIPE core data.
340 * @param focus_uri (in) focus URI string
342 * @return new SIP session
344 struct sip_session *
345 sipe_core_conf_create(struct sipe_core_public *sipe_public,
346 const gchar *focus_uri);
348 /* buddy menu callback: parameter == chat_session */
349 void sipe_core_conf_make_leader(struct sipe_core_public *sipe_public,
350 gpointer parameter,
351 const gchar *buddy_name);
352 void sipe_core_conf_remove_from(struct sipe_core_public *sipe_public,
353 gpointer parameter,
354 const gchar *buddy_name);
356 /* call control (CSTA) */
357 void sipe_core_buddy_make_call(struct sipe_core_public *sipe_public,
358 const gchar *phone);
360 /* media */
361 void sipe_core_media_initiate_call(struct sipe_core_public *sipe_public,
362 const char *participant,
363 gboolean with_video);
365 * Connects to a conference call specified by given chat session
367 * @param sipe_public (in) SIPE core data.
368 * @param chat_session (in) chat session structure
370 void sipe_core_media_connect_conference(struct sipe_core_public *sipe_public,
371 struct sipe_chat_session *chat_session);
374 * Checks whether there is a media call in progress
376 * @param sipe_public (in) SIPE core data.
378 * @return @c TRUE if media call is in progress
380 gboolean sipe_core_media_in_call(struct sipe_core_public *sipe_public);
383 * Checks voice quality by making a call to the test service
385 * @param sipe_public (in) SIPE core data.
387 void sipe_core_media_test_call(struct sipe_core_public *sipe_public);
389 /* file transfer */
390 struct sipe_file_transfer *sipe_core_ft_allocate(struct sipe_core_public *sipe_public);
391 void sipe_core_ft_deallocate(struct sipe_file_transfer *ft);
392 void sipe_core_ft_cancel(struct sipe_file_transfer *ft);
393 void sipe_core_ft_incoming_init(struct sipe_file_transfer *ft);
394 void sipe_core_ft_outgoing_init(struct sipe_file_transfer *ft,
395 const gchar *filename, gsize size,
396 const gchar *who);
398 void sipe_core_tftp_incoming_start(struct sipe_file_transfer *ft,
399 gsize total_size);
400 gboolean sipe_core_tftp_incoming_stop(struct sipe_file_transfer *ft);
401 void sipe_core_tftp_outgoing_start(struct sipe_file_transfer *ft,
402 gsize total_size);
403 gboolean sipe_core_tftp_outgoing_stop(struct sipe_file_transfer *ft);
404 gssize sipe_core_tftp_read(struct sipe_file_transfer *ft, guchar **buffer,
405 gsize bytes_remaining, gsize bytes_available);
406 gssize sipe_core_tftp_write(struct sipe_file_transfer *ft, const guchar *buffer,
407 gsize size);
408 /* group chat */
409 gboolean sipe_core_groupchat_query_rooms(struct sipe_core_public *sipe_public);
410 void sipe_core_groupchat_join(struct sipe_core_public *sipe_public,
411 const gchar *uri);
413 /* IM */
414 void sipe_core_im_send(struct sipe_core_public *sipe_public,
415 const gchar *who,
416 const gchar *what);
417 void sipe_core_im_close(struct sipe_core_public *sipe_public,
418 const gchar *who);
420 /* user */
421 void sipe_core_user_feedback_typing(struct sipe_core_public *sipe_public,
422 const gchar *to);
424 void sipe_core_user_ask_cb(gpointer key, gboolean accepted);
426 /* groups */
427 void sipe_core_group_rename(struct sipe_core_public *sipe_public,
428 const gchar *old_name,
429 const gchar *new_name);
431 void sipe_core_group_remove(struct sipe_core_public *sipe_public,
432 const gchar *name);
434 /* buddies */
435 void sipe_core_buddy_group(struct sipe_core_public *sipe_public,
436 const gchar *who,
437 const gchar *old_group_name,
438 const gchar *new_group_name);
440 void sipe_core_buddy_search(struct sipe_core_public *sipe_public,
441 const gchar *given_name,
442 const gchar *surname,
443 const gchar *email,
444 const gchar *company,
445 const gchar *country);
447 void sipe_core_buddy_get_info(struct sipe_core_public *sipe_public,
448 const gchar *who);
450 void sipe_core_buddy_new_chat(struct sipe_core_public *sipe_public,
451 const gchar *who);
452 void sipe_core_buddy_send_email(struct sipe_core_public *sipe_public,
453 const gchar *who);
455 struct sipe_backend_buddy_menu;
456 struct sipe_backend_buddy_menu *sipe_core_buddy_create_menu(struct sipe_core_public *sipe_public,
457 const gchar *buddy_name,
458 struct sipe_backend_buddy_menu *menu);
460 void sipe_core_buddy_menu_free(struct sipe_core_public *sipe_public);
462 /* status */
463 void sipe_core_status_set(struct sipe_core_public *sipe_public,
464 guint activity,
465 const gchar *note);
466 void sipe_core_status_idle(struct sipe_core_public *sipe_public);
468 #ifdef __cplusplus
470 #endif
473 Local Variables:
474 mode: c
475 c-file-style: "bsd"
476 indent-tabs-mode: t
477 tab-width: 8
478 End: