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:
30 /* Forward declarations */
31 struct sipe_account_data
;
33 /* Our publication type keys. OCS 2007+
34 * Format: SIPE_PUB_{Category}[_{SubSategory}]
41 * Unique to the device.
43 #define SIPE_PUB_DEVICE 0
48 * Availability, activity, end-point location, time zone, and device type.
49 * First hexadecimal digit is 0x3; remaining seven hexadecimal digits are unique per device.
51 #define SIPE_PUB_STATE_MACHINE 3
56 * Availability and activity.
59 #define SIPE_PUB_STATE_USER 2
64 * Availability, activity, meeting subject, and meeting location.
65 * First hexadecimal digit is 0x4; remaining seven hexadecimal digits are unique per device.
67 #define SIPE_PUB_STATE_CALENDAR 4
70 * Calendar state for an Out of Office meeting
72 * (??)Activity for when a user sets or removes an Out of Office message in Exchange.
73 * (+)user sets in Outlook for an Out of Office meeting
74 * First hexadecimal digit is 0x5; remaining seven hexadecimal digits are unique per device.
76 #define SIPE_PUB_STATE_CALENDAR_OOF 5
81 * 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.
82 * First hexadecimal digit is 0x7; remaining seven hexadecimal digits are unique per device.
84 #define SIPE_PUB_STATE_PHONE 7
89 * Start time, granularity, and free/busy data.
90 * First hexadecimal digit is 0x4; last seven hexadecimal digits uniquely define the calendar.
92 #define SIPE_PUB_CALENDAR_DATA 400
97 * Out of Office note that a user sets in Outlook using the Out of Office assistant.
98 * First hexadecimal digit is 0x4; last seven hexadecimal digits uniquely define the calendar.
100 #define SIPE_PUB_NOTE_OOF 400
103 * Returns epid value.
107 get_epid(struct sipe_account_data
*sip
);
112 * @return Call ID. Must be g_free()'d.
114 gchar
*gencallid(void);
119 * @return Tag. Must be g_free()'d.
124 * Generate conference-id
125 * 32 characters long. Value space is restricted to printable ASCII characters
127 * Ex.: 8386E6AEAAA41E4AA6627BA76D43B6D1
129 * @return conference-id. Must be g_free()'d.
131 gchar
*genconfid(void);
134 * Returns instance value for particular publication type.
135 * It should be consistent for the same endpoint
136 * but different between distinct endpoints.
138 * See defined constants for keys patterned SIPE_PUB_*
141 sipe_get_pub_instance(struct sipe_account_data
*sip
,
142 int publication_key
);
145 * Get contact information from SIPE account
147 * @param sip (in) SIPE account
149 * @return Contact. Must be g_free()'d.
151 gchar
*get_contact(const struct sipe_account_data
*sip
);
154 * Parses URI from SIP header
156 * @param hdr (in) To/From header
158 * @return URI with sip: prefix. Must be g_free()'d.
160 gchar
*parse_from(const gchar
*hdr
);
163 * Parses CSeq from SIP header
165 * @param hdr (in) CSeqm header
167 * @return int type CSeq value (i.e. without method).
169 int parse_cseq(const gchar
*hdr
);
172 * Create sip: URI from name
176 * @return URI with sip: prefix. Must be g_free()'d.
178 gchar
*sip_uri_from_name(const gchar
*name
);
181 * Create sip: URI from SIP account user name
183 * @param sip (in) SIP account data
185 * @return URI with sip: prefix. Must be g_free()'d.
187 #define sip_uri_self(sip) (sip_uri_from_name(sip->username))
190 * Create sip: URI from name or sip: URI
192 * @param string (in) name or sip: URI
194 * @return URI with sip: prefix. Must be g_free()'d.
196 gchar
*sip_uri(const gchar
*string
);
199 * Tries to figure out if contact alias which stored locally
200 * is just SIP URI, not a proper display name or local alias.
202 * @param uri SIP URI with 'sip:' prefix.
203 * @param alias as returned by purple.
206 sipe_is_bad_alias(const char *uri
,
210 * Checks if provided string is empty - NULL, zero size or just series of white spaces.
211 * Doesn't modify input string.
214 is_empty(const char *st
);
216 /** Returns newly allocated string. Must be g_free()'d */
218 replace(const char *st
,
220 const char *replace
);
223 * Replaces \r\n to \n
224 * Returns newly allocated string. Must be g_free()'d
227 fix_newlines(const char *st
);
230 * Tests two strings for equality.
232 * Unlike strcmp(), this function will not crash if one or both of the
233 * strings are @c NULL.
235 * Same as purple_strequal (defined only for 2.6) to maintain
236 * our backward compatibility.
238 * @param left A string
239 * @param right A string to compare with left
241 * @return @c TRUE if the strings are the same, else @c FALSE.
244 gboolean
sipe_strequal(const gchar
*left
, const gchar
*right
);
247 * Tests two strings for equality, ignoring the case
249 * Same as glib @c g_ascii_strcasecmp() but works correctly for @c NULL
250 * pointers too. Plus it doesn't complain loudly about them...
252 * @param left A string
253 * @param right A string to compare with left
255 * @return @c TRUE if the strings are the same, else @c FALSE.
258 gboolean
sipe_strcase_equal(const gchar
*left
, const gchar
*right
);
261 * Parses a timestamp in ISO8601 format and returns a time_t.
262 * Assumes UTC if no timezone specified
264 * @param timestamp The timestamp
267 sipe_utils_str_to_time(const gchar
*timestamp
);
270 * Converts time_t to ISO8601 string.
273 * Must be g_free()'d after use.
275 * Example: 2010-02-03T23:59:59Z
278 sipe_utils_time_to_str(time_t timestamp
);
286 * Parses string of hex digits to buffer.
289 * @param hex_str (in) string of hex digits to convert.
290 * @param buff (out) newly allocated buffer. Must be g_free()'d after use.
292 * @return size of newly allocated buffer
295 hex_str_to_buff(const char *hex_str
, guint8
**buff
);
298 * Composes hex string out of provided buffer.
301 * @param buff input buffer
302 * @param buff_len length of buffer
304 * @result newly allocated hex string representing buffer. Must be g_free()'d after use.
307 buff_to_hex_str(const guint8
*buff
, const size_t buff_len
);
310 * Creates name-value pairs from given lines and appends them to @c list
312 * Lines must be in format 'name: value'
314 * @param list a list of @c sipnameval structures
315 * @param lines array of strings in format 'name: value'
317 * @return @c FALSE if any of @c lines has incorrect format, @c TRUE otherwise
320 sipe_utils_parse_lines(GSList
**list
, gchar
**lines
);
323 * Adds a name-value pair to @c list
325 * @param list a list of @c sipnameval structures
326 * @param name attribute's name
327 * @param value value of attribute @c name
329 * @return the new start of the GSList
332 sipe_utils_nameval_add(GSList
*list
, const gchar
*name
, const gchar
*value
);
335 * Finds a value of attribute @c name in @c list
337 * @param list a list of @c sipnameval structures
338 * @param name attribute to find
340 * @return value of @c name or NULL if @c name is not found
343 sipe_utils_nameval_find(const GSList
*list
, const gchar
*name
);
346 * Returns @c which occurrence of attribute @c name in @c list
348 * @c which is zero based, so 0 means first occurrence of @c name in @c list.
350 * @param list a list of @c sipnameval structures
351 * @param name attribute to find
352 * @param which specifies occurrence of @name in @c list
354 * @return value of @c name or NULL if @c name is not found
357 sipe_utils_nameval_find_instance(const GSList
*list
, const gchar
*name
, int which
);
360 * Frees memory allocated by @c list
362 * @param list a list of @c sipnameval structures
365 sipe_utils_nameval_free(GSList
*list
);
368 * Given a string, this replaces one substring with another
369 * and returns a newly allocated string.
371 * @param string the string from which to replace stuff.
372 * @param delimiter the substring you want replaced.
373 * @param replacement the substring you want as replacement.
375 * @return string with the substitution or NULL. Must be g_free()'d after use.
377 gchar
*sipe_utils_str_replace(const gchar
*string
,
378 const gchar
*delimiter
,
379 const gchar
*replacement
);