interface cleanup: decouple header files
[siplcs.git] / src / core / sipe-utils.h
blob78567e4d665757b5ebf4fa4be058ee45b8a3d9be
1 /**
2 * @file sipe-utils.h
4 * pidgin-sipe
6 * Copyright (C) 2009 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_account_data;
32 struct _xmlnode;
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.
105 * Uses cache.
107 gchar *
108 get_epid(struct sipe_account_data *sip);
111 * Generate Call ID
113 * @return Call ID. Must be g_free()'d.
115 gchar *gencallid(void);
118 * Generate Tag
120 * @return Tag. Must be g_free()'d.
122 gchar *gentag(void);
125 * Generate conference-id
126 * 32 characters long. Value space is restricted to printable ASCII characters
128 * Ex.: 8386E6AEAAA41E4AA6627BA76D43B6D1
130 * @return conference-id. Must be g_free()'d.
132 gchar *genconfid(void);
135 * Returns instance value for particular publication type.
136 * It should be consistent for the same endpoint
137 * but different between distinct endpoints.
139 * See defined constants for keys patterned SIPE_PUB_*
141 guint
142 sipe_get_pub_instance(struct sipe_account_data *sip,
143 int publication_key);
146 * Get contact information from SIPE account
148 * @param sip (in) SIPE account
150 * @return Contact. Must be g_free()'d.
152 gchar *get_contact(const struct sipe_account_data *sip);
155 * Parses URI from SIP header
157 * @param hdr (in) To/From header
159 * @return URI with sip: prefix. Must be g_free()'d.
161 gchar *parse_from(const gchar *hdr);
164 * Parses CSeq from SIP header
166 * @param hdr (in) CSeqm header
168 * @return int type CSeq value (i.e. without method).
170 int parse_cseq(const gchar *hdr);
173 * Create sip: URI from name
175 * @param name (in)
177 * @return URI with sip: prefix. Must be g_free()'d.
179 gchar *sip_uri_from_name(const gchar *name);
182 * Create sip: URI from SIP account user name
184 * @param sip (in) SIP account data
186 * @return URI with sip: prefix. Must be g_free()'d.
188 #define sip_uri_self(sip) (sip_uri_from_name(sip->username))
191 * Create sip: URI from name or sip: URI
193 * @param string (in) name or sip: URI
195 * @return URI with sip: prefix. Must be g_free()'d.
197 gchar *sip_uri(const gchar *string);
200 * Tries to figure out if contact alias which stored locally
201 * is just SIP URI, not a proper display name or local alias.
203 * @param uri SIP URI with 'sip:' prefix.
204 * @param alias as returned by purple.
206 gboolean
207 sipe_is_bad_alias(const char *uri,
208 const char *alias);
211 * Find a XML node from the parent with the specified path
213 * @param parent (in) XML node to start search from
214 * @param ... (in) Names of the descendant nodes
216 * @return descendant XML node
218 struct _xmlnode * xmlnode_get_descendant(const struct _xmlnode *parent, ...);
221 * Convert a XML attribute to an integer
222 * @param node (in) XML node
223 * @param attr (in) name of the attribute
224 * @param fallback (in) default value if the attribute doesn't exist
226 * @return attribute value converted to integer or the fallback value
228 gint xmlnode_get_int_attrib(struct _xmlnode *node,
229 const char *attr,
230 gint fallback);
233 * For glib < 2.8 compatibility
235 char *sipe_get_host_name(void);
238 * Checks if provided string is empty - NULL, zero size or just series of white spaces.
239 * Doesn't modify input string.
241 gboolean
242 is_empty(const char *st);
244 /** Returns newly allocated string. Must be g_free()'d */
245 char *
246 replace(const char *st,
247 const char *search,
248 const char *replace);
251 * Replaces \r\n to \n
252 * Returns newly allocated string. Must be g_free()'d
254 char *
255 fix_newlines(const char *st);
258 * Tests two strings for equality.
260 * Unlike strcmp(), this function will not crash if one or both of the
261 * strings are @c NULL.
263 * Same as purple_strequal (defined only for 2.6) to maintain
264 * our backward compatibility.
266 * @param left A string
267 * @param right A string to compare with left
269 * @return @c TRUE if the strings are the same, else @c FALSE.
272 gboolean sipe_strequal(const gchar *left, const gchar *right);
275 * Tests two strings for equality, ignoring the case
277 * Same as glib @c g_ascii_strcasecmp() but works correctly for @c NULL
278 * pointers too. Plus it doesn't complain loudly about them...
280 * @param left A string
281 * @param right A string to compare with left
283 * @return @c TRUE if the strings are the same, else @c FALSE.
286 gboolean sipe_strcase_equal(const gchar *left, const gchar *right);
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 char *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 char *
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: value'
342 * @param list a list of @c sipnameval structures
343 * @param lines array of strings in format 'name: value'
345 * @return @c FALSE if any of @c lines has incorrect format, @c TRUE otherwise
347 gboolean
348 sipe_utils_parse_lines(GSList **list, gchar **lines);
351 * Adds a name-value pair to @c list
353 * @param list a list of @c sipnameval structures
354 * @param name attribute's name
355 * @param value value of attribute @c name
357 * @return the new start of the GSList
359 GSList *
360 sipe_utils_nameval_add(GSList *list, const gchar *name, const gchar *value);
363 * Finds a value of attribute @c name in @c list
365 * @param list a list of @c sipnameval structures
366 * @param name attribute to find
368 * @return value of @c name or NULL if @c name is not found
370 const gchar *
371 sipe_utils_nameval_find(const GSList *list, const gchar *name);
374 * Returns @c which occurrence of attribute @c name in @c list
376 * @c which is zero based, so 0 means first occurrence of @c name in @c list.
378 * @param list a list of @c sipnameval structures
379 * @param name attribute to find
380 * @param which specifies occurrence of @name in @c list
382 * @return value of @c name or NULL if @c name is not found
384 const gchar *
385 sipe_utils_nameval_find_instance(const GSList *list, const gchar *name, int which);
388 * Frees memory allocated by @c list
390 * @param list a list of @c sipnameval structures
392 void
393 sipe_utils_nameval_free(GSList *list);