Start the Big Split...
[siplcs.git] / src / sipe-utils.c
blobaf5f6b9a05c835600e1f02c0df5463abcf82c183
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"
28 #include "sipe.h"
29 #include "sipe-utils.h"
31 /* Generate 32 random bits */
32 #define RANDOM32BITS (rand() & 0xFFFF)
34 gchar *gencallid(void)
36 return g_strdup_printf("%04Xg%04Xa%04Xi%04Xm%04Xt%04Xb%04Xx%04Xx",
37 RANDOM32BITS, RANDOM32BITS, RANDOM32BITS,
38 RANDOM32BITS, RANDOM32BITS, RANDOM32BITS,
39 RANDOM32BITS, RANDOM32BITS);
42 gchar *gentag()
44 return g_strdup_printf("%04d%04d", RANDOM32BITS, RANDOM32BITS);
47 gchar *get_contact(const struct sipe_account_data *sip)
49 return g_strdup(sip->contact);
52 gchar *parse_from(const gchar *hdr)
54 gchar *from;
55 const gchar *tmp, *tmp2 = hdr;
57 if (!hdr) return NULL;
58 purple_debug_info("sipe", "parsing address out of %s\n", hdr);
59 tmp = strchr(hdr, '<');
61 /* i hate the different SIP UA behaviours... */
62 if (tmp) { /* sip address in <...> */
63 tmp2 = tmp + 1;
64 tmp = strchr(tmp2, '>');
65 if (tmp) {
66 from = g_strndup(tmp2, tmp - tmp2);
67 } else {
68 purple_debug_info("sipe", "found < without > in From\n");
69 return NULL;
71 } else {
72 tmp = strchr(tmp2, ';');
73 if (tmp) {
74 from = g_strndup(tmp2, tmp - tmp2);
75 } else {
76 from = g_strdup(tmp2);
79 purple_debug_info("sipe", "got %s\n", from);
80 return from;
84 Local Variables:
85 mode: c
86 c-file-style: "bsd"
87 indent-tabs-mode: t
88 tab-width: 8
89 End: