Merge branch 'mob' of git+ssh://localhost/srv/git/siplcs into mob
[siplcs.git] / src / core / sipe-utils.h
blob3a59eb76b968cddffffd6ce60b727ed7690d5a97
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
23 /* Our publication type keys. OCS 2007+
24 * Format: SIPE_PUB_{Category}[_{SubSategory}]
26 /**
27 * device
28 * -
30 * -
31 * Unique to the device.
33 #define SIPE_PUB_DEVICE 0
34 /**
35 * state
36 * Machine state
38 * Availability, activity, end-point location, time zone, and device type.
39 * First hexadecimal digit is 0x3; remaining seven hexadecimal digits are unique per device.
41 #define SIPE_PUB_STATE_MACHINE 3
42 /**
43 * state
44 * User state
46 * Availability and activity.
47 * 0x20000000
49 #define SIPE_PUB_STATE_USER 2
50 /**
51 * state
52 * Calendar state
54 * Availability, activity, meeting subject, and meeting location.
55 * First hexadecimal digit is 0x4; remaining seven hexadecimal digits are unique per device.
57 #define SIPE_PUB_STATE_CALENDAR 4
58 /**
59 * state
60 * Calendar state for an Out of Office meeting
62 * (??)Activity for when a user sets or removes an Out of Office message in Exchange.
63 * (+)user sets in Outlook for an Out of Office meeting
64 * First hexadecimal digit is 0x5; remaining seven hexadecimal digits are unique per device.
66 #define SIPE_PUB_STATE_CALENDAR_OOF 5
67 /**
68 * state
69 * RCC Phone State
71 * 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.
72 * First hexadecimal digit is 0x7; remaining seven hexadecimal digits are unique per device.
74 #define SIPE_PUB_STATE_PHONE 7
75 /**
76 * calendarData
77 * Free/busy data
79 * Start time, granularity, and free/busy data.
80 * First hexadecimal digit is 0x4; last seven hexadecimal digits uniquely define the calendar.
82 #define SIPE_PUB_CALENDAR_DATA 400
83 /**
84 * note
85 * Out of Office note
87 * Out of Office note that a user sets in Outlook using the Out of Office assistant.
88 * First hexadecimal digit is 0x4; last seven hexadecimal digits uniquely define the calendar.
90 #define SIPE_PUB_NOTE_OOF 400
92 /**
93 * Returns epid value.
94 * Uses cache.
96 gchar *
97 get_epid(struct sipe_account_data *sip);
99 /**
100 * Generate Call ID
102 * @return Call ID. Must be g_free()'d.
104 gchar *gencallid(void);
107 * Generate Tag
109 * @return Tag. Must be g_free()'d.
111 gchar *gentag(void);
114 * Generate conference-id
115 * 32 characters long. Value space is restricted to printable ASCII characters
117 * Ex.: 8386E6AEAAA41E4AA6627BA76D43B6D1
119 * @return conference-id. Must be g_free()'d.
121 gchar *genconfid(void);
124 * Returns instance value for particular publication type.
125 * It should be consistent for the same endpoint
126 * but different between distinct endpoints.
128 * See defined constants for keys patterned SIPE_PUB_*
130 guint
131 sipe_get_pub_instance(struct sipe_account_data *sip,
132 int publication_key);
135 * Get contact information from SIPE account
137 * @param sip (in) SIPE account
139 * @return Contact. Must be g_free()'d.
141 gchar *get_contact(const struct sipe_account_data *sip);
144 * Parses URI from SIP header
146 * @param hdr (in) To/From header
148 * @return URI with sip: prefix. Must be g_free()'d.
150 gchar *parse_from(const gchar *hdr);
153 * Parses CSeq from SIP header
155 * @param hdr (in) CSeqm header
157 * @return int type CSeq value (i.e. without method).
159 int parse_cseq(const gchar *hdr);
162 * Create sip: URI from name
164 * @param name (in)
166 * @return URI with sip: prefix. Must be g_free()'d.
168 gchar *sip_uri_from_name(const gchar *name);
171 * Create sip: URI from SIP account user name
173 * @param sip (in) SIP account data
175 * @return URI with sip: prefix. Must be g_free()'d.
177 #define sip_uri_self(sip) (sip_uri_from_name(sip->username))
180 * Create sip: URI from name or sip: URI
182 * @param string (in) name or sip: URI
184 * @return URI with sip: prefix. Must be g_free()'d.
186 gchar *sip_uri(const gchar *string);
189 * Tries to figure out if contact alias which stored locally
190 * is just SIP URI, not a proper display name or local alias.
192 * @param uri SIP URI with 'sip:' prefix.
193 * @param alias as returned by purple.
195 gboolean
196 sipe_is_bad_alias(const char *uri,
197 const char *alias);
200 * Find a XML node from the parent with the specified path
202 * @param parent (in) XML node to start search from
203 * @param ... (in) Names of the descendant nodes
205 * @return descendant XML node
207 xmlnode * xmlnode_get_descendant(const xmlnode *parent, ...);
210 * Convert a XML attribute to an integer
211 * @param node (in) XML node
212 * @param attr (in) name of the attribute
213 * @param fallback (in) default value if the attribute doesn't exist
215 * @return attribute value converted to integer or the fallback value
217 gint xmlnode_get_int_attrib(xmlnode *node,
218 const char *attr,
219 gint fallback);
222 * For glib < 2.8 compatibility
224 char *sipe_get_host_name(void);
227 * Checks if provided string is empty - NULL, zero size or just series of white spaces.
228 * Doesn't modify input string.
230 gboolean
231 is_empty(const char *st);
233 /** Returns newly allocated string. Must be g_free()'d */
234 char *
235 replace(const char *st,
236 const char *search,
237 const char *replace);
240 * Replaces \r\n to \n
241 * Returns newly allocated string. Must be g_free()'d
243 char *
244 fix_newlines(const char *st);
247 * Tests two strings for equality.
249 * Unlike strcmp(), this function will not crash if one or both of the
250 * strings are @c NULL.
252 * Same as purple_strequal (defined only for 2.6) to maintain
253 * our backward compatibility.
255 * @param left A string
256 * @param right A string to compare with left
258 * @return @c TRUE if the strings are the same, else @c FALSE.
261 gboolean sipe_strequal(const gchar *left, const gchar *right);
264 * Parses a timestamp in ISO8601 format and returns a time_t.
265 * Assumes UTC if no timezone specified
267 * @param timestamp The timestamp
269 time_t
270 sipe_utils_str_to_time(const char *timestamp);
273 * Converts time_t to ISO8601 string.
274 * Timezone is UTC.
276 * Must be g_free()'d after use.
278 * Example: 2010-02-03T23:59:59Z
280 char *
281 sipe_utils_time_to_str(time_t timestamp);