conf: allow to reject incoming AV conference call
[siplcs.git] / src / core / sipe-utils.h
blob4de8555fc1b6cd44b0cf7977acd1fa569ca1de59
1 /**
2 * @file sipe-utils.h
4 * pidgin-sipe
6 * Copyright (C) 2009-2011 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
24 * Interface dependencies:
26 * <time.h>
27 * <glib.h>
30 /* Forward declarations */
31 struct sipe_core_private;
32 struct sipe_transport_connection;
34 /* Our publication type keys. OCS 2007+
35 * Format: SIPE_PUB_{Category}[_{SubSategory}]
37 /**
38 * device
39 * -
41 * -
42 * Unique to the device.
44 #define SIPE_PUB_DEVICE 0
45 /**
46 * state
47 * Machine state
49 * Availability, activity, end-point location, time zone, and device type.
50 * First hexadecimal digit is 0x3; remaining seven hexadecimal digits are unique per device.
52 #define SIPE_PUB_STATE_MACHINE 3
53 /**
54 * state
55 * User state
57 * Availability and activity.
58 * 0x20000000
60 #define SIPE_PUB_STATE_USER 2
61 /**
62 * state
63 * Calendar state
65 * Availability, activity, meeting subject, and meeting location.
66 * First hexadecimal digit is 0x4; remaining seven hexadecimal digits are unique per device.
68 #define SIPE_PUB_STATE_CALENDAR 4
69 /**
70 * state
71 * Calendar state for an Out of Office meeting
73 * (??)Activity for when a user sets or removes an Out of Office message in Exchange.
74 * (+)user sets in Outlook for an Out of Office meeting
75 * First hexadecimal digit is 0x5; remaining seven hexadecimal digits are unique per device.
77 #define SIPE_PUB_STATE_CALENDAR_OOF 5
78 /**
79 * state
80 * RCC Phone State
82 * Availability and activity for RCC call connect/disconnect or participant count changes from 0 to 2, 2 to N, N to 2, 2 to 0.
83 * First hexadecimal digit is 0x7; remaining seven hexadecimal digits are unique per device.
85 #define SIPE_PUB_STATE_PHONE 7
86 /**
87 * calendarData
88 * Free/busy data
90 * Start time, granularity, and free/busy data.
91 * First hexadecimal digit is 0x4; last seven hexadecimal digits uniquely define the calendar.
93 #define SIPE_PUB_CALENDAR_DATA 400
94 /**
95 * note
96 * Out of Office note
98 * Out of Office note that a user sets in Outlook using the Out of Office assistant.
99 * First hexadecimal digit is 0x4; last seven hexadecimal digits uniquely define the calendar.
101 #define SIPE_PUB_NOTE_OOF 400
104 * Returns epid value.
106 * @param sipe_private (in) SIPE core private data
108 * @return epid. Must be g_free()'d.
110 gchar *
111 get_epid(struct sipe_core_private *sipe_private);
114 * Generate Call ID
116 * @return Call ID. Must be g_free()'d.
118 gchar *gencallid(void);
121 * Generate Tag
123 * @return Tag. Must be g_free()'d.
125 gchar *gentag(void);
128 * Generate conference-id
129 * 32 characters long. Value space is restricted to printable ASCII characters
131 * Ex.: 8386E6AEAAA41E4AA6627BA76D43B6D1
133 * @return conference-id. Must be g_free()'d.
135 gchar *genconfid(void);
138 * Returns instance value for particular publication type.
139 * It should be consistent for the same endpoint
140 * but different between distinct endpoints.
142 * See defined constants for keys patterned SIPE_PUB_*
144 guint
145 sipe_get_pub_instance(struct sipe_core_private *sipe_private,
146 int publication_key);
149 * Get contact information from SIPE account
151 * @param sipe_private (in) SIPE core private data
153 * @return Contact. Must be g_free()'d.
155 gchar *get_contact(const struct sipe_core_private *sipe_private);
158 * Parses URI from SIP header
160 * @param hdr (in) To/From header
162 * @return URI with sip: prefix. Must be g_free()'d.
164 gchar *parse_from(const gchar *hdr);
167 * Create sip: URI from name
169 * @param name (in)
171 * @return URI with sip: prefix. Must be g_free()'d.
173 gchar *sip_uri_from_name(const gchar *name);
176 * Create sip: URI from SIP account user name
178 * @param sipe_private (in) SIPE core private data
180 * @return URI with sip: prefix. Must be g_free()'d.
182 #define sip_uri_self(sipe_private) (sip_uri_from_name(sipe_private->username))
185 * Create sip: URI from name or sip: URI
187 * @param string (in) name or sip: URI
189 * @return URI with sip: prefix. Must be g_free()'d.
191 gchar *sip_uri(const gchar *string);
194 * Tries to figure out if contact alias which stored locally
195 * is just SIP URI, not a proper display name or local alias.
197 * @param uri SIP URI with 'sip:' prefix.
198 * @param alias as returned by purple.
200 gboolean
201 sipe_is_bad_alias(const char *uri,
202 const char *alias);
205 * Checks if provided string is empty - NULL, zero size or just series of white spaces.
206 * Doesn't modify input string.
208 gboolean
209 is_empty(const char *st);
211 /** Returns newly allocated string. Must be g_free()'d */
212 char *
213 replace(const char *st,
214 const char *search,
215 const char *replace);
218 * Message debugging
220 * @param type message type description (SIP or HTTP).
221 * @param header message header
222 * @param body message body or NULL
223 * @param sending TRUE if outgoing message
225 void sipe_utils_message_debug(const gchar *type,
226 const gchar *header,
227 const gchar *body,
228 gboolean sending);
231 * Tests two strings for equality.
233 * Unlike strcmp(), this function will not crash if one or both of the
234 * strings are @c NULL.
236 * Same as purple_strequal (defined only for 2.6) to maintain
237 * our backward compatibility.
239 * @param left A string
240 * @param right A string to compare with left
242 * @return @c TRUE if the strings are the same, else @c FALSE.
245 gboolean sipe_strequal(const gchar *left, const gchar *right);
248 * Tests two strings for equality, ignoring the case
250 * Same as glib @c g_ascii_strcasecmp() but works correctly for @c NULL
251 * pointers too. Plus it doesn't complain loudly about them...
253 * @param left A string
254 * @param right A string to compare with left
256 * @return @c TRUE if the strings are the same, else @c FALSE.
259 gboolean sipe_strcase_equal(const gchar *left, const gchar *right);
262 * Compares two strings
264 * Unlike strcmp(), this function will not crash if one or both of the
265 * strings are @c NULL.
267 * Same as g_strcmp0 (defined only for >= 2.16) to maintain
268 * our backward compatibility. The declaration is compatible to
269 * @c GCompareFunc.
271 * @param a A string
272 * @param b A string to compare with a
274 * @return negative value if a < b; zero if a = b; positive value if a > b.
277 gint sipe_strcompare(gconstpointer a, gconstpointer b);
280 * Parses a timestamp in ISO8601 format and returns a time_t.
281 * Assumes UTC if no timezone specified
283 * @param timestamp The timestamp
285 time_t
286 sipe_utils_str_to_time(const gchar *timestamp);
289 * Converts time_t to ISO8601 string.
290 * Timezone is UTC.
292 * Must be g_free()'d after use.
294 * Example: 2010-02-03T23:59:59Z
296 gchar *
297 sipe_utils_time_to_str(time_t timestamp);
299 struct sipnameval {
300 gchar *name;
301 gchar *value;
305 * Parses string of hex digits to buffer.
306 * Allocates memory.
308 * @param hex_str (in) string of hex digits to convert.
309 * @param buff (out) newly allocated buffer. Must be g_free()'d after use.
311 * @return size of newly allocated buffer
313 size_t
314 hex_str_to_buff(const char *hex_str, guint8 **buff);
317 * Composes hex string out of provided buffer.
318 * Allocates memory.
320 * @param buff input buffer
321 * @param buff_len length of buffer
323 * @result newly allocated hex string representing buffer. Must be g_free()'d after use.
325 char *
326 buff_to_hex_str(const guint8 *buff, const size_t buff_len);
329 * Creates name-value pairs from given lines and appends them to @c list
331 * Lines must be in format 'name [delimiter] value'
333 * @param list a list of @c sipnameval structures
334 * @param lines array of strings in format 'name: value'
335 * @param delimiter sequence of characters between name and value
337 * @return @c FALSE if any of @c lines has incorrect format, @c TRUE otherwise
339 gboolean
340 sipe_utils_parse_lines(GSList **list, gchar **lines, gchar *delimiter);
343 * Adds a name-value pair to @c list
345 * @param list a list of @c sipnameval structures
346 * @param name attribute's name
347 * @param value value of attribute @c name
349 * @return the new start of the GSList
351 GSList *
352 sipe_utils_nameval_add(GSList *list, const gchar *name, const gchar *value);
355 * Finds a value of attribute @c name in @c list
357 * @param list a list of @c sipnameval structures
358 * @param name attribute to find
360 * @return value of @c name or NULL if @c name is not found
362 const gchar *
363 sipe_utils_nameval_find(const GSList *list, const gchar *name);
366 * Returns @c which occurrence of attribute @c name in @c list
368 * @c which is zero based, so 0 means first occurrence of @c name in @c list.
370 * @param list a list of @c sipnameval structures
371 * @param name attribute to find
372 * @param which specifies occurrence of @name in @c list
374 * @return value of @c name or NULL if @c name is not found
376 const gchar *
377 sipe_utils_nameval_find_instance(const GSList *list, const gchar *name, int which);
380 * Frees memory allocated by @c list
382 * @param list a list of @c sipnameval structures
384 void
385 sipe_utils_nameval_free(GSList *list);
388 * Given a string, this replaces one substring with another
389 * and returns a newly allocated string.
391 * @param string the string from which to replace stuff.
392 * @param delimiter the substring you want replaced.
393 * @param replacement the substring you want as replacement.
395 * @return string with the substitution or NULL. Must be g_free()'d after use.
397 gchar *sipe_utils_str_replace(const gchar *string,
398 const gchar *delimiter,
399 const gchar *replacement);
402 * Remove read characters from transport buffer
404 * @param conn the transport connection
405 * @param unread pointer to the first character in the buffer
407 void sipe_utils_shrink_buffer(struct sipe_transport_connection *conn,
408 const gchar *unread);
410 * Returns local IP address suitable for connection.
412 * purple_network_get_my_ip() will not do this, because it might return an
413 * address within 169.254.x.x range that was assigned to interface disconnected
414 * from the network (when multiple network adapters are available). This is a
415 * copy-paste from libpurple's network.c, only change is that link local addresses
416 * are ignored.
418 * Maybe this should be fixed in libpurple or some better solution found.
420 const char * sipe_utils_get_suitable_local_ip(int fd);
423 * Checks whether given IP address belongs to private block as defined in RFC1918
425 * @param ip IPv4 address in "X.X.X.X" format
426 * @return @c TRUE if address is private
428 gboolean sipe_utils_ip_is_private(const char *ip);
431 * Generate presence key
433 * @param uri presence URI
435 * @return key string. Must be g_free()'d after use.
437 gchar *sipe_utils_presence_key(const gchar *uri);
440 * Generate subscription key
442 * @param event event name
443 * @param uri presence URI
445 * @return key string. Must be g_free()'d after use.
447 gchar *sipe_utils_subscription_key(const gchar *event,
448 const gchar *uri);
451 * Decodes a URI into a plain string.
453 * @param string the string to translate.
455 * @return the resulting string. Must be g_free()'d after use.
457 gchar *sipe_utils_uri_unescape(const gchar *string);
460 * Tests whether given string is a Uniform Resource Identifier of audio/video
461 * conference
463 * @param uri a string
464 * @return @c TRUE if the string represents AV conference URI
466 gboolean sipe_utils_is_avconf_uri(const gchar *uri);