filetransfer: use 'read' callback in sipe_file_transfer
[siplcs.git] / src / api / sipe-core.h
blob83ef5bbed2f5f446caf34938e96fbf88e3dc8535
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;
81 void (* init)(struct sipe_file_transfer *ft, const gchar *filename,
82 gsize size, const gchar *who);
83 void (* start)(struct sipe_file_transfer *ft, gsize total_size);
84 gssize (* read)(struct sipe_file_transfer *ft, guchar **buffer,
85 gsize bytes_remaining, gsize bytes_available);
86 gboolean (* end)(struct sipe_file_transfer *ft);
87 void (* request_denied)(struct sipe_file_transfer *ft);
88 void (* deallocate)(struct sipe_file_transfer *ft);
91 /**
92 * Opaque data type for backend private data.
93 * The backend is responsible to allocate and free it.
95 struct sipe_backend_private;
97 /**
98 * SIP transport authentication scheme
100 #define SIPE_AUTHENTICATION_TYPE_UNSET 0
101 #define SIPE_AUTHENTICATION_TYPE_BASIC 1 /* internal use only */
102 #define SIPE_AUTHENTICATION_TYPE_NTLM 2
103 #define SIPE_AUTHENTICATION_TYPE_KERBEROS 3
104 #define SIPE_AUTHENTICATION_TYPE_NEGOTIATE 4 /* internal use only */
105 #define SIPE_AUTHENTICATION_TYPE_TLS_DSK 5
106 #define SIPE_AUTHENTICATION_TYPE_AUTOMATIC 6 /* always last */
109 * Flags
111 /* user disabled calendar information publishing */
112 #define SIPE_CORE_FLAG_DONT_PUBLISH 0x00000001
114 #define SIPE_CORE_FLAG_IS(flag) \
115 ((sipe_public->flags & SIPE_CORE_FLAG_ ## flag) == SIPE_CORE_FLAG_ ## flag)
116 #define SIPE_CORE_FLAG_SET(flag) \
117 (sipe_public->flags |= SIPE_CORE_FLAG_ ## flag)
118 #define SIPE_CORE_FLAG_UNSET(flag) \
119 (sipe_public->flags &= ~SIPE_CORE_FLAG_ ## flag)
122 * Byte length of cryptographic key for call encryption.
124 #define SIPE_SRTP_KEY_LEN 30
127 * Public part of the Sipe data structure
129 * This part contains the information needed by the core and the backend.
131 struct sipe_core_public {
133 * This points to the private data for the backend.
134 * The backend is responsible to allocate and free it.
136 struct sipe_backend_private *backend_private;
138 /* flags (see above) */
139 guint32 flags;
141 /* user information */
142 gchar *sip_name;
143 gchar *sip_domain;
145 /* server information */
146 /* currently nothing */
150 * Initialize & destroy functions for the SIPE core
151 * Should be called on loading and unloading of the plugin.
153 void sipe_core_init(const char *locale_dir);
154 void sipe_core_destroy(void);
156 /** Utility functions exported by the core to backends ***********************/
157 gboolean sipe_strequal(const gchar *left, const gchar *right);
159 GSList *
160 sipe_utils_nameval_add(GSList *list, const gchar *name, const gchar *value);
162 const gchar *
163 sipe_utils_nameval_find(const GSList *list, const gchar *name);
165 const gchar *
166 sipe_utils_nameval_find_instance(const GSList *list, const gchar *name, int which);
168 void
169 sipe_utils_nameval_free(GSList *list);
171 gchar *sip_uri_from_name(const gchar *name);
172 gchar *sip_uri_if_valid(const gchar *string);
174 /*****************************************************************************/
177 * Other functions (need to be sorted once structure becomes clear.
180 /* Get translated about string. Must be g_free'd(). */
181 gchar *sipe_core_about(void);
183 /* Execute a scheduled action */
184 void sipe_core_schedule_execute(gpointer data);
186 /* menu actions */
187 void sipe_core_update_calendar(struct sipe_core_public *sipe_public);
188 void sipe_core_reset_status(struct sipe_core_public *sipe_public);
190 /* access levels */
191 void sipe_core_change_access_level_from_container(struct sipe_core_public *sipe_public,
192 gpointer parameter);
193 void sipe_core_change_access_level_for_domain(struct sipe_core_public *sipe_public,
194 const gchar *domain,
195 guint index);
198 * Activity
199 * - core: maps this to OCS protocol values
200 * maps this to translated descriptions
201 * - backend: maps this to backend status values
202 * backend token string can be used as "ID" in protocol
204 * This is passed back-and-forth and therefore defined as list, not as enum.
205 * Can be used as array index
207 #define SIPE_ACTIVITY_UNSET 0
208 #define SIPE_ACTIVITY_AVAILABLE 1
209 #define SIPE_ACTIVITY_ONLINE 2
210 #define SIPE_ACTIVITY_INACTIVE 3
211 #define SIPE_ACTIVITY_BUSY 4
212 #define SIPE_ACTIVITY_BUSYIDLE 5
213 #define SIPE_ACTIVITY_DND 6
214 #define SIPE_ACTIVITY_BRB 7
215 #define SIPE_ACTIVITY_AWAY 8
216 #define SIPE_ACTIVITY_LUNCH 9
217 #define SIPE_ACTIVITY_INVISIBLE 10
218 #define SIPE_ACTIVITY_OFFLINE 11
219 #define SIPE_ACTIVITY_ON_PHONE 12
220 #define SIPE_ACTIVITY_IN_CONF 13
221 #define SIPE_ACTIVITY_IN_MEETING 14
222 #define SIPE_ACTIVITY_OOF 15
223 #define SIPE_ACTIVITY_URGENT_ONLY 16
224 #define SIPE_ACTIVITY_NUM_TYPES 17 /* use to define array size */
226 const gchar *sipe_core_activity_description(guint type);
228 /* buddy actions */
230 * Get status text for buddy.
232 * @param sipe_public Sipe core public data structure.
233 * @param uri SIP URI of the buddy
234 * @param activity activity value for buddy
235 * @param status_text backend-specific buddy status text for activity.
237 * @return HTML status text for the buddy or NULL. Must be g_free()'d.
239 gchar *sipe_core_buddy_status(struct sipe_core_public *sipe_public,
240 const gchar *uri,
241 guint activity,
242 const gchar *status_text);
244 void sipe_core_buddy_got_status(struct sipe_core_public *sipe_public,
245 const gchar *uri,
246 guint activity);
249 * Trigger generation of buddy information label/text pairs
251 * @param sipe_public Sipe core public data structure.
252 * @param uri SIP URI of the buddy
253 * @param status_text backend-specific buddy status text for ID.
254 * @param is_online backend considers buddy to be online.
255 * @param tooltip opaque backend identifier for tooltip info. This is the
256 * parameter given to @c sipe_backend_buddy_tooltip_add()
258 struct sipe_backend_buddy_tooltip;
259 void sipe_core_buddy_tooltip_info(struct sipe_core_public *sipe_public,
260 const gchar *uri,
261 const gchar *status_name,
262 gboolean is_online,
263 struct sipe_backend_buddy_tooltip *tooltip);
266 * Add a buddy
268 * @param sipe_public Sipe core public data structure
269 * @param uri SIP URI of the buddy
270 * @param group_name backend-specific group name
272 void sipe_core_buddy_add(struct sipe_core_public *sipe_public,
273 const gchar *uri,
274 const gchar *group_name);
277 * Remove a buddy
279 * @param sipe_public Sipe core public data structure
280 * @param uri SIP URI of the buddy
281 * @param group_name backend-specific group name
283 void sipe_core_buddy_remove(struct sipe_core_public *sipe_public,
284 const gchar *uri,
285 const gchar *group_name);
287 void sipe_core_contact_allow_deny(struct sipe_core_public *sipe_public,
288 const gchar *who,
289 gboolean allow);
290 void sipe_core_group_set_alias(struct sipe_core_public *sipe_public,
291 const gchar *who,
292 const gchar *alias);
295 * Setup core data
297 struct sipe_core_public *sipe_core_allocate(const gchar *signin_name,
298 gboolean sso,
299 const gchar *login_account,
300 const gchar *password,
301 const gchar *email,
302 const gchar *email_url,
303 const gchar **errmsg);
304 void sipe_core_deallocate(struct sipe_core_public *sipe_public);
307 * Check if SIP authentication scheme requires a password
309 * NOTE: this can be called *BEFORE* @c sipe_core_allocate()!
311 * @param authentication SIP transport authentication type
312 * @param sso TRUE if user selected Single-Sign On
314 * @return TRUE if password is required
316 gboolean sipe_core_transport_sip_requires_password(guint authentication,
317 gboolean sso);
320 * Connect to SIP server
322 void sipe_core_transport_sip_connect(struct sipe_core_public *sipe_public,
323 guint transport,
324 guint authentication,
325 const gchar *server,
326 const gchar *port);
329 * Get SIP server host name
331 * @param sipe_public Sipe core public data structure
333 * @return server host name (may be @c NULL if not fully connected yet)
335 const gchar *sipe_core_transport_sip_server_name(struct sipe_core_public *sipe_public);
338 * Get chat ID, f.ex. group chat URI
340 const gchar *sipe_core_chat_id(struct sipe_core_public *sipe_public,
341 struct sipe_chat_session *chat_session);
344 * Invite to chat
346 void sipe_core_chat_invite(struct sipe_core_public *sipe_public,
347 struct sipe_chat_session *chat_session,
348 const char *name);
351 * Rejoin a chat after connection re-establishment
353 void sipe_core_chat_rejoin(struct sipe_core_public *sipe_public,
354 struct sipe_chat_session *chat_session);
357 * Leave a chat
359 void sipe_core_chat_leave(struct sipe_core_public *sipe_public,
360 struct sipe_chat_session *chat_session);
363 * Send message to chat
365 void sipe_core_chat_send(struct sipe_core_public *sipe_public,
366 struct sipe_chat_session *chat_session,
367 const char *what);
370 * Check chat lock status
372 typedef enum {
373 SIPE_CHAT_LOCK_STATUS_NOT_ALLOWED = 0,
374 SIPE_CHAT_LOCK_STATUS_UNLOCKED,
375 SIPE_CHAT_LOCK_STATUS_LOCKED
376 } sipe_chat_lock_status;
377 sipe_chat_lock_status sipe_core_chat_lock_status(struct sipe_core_public *sipe_public,
378 struct sipe_chat_session *chat_session);
381 * Lock chat
383 void sipe_core_chat_modify_lock(struct sipe_core_public *sipe_public,
384 struct sipe_chat_session *chat_session,
385 const gboolean locked);
388 * Create new session with Focus URI
390 * @param sipe_public (in) SIPE core data.
391 * @param focus_uri (in) focus URI string
393 void sipe_core_conf_create(struct sipe_core_public *sipe_public,
394 const gchar *focus_uri);
396 /* buddy menu callback: parameter == chat_session */
397 void sipe_core_conf_make_leader(struct sipe_core_public *sipe_public,
398 gpointer parameter,
399 const gchar *buddy_name);
400 void sipe_core_conf_remove_from(struct sipe_core_public *sipe_public,
401 gpointer parameter,
402 const gchar *buddy_name);
404 gchar *
405 sipe_core_conf_entry_info(struct sipe_core_public *sipe_public,
406 struct sipe_chat_session *chat_session);
408 /* call control (CSTA) */
409 void sipe_core_buddy_make_call(struct sipe_core_public *sipe_public,
410 const gchar *phone);
412 /* media */
413 void sipe_core_media_initiate_call(struct sipe_core_public *sipe_public,
414 const char *participant,
415 gboolean with_video);
416 struct sipe_media_call;
417 struct sipe_media_stream *
418 sipe_core_media_get_stream_by_id(struct sipe_media_call *call, const gchar *id);
421 * Connects to a conference call specified by given chat session
423 * @param sipe_public (in) SIPE core data.
424 * @param chat_session (in) chat session structure
426 void sipe_core_media_connect_conference(struct sipe_core_public *sipe_public,
427 struct sipe_chat_session *chat_session);
430 * Checks whether there is a media call in progress
432 * @param sipe_public (in) SIPE core data.
434 * @return @c TRUE if media call is in progress
436 gboolean sipe_core_media_in_call(struct sipe_core_public *sipe_public);
439 * Initiates a call with given phone number
441 * @param sipe_public (in) SIPE core data.
442 * @parem phone_number (in) a mobile or landline phone number, i.e. +46123456
444 void sipe_core_media_phone_call(struct sipe_core_public *sipe_public,
445 const gchar *phone_number);
448 * Checks voice quality by making a call to the test service
450 * @param sipe_public (in) SIPE core data.
452 void sipe_core_media_test_call(struct sipe_core_public *sipe_public);
454 /* file transfer */
455 struct sipe_file_transfer *sipe_core_ft_allocate(struct sipe_core_public *sipe_public);
457 gssize sipe_core_tftp_write(struct sipe_file_transfer *ft, const guchar *buffer,
458 gsize size);
459 /* group chat */
460 gboolean sipe_core_groupchat_query_rooms(struct sipe_core_public *sipe_public);
461 void sipe_core_groupchat_join(struct sipe_core_public *sipe_public,
462 const gchar *uri);
464 /* IM */
465 void sipe_core_im_send(struct sipe_core_public *sipe_public,
466 const gchar *who,
467 const gchar *what);
468 void sipe_core_im_close(struct sipe_core_public *sipe_public,
469 const gchar *who);
471 /* user */
472 void sipe_core_user_feedback_typing(struct sipe_core_public *sipe_public,
473 const gchar *to,
474 gboolean typing);
476 void sipe_core_user_ask_cb(gpointer key, gboolean accepted);
478 /* groups */
479 void sipe_core_group_rename(struct sipe_core_public *sipe_public,
480 const gchar *old_name,
481 const gchar *new_name);
483 void sipe_core_group_remove(struct sipe_core_public *sipe_public,
484 const gchar *name);
486 /* buddies */
487 void sipe_core_buddy_group(struct sipe_core_public *sipe_public,
488 const gchar *who,
489 const gchar *old_group_name,
490 const gchar *new_group_name);
492 struct sipe_backend_search_token;
493 void sipe_core_buddy_search(struct sipe_core_public *sipe_public,
494 struct sipe_backend_search_token *token,
495 const gchar *given_name,
496 const gchar *surname,
497 const gchar *email,
498 const gchar *sipid,
499 const gchar *company,
500 const gchar *country);
502 void sipe_core_buddy_get_info(struct sipe_core_public *sipe_public,
503 const gchar *who);
505 void sipe_core_buddy_new_chat(struct sipe_core_public *sipe_public,
506 const gchar *who);
507 void sipe_core_buddy_send_email(struct sipe_core_public *sipe_public,
508 const gchar *who);
510 struct sipe_backend_buddy_menu;
511 struct sipe_backend_buddy_menu *sipe_core_buddy_create_menu(struct sipe_core_public *sipe_public,
512 const gchar *buddy_name,
513 struct sipe_backend_buddy_menu *menu);
515 void sipe_core_buddy_menu_free(struct sipe_core_public *sipe_public);
518 * User/Machine has changed the user status
520 * NOTE: must *NEVER* be triggered by @c sipe_backend_status_and_note()!
522 * @param sipe_public The handle representing the protocol instance
523 * @param set_by_user @c TRUE if status has been changed by user
524 * @param activity New activity
525 * @param message New note text
527 void sipe_core_status_set(struct sipe_core_public *sipe_public,
528 gboolean set_by_user,
529 guint activity,
530 const gchar *note);
532 #ifdef __cplusplus
534 #endif
537 Local Variables:
538 mode: c
539 c-file-style: "bsd"
540 indent-tabs-mode: t
541 tab-width: 8
542 End: