Free session focus dialog
[siplcs.git] / src / sipe-utils.c
blob59641da0c84bf2628ae8b12d5ccdfe9400bb8384
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 #include "sipe.h"
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);
43 gchar *gentag()
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)
63 gchar *from;
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 <...> */
72 tmp2 = tmp + 1;
73 tmp = strchr(tmp2, '>');
74 if (tmp) {
75 from = g_strndup(tmp2, tmp - tmp2);
76 } else {
77 purple_debug_info("sipe", "found < without > in From\n");
78 return NULL;
80 } else {
81 tmp = strchr(tmp2, ';');
82 if (tmp) {
83 from = g_strndup(tmp2, tmp - tmp2);
84 } else {
85 from = g_strdup(tmp2);
88 purple_debug_info("sipe", "got %s\n", from);
89 return from;
92 int parse_cseq(const gchar *hdr)
94 int res = -1;
95 gchar **items;
96 items = g_strsplit(hdr, " ", 1);
97 if (items[0]) {
98 res = atoi(items[0]);
100 g_strfreev(items);
101 return res;
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, ...)
116 va_list args;
117 xmlnode *node = NULL;
118 const gchar *name;
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;
124 parent = node;
126 va_end(args);
128 return node;
132 Local Variables:
133 mode: c
134 c-file-style: "bsd"
135 indent-tabs-mode: t
136 tab-width: 8
137 End: