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
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
);
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
)
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 <...> */
69 tmp
= strchr(tmp2
, '>');
71 from
= g_strndup(tmp2
, tmp
- tmp2
);
73 purple_debug_info("sipe", "found < without > in From\n");
77 tmp
= strchr(tmp2
, ';');
79 from
= g_strndup(tmp2
, tmp
- tmp2
);
81 from
= g_strdup(tmp2
);
84 purple_debug_info("sipe", "got %s\n", from
);
88 xmlnode
*xmlnode_get_descendant(const xmlnode
*parent
, ...)
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
;