Fix sipe_buddy_menu_copy_to_cb when copying buddy not yet in our list
[siplcs.git] / src / core / sipe-utils.h
blobdfd7ac7b313463fdea17b69a47e63ffadaa0d951
1 /**
2 * @file sipe-utils.h
4 * pidgin-sipe
6 * Copyright (C) 2009-2010 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 * Parses CSeq from SIP header
169 * @param hdr (in) CSeqm header
171 * @return int type CSeq value (i.e. without method).
173 int parse_cseq(const gchar *hdr);
176 * Create sip: URI from name
178 * @param name (in)
180 * @return URI with sip: prefix. Must be g_free()'d.
182 gchar *sip_uri_from_name(const gchar *name);
185 * Create sip: URI from SIP account user name
187 * @param sipe_private (in) SIPE core private data
189 * @return URI with sip: prefix. Must be g_free()'d.
191 #define sip_uri_self(sipe_private) (sip_uri_from_name(sipe_private->username))
194 * Create sip: URI from name or sip: URI
196 * @param string (in) name or sip: URI
198 * @return URI with sip: prefix. Must be g_free()'d.
200 gchar *sip_uri(const gchar *string);
203 * Tries to figure out if contact alias which stored locally
204 * is just SIP URI, not a proper display name or local alias.
206 * @param uri SIP URI with 'sip:' prefix.
207 * @param alias as returned by purple.
209 gboolean
210 sipe_is_bad_alias(const char *uri,
211 const char *alias);
214 * Checks if provided string is empty - NULL, zero size or just series of white spaces.
215 * Doesn't modify input string.
217 gboolean
218 is_empty(const char *st);
220 /** Returns newly allocated string. Must be g_free()'d */
221 char *
222 replace(const char *st,
223 const char *search,
224 const char *replace);
227 * Message debugging
229 * @param type message type description (SIP or HTTP).
230 * @param header message header
231 * @param body message body or NULL
232 * @param sending TRUE if outgoing message
234 void sipe_utils_message_debug(const gchar *type,
235 const gchar *header,
236 const gchar *body,
237 gboolean sending);
240 * Tests two strings for equality.
242 * Unlike strcmp(), this function will not crash if one or both of the
243 * strings are @c NULL.
245 * Same as purple_strequal (defined only for 2.6) to maintain
246 * our backward compatibility.
248 * @param left A string
249 * @param right A string to compare with left
251 * @return @c TRUE if the strings are the same, else @c FALSE.
254 gboolean sipe_strequal(const gchar *left, const gchar *right);
257 * Tests two strings for equality, ignoring the case
259 * Same as glib @c g_ascii_strcasecmp() but works correctly for @c NULL
260 * pointers too. Plus it doesn't complain loudly about them...
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_strcase_equal(const gchar *left, const gchar *right);
271 * Compares two strings
273 * Unlike strcmp(), this function will not crash if one or both of the
274 * strings are @c NULL.
276 * Same as g_strcmp0 (defined only for >= 2.16) to maintain
277 * our backward compatibility. The declaration is compatible to
278 * @c GCompareFunc.
280 * @param a A string
281 * @param b A string to compare with a
283 * @return negative value if a < b; zero if a = b; positive value if a > b.
286 gint sipe_strcompare(gconstpointer a, gconstpointer b);
289 * Parses a timestamp in ISO8601 format and returns a time_t.
290 * Assumes UTC if no timezone specified
292 * @param timestamp The timestamp
294 time_t
295 sipe_utils_str_to_time(const gchar *timestamp);
298 * Converts time_t to ISO8601 string.
299 * Timezone is UTC.
301 * Must be g_free()'d after use.
303 * Example: 2010-02-03T23:59:59Z
305 gchar *
306 sipe_utils_time_to_str(time_t timestamp);
308 struct sipnameval {
309 gchar *name;
310 gchar *value;
314 * Parses string of hex digits to buffer.
315 * Allocates memory.
317 * @param hex_str (in) string of hex digits to convert.
318 * @param buff (out) newly allocated buffer. Must be g_free()'d after use.
320 * @return size of newly allocated buffer
322 size_t
323 hex_str_to_buff(const char *hex_str, guint8 **buff);
326 * Composes hex string out of provided buffer.
327 * Allocates memory.
329 * @param buff input buffer
330 * @param buff_len length of buffer
332 * @result newly allocated hex string representing buffer. Must be g_free()'d after use.
334 char *
335 buff_to_hex_str(const guint8 *buff, const size_t buff_len);
338 * Creates name-value pairs from given lines and appends them to @c list
340 * Lines must be in format 'name [delimiter] value'
342 * @param list a list of @c sipnameval structures
343 * @param lines array of strings in format 'name: value'
344 * @param delimiter sequence of characters between name and value
346 * @return @c FALSE if any of @c lines has incorrect format, @c TRUE otherwise
348 gboolean
349 sipe_utils_parse_lines(GSList **list, gchar **lines, gchar *delimiter);
352 * Adds a name-value pair to @c list
354 * @param list a list of @c sipnameval structures
355 * @param name attribute's name
356 * @param value value of attribute @c name
358 * @return the new start of the GSList
360 GSList *
361 sipe_utils_nameval_add(GSList *list, const gchar *name, const gchar *value);
364 * Finds a value of attribute @c name in @c list
366 * @param list a list of @c sipnameval structures
367 * @param name attribute to find
369 * @return value of @c name or NULL if @c name is not found
371 const gchar *
372 sipe_utils_nameval_find(const GSList *list, const gchar *name);
375 * Returns @c which occurrence of attribute @c name in @c list
377 * @c which is zero based, so 0 means first occurrence of @c name in @c list.
379 * @param list a list of @c sipnameval structures
380 * @param name attribute to find
381 * @param which specifies occurrence of @name in @c list
383 * @return value of @c name or NULL if @c name is not found
385 const gchar *
386 sipe_utils_nameval_find_instance(const GSList *list, const gchar *name, int which);
389 * Frees memory allocated by @c list
391 * @param list a list of @c sipnameval structures
393 void
394 sipe_utils_nameval_free(GSList *list);
397 * Given a string, this replaces one substring with another
398 * and returns a newly allocated string.
400 * @param string the string from which to replace stuff.
401 * @param delimiter the substring you want replaced.
402 * @param replacement the substring you want as replacement.
404 * @return string with the substitution or NULL. Must be g_free()'d after use.
406 gchar *sipe_utils_str_replace(const gchar *string,
407 const gchar *delimiter,
408 const gchar *replacement);
411 * Remove read characters from transport buffer
413 * @param conn the transport connection
414 * @param unread pointer to the first character in the buffer
416 void sipe_utils_shrink_buffer(struct sipe_transport_connection *conn,
417 const gchar *unread);
419 * Returns local IP address suitable for connection.
421 * purple_network_get_my_ip() will not do this, because it might return an
422 * address within 169.254.x.x range that was assigned to interface disconnected
423 * from the network (when multiple network adapters are available). This is a
424 * copy-paste from libpurple's network.c, only change is that link local addresses
425 * are ignored.
427 * Maybe this should be fixed in libpurple or some better solution found.
429 const char * sipe_utils_get_suitable_local_ip(int fd);
432 * Generate presence key
434 * @param uri presence URI
436 * @return key string. Must be g_free()'d after use.
438 gchar *sipe_utils_presence_key(const gchar *uri);
441 * Generate subscription key
443 * @param event event name
444 * @param uri presence URI
446 * @return key string. Must be g_free()'d after use.
448 gchar *sipe_utils_subscription_key(const gchar *event,
449 const gchar *uri);