chat: add sipe_core_chat_type()
[siplcs.git] / src / api / sipe-core.h
blob37b0f52eaae160755478fd4f819591b2447c20cb
1 /**
2 * @file sipe-core.h
4 * pidgin-sipe
6 * Copyright (C) 2010-2016 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;
81 void (* ft_init)(struct sipe_file_transfer *ft, const gchar *filename,
82 gsize size, const gchar *who);
83 void (* ft_start)(struct sipe_file_transfer *ft, gsize total_size);
84 gssize (* ft_read)(struct sipe_file_transfer *ft, guchar **buffer,
85 gsize bytes_remaining, gsize bytes_available);
86 gssize (* ft_write)(struct sipe_file_transfer *ft, const guchar *buffer,
87 gsize size);
88 gboolean (* ft_end)(struct sipe_file_transfer *ft);
89 void (* ft_request_denied)(struct sipe_file_transfer *ft);
90 void (* ft_cancelled)(struct sipe_file_transfer *ft);
93 /**
94 * Opaque data type for backend private data.
95 * The backend is responsible to allocate and free it.
97 struct sipe_backend_private;
99 /**
100 * SIP transport authentication scheme
102 #define SIPE_AUTHENTICATION_TYPE_UNSET 0
103 #define SIPE_AUTHENTICATION_TYPE_BASIC 1 /* internal use only */
104 #define SIPE_AUTHENTICATION_TYPE_NTLM 2
105 #define SIPE_AUTHENTICATION_TYPE_KERBEROS 3
106 #define SIPE_AUTHENTICATION_TYPE_NEGOTIATE 4 /* internal use only */
107 #define SIPE_AUTHENTICATION_TYPE_TLS_DSK 5
108 #define SIPE_AUTHENTICATION_TYPE_AUTOMATIC 6 /* always last */
111 * Flags
113 /* user disabled calendar information publishing */
114 #define SIPE_CORE_FLAG_DONT_PUBLISH 0x00000001
116 #define SIPE_CORE_FLAG_IS(flag) \
117 ((sipe_public->flags & SIPE_CORE_FLAG_ ## flag) == SIPE_CORE_FLAG_ ## flag)
118 #define SIPE_CORE_FLAG_SET(flag) \
119 (sipe_public->flags |= SIPE_CORE_FLAG_ ## flag)
120 #define SIPE_CORE_FLAG_UNSET(flag) \
121 (sipe_public->flags &= ~SIPE_CORE_FLAG_ ## flag)
124 * Byte length of cryptographic key for call encryption.
126 #define SIPE_SRTP_KEY_LEN 30
129 * Public part of the Sipe data structure
131 * This part contains the information needed by the core and the backend.
133 struct sipe_core_public {
135 * This points to the private data for the backend.
136 * The backend is responsible to allocate and free it.
138 struct sipe_backend_private *backend_private;
140 /* flags (see above) */
141 guint32 flags;
143 /* user information */
144 gchar *sip_name;
145 gchar *sip_domain;
147 /* server information */
148 /* currently nothing */
152 * Initialize & destroy functions for the SIPE core
153 * Should be called on loading and unloading of the plugin.
155 void sipe_core_init(const char *locale_dir);
156 void sipe_core_destroy(void);
158 /** Utility functions exported by the core to backends ***********************/
159 gboolean sipe_strequal(const gchar *left, const gchar *right);
161 GSList *
162 sipe_utils_nameval_add(GSList *list, const gchar *name, const gchar *value);
164 const gchar *
165 sipe_utils_nameval_find(const GSList *list, const gchar *name);
167 const gchar *
168 sipe_utils_nameval_find_instance(const GSList *list, const gchar *name, int which);
170 void
171 sipe_utils_nameval_free(GSList *list);
173 gchar *sip_uri_from_name(const gchar *name);
174 gchar *sip_uri_if_valid(const gchar *string);
176 /*****************************************************************************/
179 * Other functions (need to be sorted once structure becomes clear.
182 /* Get translated about string. Must be g_free'd(). */
183 gchar *sipe_core_about(void);
185 /* Execute a scheduled action */
186 void sipe_core_schedule_execute(gpointer data);
188 /* menu actions */
189 void sipe_core_update_calendar(struct sipe_core_public *sipe_public);
190 void sipe_core_reset_status(struct sipe_core_public *sipe_public);
192 /* access levels */
193 void sipe_core_change_access_level_from_container(struct sipe_core_public *sipe_public,
194 gpointer parameter);
195 void sipe_core_change_access_level_for_domain(struct sipe_core_public *sipe_public,
196 const gchar *domain,
197 guint index);
200 * Activity
201 * - core: maps this to OCS protocol values
202 * maps this to translated descriptions
203 * - backend: maps this to backend status values
204 * backend token string can be used as "ID" in protocol
206 * This is passed back-and-forth and therefore defined as list, not as enum.
207 * Can be used as array index
209 #define SIPE_ACTIVITY_UNSET 0
210 #define SIPE_ACTIVITY_AVAILABLE 1
211 #define SIPE_ACTIVITY_ONLINE 2
212 #define SIPE_ACTIVITY_INACTIVE 3
213 #define SIPE_ACTIVITY_BUSY 4
214 #define SIPE_ACTIVITY_BUSYIDLE 5
215 #define SIPE_ACTIVITY_DND 6
216 #define SIPE_ACTIVITY_BRB 7
217 #define SIPE_ACTIVITY_AWAY 8
218 #define SIPE_ACTIVITY_LUNCH 9
219 #define SIPE_ACTIVITY_INVISIBLE 10
220 #define SIPE_ACTIVITY_OFFLINE 11
221 #define SIPE_ACTIVITY_ON_PHONE 12
222 #define SIPE_ACTIVITY_IN_CONF 13
223 #define SIPE_ACTIVITY_IN_MEETING 14
224 #define SIPE_ACTIVITY_OOF 15
225 #define SIPE_ACTIVITY_URGENT_ONLY 16
226 #define SIPE_ACTIVITY_NUM_TYPES 17 /* use to define array size */
228 const gchar *sipe_core_activity_description(guint type);
230 /* buddy actions */
232 * Get status text for buddy.
234 * @param sipe_public Sipe core public data structure.
235 * @param uri SIP URI of the buddy
236 * @param activity activity value for buddy
237 * @param status_text backend-specific buddy status text for activity.
239 * @return HTML status text for the buddy or NULL. Must be g_free()'d.
241 gchar *sipe_core_buddy_status(struct sipe_core_public *sipe_public,
242 const gchar *uri,
243 guint activity,
244 const gchar *status_text);
246 void sipe_core_buddy_got_status(struct sipe_core_public *sipe_public,
247 const gchar *uri,
248 guint activity);
251 * Trigger generation of buddy information label/text pairs
253 * @param sipe_public Sipe core public data structure.
254 * @param uri SIP URI of the buddy
255 * @param status_text backend-specific buddy status text for ID.
256 * @param is_online backend considers buddy to be online.
257 * @param tooltip opaque backend identifier for tooltip info. This is the
258 * parameter given to @c sipe_backend_buddy_tooltip_add()
260 struct sipe_backend_buddy_tooltip;
261 void sipe_core_buddy_tooltip_info(struct sipe_core_public *sipe_public,
262 const gchar *uri,
263 const gchar *status_name,
264 gboolean is_online,
265 struct sipe_backend_buddy_tooltip *tooltip);
268 * Add a buddy
270 * @param sipe_public Sipe core public data structure
271 * @param uri SIP URI of the buddy
272 * @param group_name backend-specific group name
274 void sipe_core_buddy_add(struct sipe_core_public *sipe_public,
275 const gchar *uri,
276 const gchar *group_name);
279 * Remove a buddy
281 * @param sipe_public Sipe core public data structure
282 * @param uri SIP URI of the buddy
283 * @param group_name backend-specific group name
285 void sipe_core_buddy_remove(struct sipe_core_public *sipe_public,
286 const gchar *uri,
287 const gchar *group_name);
289 void sipe_core_contact_allow_deny(struct sipe_core_public *sipe_public,
290 const gchar *who,
291 gboolean allow);
292 void sipe_core_group_set_alias(struct sipe_core_public *sipe_public,
293 const gchar *who,
294 const gchar *alias);
297 * Setup core data
299 struct sipe_core_public *sipe_core_allocate(const gchar *signin_name,
300 gboolean sso,
301 const gchar *login_account,
302 const gchar *password,
303 const gchar *email,
304 const gchar *email_url,
305 const gchar **errmsg);
306 void sipe_core_deallocate(struct sipe_core_public *sipe_public);
309 * Check if SIP authentication scheme requires a password
311 * NOTE: this can be called *BEFORE* @c sipe_core_allocate()!
313 * @param authentication SIP transport authentication type
314 * @param sso TRUE if user selected Single-Sign On
316 * @return TRUE if password is required
318 gboolean sipe_core_transport_sip_requires_password(guint authentication,
319 gboolean sso);
322 * Connect to SIP server
324 void sipe_core_transport_sip_connect(struct sipe_core_public *sipe_public,
325 guint transport,
326 guint authentication,
327 const gchar *server,
328 const gchar *port);
331 * Get SIP server host name
333 * @param sipe_public Sipe core public data structure
335 * @return server host name (may be @c NULL if not fully connected yet)
337 const gchar *sipe_core_transport_sip_server_name(struct sipe_core_public *sipe_public);
340 * Get chat ID, f.ex. group chat URI
342 const gchar *sipe_core_chat_id(struct sipe_core_public *sipe_public,
343 struct sipe_chat_session *chat_session);
346 * Get type of chat session, e.g. group chat
348 typedef enum {
349 SIPE_CHAT_TYPE_UNKNOWN = 0,
350 SIPE_CHAT_TYPE_MULTIPARTY,
351 SIPE_CHAT_TYPE_CONFERENCE,
352 SIPE_CHAT_TYPE_GROUPCHAT
353 } sipe_chat_type;
354 sipe_chat_type sipe_core_chat_type(struct sipe_chat_session *chat_session);
357 * Invite to chat
359 void sipe_core_chat_invite(struct sipe_core_public *sipe_public,
360 struct sipe_chat_session *chat_session,
361 const char *name);
364 * Rejoin a chat after connection re-establishment
366 void sipe_core_chat_rejoin(struct sipe_core_public *sipe_public,
367 struct sipe_chat_session *chat_session);
370 * Leave a chat
372 void sipe_core_chat_leave(struct sipe_core_public *sipe_public,
373 struct sipe_chat_session *chat_session);
376 * Send message to chat
378 void sipe_core_chat_send(struct sipe_core_public *sipe_public,
379 struct sipe_chat_session *chat_session,
380 const char *what);
383 * Check chat lock status
385 typedef enum {
386 SIPE_CHAT_LOCK_STATUS_NOT_ALLOWED = 0,
387 SIPE_CHAT_LOCK_STATUS_UNLOCKED,
388 SIPE_CHAT_LOCK_STATUS_LOCKED
389 } sipe_chat_lock_status;
390 sipe_chat_lock_status sipe_core_chat_lock_status(struct sipe_core_public *sipe_public,
391 struct sipe_chat_session *chat_session);
394 * Lock chat
396 void sipe_core_chat_modify_lock(struct sipe_core_public *sipe_public,
397 struct sipe_chat_session *chat_session,
398 const gboolean locked);
401 * Create new session with Focus URI
403 * @param sipe_public (in) SIPE core data.
404 * @param focus_uri (in) focus URI string
406 void sipe_core_conf_create(struct sipe_core_public *sipe_public,
407 const gchar *focus_uri,
408 const gchar *organizer,
409 const gchar *meeting_id);
411 /* buddy menu callback: parameter == chat_session */
412 void sipe_core_conf_make_leader(struct sipe_core_public *sipe_public,
413 gpointer parameter,
414 const gchar *buddy_name);
415 void sipe_core_conf_remove_from(struct sipe_core_public *sipe_public,
416 gpointer parameter,
417 const gchar *buddy_name);
419 gchar *
420 sipe_core_conf_entry_info(struct sipe_core_public *sipe_public,
421 struct sipe_chat_session *chat_session);
424 * Checks if given chat session has an open RDP client window.
426 * @param sipe_public (in) SIPE core data.
427 * @param chat_session (in) chat session structure
429 * @return @c TRUE if RDP session is in progress.
431 gboolean
432 sipe_core_conf_is_viewing_appshare(struct sipe_core_public *sipe_public,
433 struct sipe_chat_session *chat_session);
435 /* call control (CSTA) */
436 void sipe_core_buddy_make_call(struct sipe_core_public *sipe_public,
437 const gchar *phone);
439 /* media */
440 void sipe_core_media_initiate_call(struct sipe_core_public *sipe_public,
441 const char *participant,
442 gboolean with_video);
443 struct sipe_media_call;
444 struct sipe_media_stream *
445 sipe_core_media_get_stream_by_id(struct sipe_media_call *call, const gchar *id);
448 * Called by media backend after a candidate pair for a media stream component
449 * has been established.
451 * @param stream (in) SIPE media stream data.
453 void
454 sipe_core_media_stream_candidate_pair_established(struct sipe_media_stream *stream);
456 void
457 sipe_core_media_stream_readable(struct sipe_media_stream *stream);
460 * Called by media backend when a @c SIPE_MEDIA_APPLICATION stream changes its
461 * state between writable and unwritable.
463 * @param stream (in) SIPE media stream data.
464 * @param writable (in) @c TRUE if stream has become writable, otherwise
465 * @c FALSE.
467 void
468 sipe_core_media_stream_writable(struct sipe_media_stream *stream,
469 gboolean writable);
472 * Called by media backend when @c stream has ended and should be destroyed.
474 * @param stream (in) SIPE media stream data.
476 void
477 sipe_core_media_stream_end(struct sipe_media_stream *stream);
480 * Connects to a conference call specified by given chat session
482 * @param sipe_public (in) SIPE core data.
483 * @param chat_session (in) chat session structure
485 void sipe_core_media_connect_conference(struct sipe_core_public *sipe_public,
486 struct sipe_chat_session *chat_session);
489 * Retrieves the media call in progress
491 * The function checks only for voice and video calls, ignoring other types of
492 * data transfers.
494 * @param sipe_public (in) SIPE core data.
496 * @return @c sipe_media_call structure or @c NULL if call is not in progress.
498 struct sipe_media_call *
499 sipe_core_media_get_call(struct sipe_core_public *sipe_public);
502 * Initiates a call with given phone number
504 * @param sipe_public (in) SIPE core data.
505 * @parem phone_number (in) a mobile or landline phone number, i.e. +46123456
507 void sipe_core_media_phone_call(struct sipe_core_public *sipe_public,
508 const gchar *phone_number);
511 * Checks voice quality by making a call to the test service
513 * @param sipe_public (in) SIPE core data.
515 void sipe_core_media_test_call(struct sipe_core_public *sipe_public);
517 /* file transfer */
518 struct sipe_file_transfer *
519 sipe_core_ft_create_outgoing(struct sipe_core_public *sipe_public,
520 const gchar *who,
521 const gchar *file);
523 /* application sharing */
526 * Connects to a meeting's presentation
528 * @param sipe_public (in) SIPE core data.
529 * @param chat_session (in) chat session structure
530 * @param user_must_accept (in) @c TRUE if user should be shown accept/decline
531 * dialog before the action can proceed.
533 void sipe_core_appshare_connect_conference(struct sipe_core_public *sipe_public,
534 struct sipe_chat_session *chat_session,
535 gboolean user_must_accept);
537 /* group chat */
538 gboolean sipe_core_groupchat_query_rooms(struct sipe_core_public *sipe_public);
539 void sipe_core_groupchat_join(struct sipe_core_public *sipe_public,
540 const gchar *uri);
542 /* IM */
543 void sipe_core_im_send(struct sipe_core_public *sipe_public,
544 const gchar *who,
545 const gchar *what);
546 void sipe_core_im_close(struct sipe_core_public *sipe_public,
547 const gchar *who);
549 /* user */
550 void sipe_core_user_feedback_typing(struct sipe_core_public *sipe_public,
551 const gchar *to,
552 gboolean typing);
554 void sipe_core_user_ask_cb(gpointer key, gboolean accepted);
556 /* groups */
557 void sipe_core_group_rename(struct sipe_core_public *sipe_public,
558 const gchar *old_name,
559 const gchar *new_name);
561 void sipe_core_group_remove(struct sipe_core_public *sipe_public,
562 const gchar *name);
564 /* buddies */
565 void sipe_core_buddy_group(struct sipe_core_public *sipe_public,
566 const gchar *who,
567 const gchar *old_group_name,
568 const gchar *new_group_name);
570 struct sipe_backend_search_token;
571 void sipe_core_buddy_search(struct sipe_core_public *sipe_public,
572 struct sipe_backend_search_token *token,
573 const gchar *given_name,
574 const gchar *surname,
575 const gchar *email,
576 const gchar *sipid,
577 const gchar *company,
578 const gchar *country);
580 void sipe_core_buddy_get_info(struct sipe_core_public *sipe_public,
581 const gchar *who);
583 void sipe_core_buddy_new_chat(struct sipe_core_public *sipe_public,
584 const gchar *who);
585 void sipe_core_buddy_send_email(struct sipe_core_public *sipe_public,
586 const gchar *who);
588 struct sipe_backend_buddy_menu;
589 struct sipe_backend_buddy_menu *sipe_core_buddy_create_menu(struct sipe_core_public *sipe_public,
590 const gchar *buddy_name,
591 struct sipe_backend_buddy_menu *menu);
593 void sipe_core_buddy_menu_free(struct sipe_core_public *sipe_public);
596 * User/Machine has changed the user status
598 * NOTE: must *NEVER* be triggered by @c sipe_backend_status_and_note()!
600 * @param sipe_public The handle representing the protocol instance
601 * @param set_by_user @c TRUE if status has been changed by user
602 * @param activity New activity
603 * @param message New note text
605 void sipe_core_status_set(struct sipe_core_public *sipe_public,
606 gboolean set_by_user,
607 guint activity,
608 const gchar *note);
610 #define SIPE_MSRTP_VSR_HEADER_LEN 20
611 #define SIPE_MSRTP_VSR_ENTRY_LEN 0x44
612 #define SIPE_MSRTP_VSR_FCI_WORDLEN \
613 (SIPE_MSRTP_VSR_HEADER_LEN + SIPE_MSRTP_VSR_ENTRY_LEN) / 4
615 #define SIPE_MSRTP_VSR_SOURCE_ANY 0xFFFFFFFE
616 #define SIPE_MSRTP_VSR_SOURCE_NONE 0xFFFFFFFF
619 * Fills @buffer with Video Source Request described in [MS-RTP] 2.2.12.2.
621 * @param buffer (out) destination the VSR will be written to. The byte length
622 * of @c buffer MUST be at least @c SIPE_MSRTP_VSR_HEADER_LEN +
623 * @c SIPE_MSRTP_VSR_ENTRY_LEN.
624 * @param payload_type (in) payload ID of the codec negotiated with the peer.
626 void sipe_core_msrtp_write_video_source_request(guint8 *buffer,
627 guint8 payload_type);
630 * Fills @buffer with customized Payload Content Scalability Information packet
631 * described in [MS-H264PF] consisting of a Stream Layout SEI Message (section
632 * 2.2.5) and a Bitstream Info SEI Message (section 2.2.7).
634 * @param buffer (out) destination the PACSI will be written to.
635 * @param nal_count (in) number of NAL units this packet describes.
637 * @return Byte length of the PACSI packet.
639 gsize sipe_core_msrtp_write_video_scalability_info(guint8 *buffer,
640 guint8 nal_count);
642 #ifdef __cplusplus
644 #endif
647 Local Variables:
648 mode: c
649 c-file-style: "bsd"
650 indent-tabs-mode: t
651 tab-width: 8
652 End: