Release 1.25.0 -- Buddy Idle Time, RTF
[siplcs.git] / src / core / sipe-utils.h
blob0d408bf6d8a63f207afd0269f5c1ac8bd16b3f29
1 /**
2 * @file sipe-utils.h
4 * pidgin-sipe
6 * Copyright (C) 2009-2019 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_RCC 7
86 /**
87 * state
88 * VOIP Phone State
90 * Availability and activity for VOIP call connect/disconnect or participant count changes from 0 to 2, 2 to N, N to 2, 2 to 0.
91 * First hexadecimal digit is 0x8; remaining seven hexadecimal digits uniquely define the SIP URI and device.
93 #define SIPE_PUB_STATE_PHONE_VOIP 8
94 /**
95 * calendarData
96 * Free/busy data
98 * Start time, granularity, and free/busy data.
99 * First hexadecimal digit is 0x4; last seven hexadecimal digits uniquely define the calendar.
101 #define SIPE_PUB_CALENDAR_DATA 400
103 * note
104 * Out of Office note
106 * Out of Office note that a user sets in Outlook using the Out of Office assistant.
107 * First hexadecimal digit is 0x4; last seven hexadecimal digits uniquely define the calendar.
109 #define SIPE_PUB_NOTE_OOF 400
112 * Returns UUID value.
114 * @param sipe_private (in) SIPE core private data
116 * @return uuid. Must be g_free()'d.
118 gchar *
119 get_uuid(struct sipe_core_private *sipe_private);
122 * Generate Call ID
124 * @return Call ID. Must be g_free()'d.
126 gchar *gencallid(void);
129 * Generate Tag
131 * @return Tag. Must be g_free()'d.
133 gchar *gentag(void);
136 * Generate conference-id
137 * 32 characters long. Value space is restricted to printable ASCII characters
139 * Ex.: 8386E6AEAAA41E4AA6627BA76D43B6D1
141 * @return conference-id. Must be g_free()'d.
143 gchar *genconfid(void);
146 * Returns instance value for particular publication type.
147 * It should be consistent for the same endpoint
148 * but different between distinct endpoints.
150 * See defined constants for keys patterned SIPE_PUB_*
152 guint
153 sipe_get_pub_instance(struct sipe_core_private *sipe_private,
154 int publication_key);
157 * Get contact information from SIPE account
159 * @param sipe_private (in) SIPE core private data
161 * @return Contact. Must be g_free()'d.
163 gchar *get_contact(const struct sipe_core_private *sipe_private);
166 * Parses URI from SIP header
168 * @param hdr (in) To/From header
170 * @return URI with sip: prefix. Must be g_free()'d.
172 gchar *parse_from(const gchar *hdr);
175 * Create sip: URI from name
177 * @param name (in)
179 * @return URI with sip: prefix. Must be g_free()'d.
181 gchar *sip_uri_from_name(const gchar *name);
184 * Create sip: URI from SIP account user name
186 * @param sipe_private (in) SIPE core private data
188 * @return URI with sip: prefix. Must be g_free()'d.
190 #define sip_uri_self(sipe_private) (sip_uri_from_name(sipe_private->username))
193 * Create sip: URI from name or sip: URI
195 * @param string (in) name or sip: URI
197 * @return URI with sip: prefix. Must be g_free()'d.
199 gchar *sip_uri(const gchar *string);
202 * Create sip: URI from name or sip: URI. Checks for invalid characters
204 * @param string (in) name or sip: URI
206 * @return URI with sip: prefix. Returns NULL if @c string contains invalid
207 * characters. Must be g_free()'d.
209 gchar *sip_uri_if_valid(const gchar *string);
212 * Returns pointer to URI without sip: prefix if any (doesn't allocate memory)
214 * @param sip_uri SIP URI possibly with sip: prefix. Example: sip:first.last@hq.company.com
216 * @return pointer to URL without sip: prefix. Coresponding example: first.last@hq.company.com
218 const gchar *sipe_get_no_sip_uri(const gchar *sip_uri);
221 * Tries to figure out if contact alias which stored locally
222 * is just SIP URI, not a proper display name or local alias.
224 * @param uri SIP URI with 'sip:' prefix.
225 * @param alias as returned by purple.
227 gboolean
228 sipe_is_bad_alias(const char *uri,
229 const char *alias);
232 * Checks if provided string is empty - NULL, zero size or just series of white spaces.
233 * Doesn't modify input string.
235 gboolean
236 is_empty(const char *st);
239 * Message debugging
241 * @param transport the transport connection
242 * @param type message type description (SIP or HTTP).
243 * @param header message header
244 * @param body message body or NULL
245 * @param sending TRUE if outgoing message
247 void sipe_utils_message_debug(struct sipe_transport_connection *conn,
248 const gchar *type,
249 const gchar *header,
250 const gchar *body,
251 gboolean sending);
254 * Tests two strings for equality.
256 * Unlike strcmp(), this function will not crash if one or both of the
257 * strings are @c NULL.
259 * Same as purple_strequal (defined only for 2.6) to maintain
260 * our backward compatibility.
262 * @param left A string
263 * @param right A string to compare with left
265 * @return @c TRUE if the strings are the same, else @c FALSE.
268 gboolean sipe_strequal(const gchar *left, const gchar *right);
271 * Tests two strings for equality, ignoring the case
273 * Same as glib @c g_ascii_strcasecmp() but works correctly for @c NULL
274 * pointers too. Plus it doesn't complain loudly about them...
276 * @param left A string
277 * @param right A string to compare with left
279 * @return @c TRUE if the strings are the same, else @c FALSE.
282 gboolean sipe_strcase_equal(const gchar *left, const gchar *right);
285 * Parses a timestamp in ISO8601 format and returns a time_t.
286 * Assumes UTC if no timezone specified
288 * @param timestamp The timestamp (may be @c NULL)
290 * @return time_t or 0 if timestamp parsing failed
292 time_t
293 sipe_utils_str_to_time(const gchar *timestamp);
296 * Converts time_t to ISO8601 string.
297 * Timezone is UTC.
299 * Must be g_free()'d after use.
301 * Example: 2010-02-03T23:59:59Z
303 gchar *
304 sipe_utils_time_to_str(time_t timestamp);
307 * Converts struct tm to human readable string
309 * Example: Sat Feb 28 11:07:35 2015
311 * @return pointer to static buffer. Will never return @c NULL.
313 const gchar *sipe_utils_time_to_debug_str(const struct tm *tm);
315 struct sipnameval {
316 gchar *name;
317 gchar *value;
321 * Parses string of hex digits to buffer.
322 * Allocates memory.
324 * @param hex_str (in) string of hex digits to convert.
325 * @param buff (out) newly allocated buffer. Must be g_free()'d after use.
327 * @return size of newly allocated buffer
329 size_t
330 hex_str_to_buff(const char *hex_str, guint8 **buff);
333 * Composes hex string out of provided buffer.
334 * Allocates memory.
336 * @param buff input buffer
337 * @param buff_len length of buffer
339 * @result newly allocated hex string representing buffer. Must be g_free()'d after use.
341 char *
342 buff_to_hex_str(const guint8 *buff, const size_t buff_len);
345 * Creates name-value pairs from given lines and appends them to @c list
347 * Lines must be in format 'name [delimiter] value'
349 * @param list a list of @c sipnameval structures
350 * @param lines array of strings in format 'name: value'
351 * @param delimiter sequence of characters between name and value
353 * @return @c FALSE if any of @c lines has incorrect format, @c TRUE otherwise
355 gboolean
356 sipe_utils_parse_lines(GSList **list, gchar **lines, const gchar *delimiter);
359 * Adds a name-value pair to @c list
361 * @param list a list of @c sipnameval structures
362 * @param name attribute's name
363 * @param value value of attribute @c name
365 * @return the new start of the GSList
367 GSList *
368 sipe_utils_nameval_add(GSList *list, const gchar *name, const gchar *value);
371 * Finds a value of attribute @c name in @c list
373 * @param list a list of @c sipnameval structures
374 * @param name attribute to find
376 * @return value of @c name or NULL if @c name is not found
378 const gchar *
379 sipe_utils_nameval_find(const GSList *list, const gchar *name);
382 * Returns @c which occurrence of attribute @c name in @c list
384 * @c which is zero based, so 0 means first occurrence of @c name in @c list.
386 * @param list a list of @c sipnameval structures
387 * @param name attribute to find
388 * @param which specifies occurrence of @name in @c list
390 * @return value of @c name or NULL if @c name is not found
392 const gchar *
393 sipe_utils_nameval_find_instance(const GSList *list, const gchar *name, int which);
396 * Frees memory allocated by @c list
398 * @param list a list of @c sipnameval structures
400 void
401 sipe_utils_nameval_free(GSList *list);
404 * Given a string, this replaces one substring with another
405 * and returns a newly allocated string.
407 * @param string the string from which to replace stuff.
408 * @param delimiter the substring you want replaced.
409 * @param replacement the substring you want as replacement.
411 * @return string with the substitution or NULL. Must be g_free()'d after use.
413 gchar *sipe_utils_str_replace(const gchar *string,
414 const gchar *delimiter,
415 const gchar *replacement);
418 * Remove read characters from transport buffer
420 * @param conn the transport connection
421 * @param unread pointer to the first character in the buffer
423 void sipe_utils_shrink_buffer(struct sipe_transport_connection *conn,
424 const gchar *unread);
426 * Checks whether given IP address belongs to private block as defined in RFC1918
428 * @param ip IPv4 address in "X.X.X.X" format
429 * @return @c TRUE if address is private
431 gboolean sipe_utils_ip_is_private(const char *ip);
434 * Get SDP address marker for IP address
436 * @param ip address
438 * @return address marker string for IP address
440 const gchar *sipe_utils_ip_sdp_address_marker(const gchar *ip);
443 * Generate presence key
445 * @param uri presence URI
447 * @return key string. Must be g_free()'d after use.
449 gchar *sipe_utils_presence_key(const gchar *uri);
452 * Decodes a URI into a plain string.
454 * @param string the string to translate.
456 * @return the resulting string. Must be g_free()'d after use.
458 gchar *sipe_utils_uri_unescape(const gchar *string);
461 * Inserts in item in the list only if the value isn't already in that list
463 * @param list a singly linked list
464 * @param data the item to insert. Will not be copied.
465 * @param func function to use to compare the values
466 * @param destroy if @c NULL call to destroy @c data if is already on list
468 * @return the new list head
470 GSList *sipe_utils_slist_insert_unique_sorted(GSList *list,
471 gpointer data,
472 GCompareFunc func,
473 GDestroyNotify destroy);
476 * Same as @c g_slist_free_full() which is only defined for >= 2.28
478 * @param list a singly linked list
479 * @param free function to free list data
481 void sipe_utils_slist_free_full(GSList *list,
482 GDestroyNotify free);