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
30 #include "sipe-utils.h"
32 /* Generate 32 random bits */
33 #define RANDOM32BITS (rand() & 0xFFFF)
35 gchar
*gencallid(void)
37 return g_strdup_printf("%04Xg%04Xa%04Xi%04Xm%04Xt%04Xb%04Xx%04Xx",
38 RANDOM32BITS
, RANDOM32BITS
, RANDOM32BITS
,
39 RANDOM32BITS
, RANDOM32BITS
, RANDOM32BITS
,
40 RANDOM32BITS
, RANDOM32BITS
);
45 return g_strdup_printf("%04d%04d", RANDOM32BITS
, RANDOM32BITS
);
48 gchar
*genconfid(void)
50 return g_strdup_printf("%04X%04X%04X%04X%04X%04X%04X%04X",
51 RANDOM32BITS
, RANDOM32BITS
, RANDOM32BITS
,
52 RANDOM32BITS
, RANDOM32BITS
, RANDOM32BITS
,
53 RANDOM32BITS
, RANDOM32BITS
);
56 gchar
*get_contact(const struct sipe_account_data
*sip
)
58 return g_strdup(sip
->contact
);
61 gchar
*parse_from(const gchar
*hdr
)
64 const gchar
*tmp
, *tmp2
= hdr
;
66 if (!hdr
) return NULL
;
67 purple_debug_info("sipe", "parsing address out of %s\n", hdr
);
68 tmp
= strchr(hdr
, '<');
70 /* i hate the different SIP UA behaviours... */
71 if (tmp
) { /* sip address in <...> */
73 tmp
= strchr(tmp2
, '>');
75 from
= g_strndup(tmp2
, tmp
- tmp2
);
77 purple_debug_info("sipe", "found < without > in From\n");
81 tmp
= strchr(tmp2
, ';');
83 from
= g_strndup(tmp2
, tmp
- tmp2
);
85 from
= g_strdup(tmp2
);
88 purple_debug_info("sipe", "got %s\n", from
);
92 int parse_cseq(const gchar
*hdr
)
96 items
= g_strsplit(hdr
, " ", 1);
104 gchar
*sip_uri_from_name(const gchar
*name
)
106 return(g_strdup_printf("sip:%s", name
));
109 gchar
*sip_uri(const gchar
*string
)
111 return(strstr(string
, "sip:") ? g_strdup(string
) : sip_uri_from_name(string
));
114 xmlnode
*xmlnode_get_descendant(const xmlnode
*parent
, ...)
117 xmlnode
*node
= NULL
;
120 va_start(args
, parent
);
121 while ((name
= va_arg(args
, const char *)) != NULL
) {
122 node
= xmlnode_get_child(parent
, name
);
123 if (node
== NULL
) return NULL
;