fix for compilation on Windows
[siplcs.git] / src / sipe-utils.c
blob8c892f084be03449043b01d1fa03a1095e8e3ad5
1 /**
2 * @file sipe-utils.c
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 #include <string.h>
24 #include <glib.h>
26 #include "debug.h"
27 #include "xmlnode.h"
29 #ifdef _WIN32
30 #include "internal.h"
31 #endif
33 #include "sipe.h"
34 #include "sipe-utils.h"
36 /* Generate 32 random bits */
37 #define RANDOM32BITS (rand() & 0xFFFF)
39 gchar *gencallid(void)
41 return g_strdup_printf("%04Xg%04Xa%04Xi%04Xm%04Xt%04Xb%04Xx%04Xx",
42 RANDOM32BITS, RANDOM32BITS, RANDOM32BITS,
43 RANDOM32BITS, RANDOM32BITS, RANDOM32BITS,
44 RANDOM32BITS, RANDOM32BITS);
47 gchar *gentag()
49 return g_strdup_printf("%04d%04d", RANDOM32BITS, RANDOM32BITS);
52 gchar *get_contact(const struct sipe_account_data *sip)
54 return g_strdup(sip->contact);
57 gchar *parse_from(const gchar *hdr)
59 gchar *from;
60 const gchar *tmp, *tmp2 = hdr;
62 if (!hdr) return NULL;
63 purple_debug_info("sipe", "parsing address out of %s\n", hdr);
64 tmp = strchr(hdr, '<');
66 /* i hate the different SIP UA behaviours... */
67 if (tmp) { /* sip address in <...> */
68 tmp2 = tmp + 1;
69 tmp = strchr(tmp2, '>');
70 if (tmp) {
71 from = g_strndup(tmp2, tmp - tmp2);
72 } else {
73 purple_debug_info("sipe", "found < without > in From\n");
74 return NULL;
76 } else {
77 tmp = strchr(tmp2, ';');
78 if (tmp) {
79 from = g_strndup(tmp2, tmp - tmp2);
80 } else {
81 from = g_strdup(tmp2);
84 purple_debug_info("sipe", "got %s\n", from);
85 return from;
88 xmlnode *xmlnode_get_descendant(const xmlnode *parent, ...)
90 va_list args;
91 xmlnode *node = NULL;
92 const gchar *name;
94 va_start(args, parent);
95 while ((name = va_arg(args, const char *)) != NULL) {
96 node = xmlnode_get_child(parent, name);
97 if (node == NULL) return NULL;
98 parent = node;
100 va_end(args);
102 return node;
106 Local Variables:
107 mode: c
108 c-file-style: "bsd"
109 indent-tabs-mode: t
110 tab-width: 8
111 End: