libpurple/protocols/msn/msnutils.c

Thu, 17 Jul 2008 05:26:47 +0000

author
Elliott Sales de Andrade <qulogic@pidgin.im>
date
Thu, 17 Jul 2008 05:26:47 +0000
changeset 23872
062f3d3b46b4
parent 23833
1a4c1d44858d
child 25615
3b715bfa3527
permissions
-rw-r--r--

merge of '6926fed80ff1470d0fa3a7631f99a0237b402751'
and '9dbe8580fc233673d0cf398929b4499ff5b450f8'

5309
3178acad1449 [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
1 /**
20483
45d3a4773e1b propagate from branch 'im.pidgin.rlaager.merging.msnp13-and-sf-1621854-4' (head cd47bac1af94287a1145874b9ed7a153fd1fb8bd)
Richard Laager <rlaager@pidgin.im>
parents: 16144
diff changeset
2 * @file msnutils.c Utility functions
5309
3178acad1449 [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
3 *
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15850
diff changeset
4 * purple
5309
3178acad1449 [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
5 *
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15850
diff changeset
6 * Purple is the legal property of its developers, whose names are too numerous
9198
e8eb6d5eb9eb [gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents: 9193
diff changeset
7 * to list here. Please refer to the COPYRIGHT file distributed with this
e8eb6d5eb9eb [gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents: 9193
diff changeset
8 * source distribution.
6701
7e2db9273748 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6359
diff changeset
9 *
5309
3178acad1449 [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
10 * This program is free software; you can redistribute it and/or modify
3178acad1449 [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
11 * it under the terms of the GNU General Public License as published by
3178acad1449 [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
12 * the Free Software Foundation; either version 2 of the License, or
3178acad1449 [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
13 * (at your option) any later version.
3178acad1449 [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
14 *
3178acad1449 [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
15 * This program is distributed in the hope that it will be useful,
3178acad1449 [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
3178acad1449 [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3178acad1449 [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
18 * GNU General Public License for more details.
3178acad1449 [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
19 *
3178acad1449 [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
20 * You should have received a copy of the GNU General Public License
3178acad1449 [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
21 * along with this program; if not, write to the Free Software
19859
71d37b57eff2 The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 18552
diff changeset
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
5309
3178acad1449 [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
23 */
3178acad1449 [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
24 #include "msn.h"
20483
45d3a4773e1b propagate from branch 'im.pidgin.rlaager.merging.msnp13-and-sf-1621854-4' (head cd47bac1af94287a1145874b9ed7a153fd1fb8bd)
Richard Laager <rlaager@pidgin.im>
parents: 16144
diff changeset
25 #include "msnutils.h"
23808
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
26
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
27 #include "cipher.h"
20483
45d3a4773e1b propagate from branch 'im.pidgin.rlaager.merging.msnp13-and-sf-1621854-4' (head cd47bac1af94287a1145874b9ed7a153fd1fb8bd)
Richard Laager <rlaager@pidgin.im>
parents: 16144
diff changeset
28
45d3a4773e1b propagate from branch 'im.pidgin.rlaager.merging.msnp13-and-sf-1621854-4' (head cd47bac1af94287a1145874b9ed7a153fd1fb8bd)
Richard Laager <rlaager@pidgin.im>
parents: 16144
diff changeset
29 char *rand_guid(void);
45d3a4773e1b propagate from branch 'im.pidgin.rlaager.merging.msnp13-and-sf-1621854-4' (head cd47bac1af94287a1145874b9ed7a153fd1fb8bd)
Richard Laager <rlaager@pidgin.im>
parents: 16144
diff changeset
30
45d3a4773e1b propagate from branch 'im.pidgin.rlaager.merging.msnp13-and-sf-1621854-4' (head cd47bac1af94287a1145874b9ed7a153fd1fb8bd)
Richard Laager <rlaager@pidgin.im>
parents: 16144
diff changeset
31 /**************************************************************************
45d3a4773e1b propagate from branch 'im.pidgin.rlaager.merging.msnp13-and-sf-1621854-4' (head cd47bac1af94287a1145874b9ed7a153fd1fb8bd)
Richard Laager <rlaager@pidgin.im>
parents: 16144
diff changeset
32 * Util
45d3a4773e1b propagate from branch 'im.pidgin.rlaager.merging.msnp13-and-sf-1621854-4' (head cd47bac1af94287a1145874b9ed7a153fd1fb8bd)
Richard Laager <rlaager@pidgin.im>
parents: 16144
diff changeset
33 **************************************************************************/
45d3a4773e1b propagate from branch 'im.pidgin.rlaager.merging.msnp13-and-sf-1621854-4' (head cd47bac1af94287a1145874b9ed7a153fd1fb8bd)
Richard Laager <rlaager@pidgin.im>
parents: 16144
diff changeset
34 char *
45d3a4773e1b propagate from branch 'im.pidgin.rlaager.merging.msnp13-and-sf-1621854-4' (head cd47bac1af94287a1145874b9ed7a153fd1fb8bd)
Richard Laager <rlaager@pidgin.im>
parents: 16144
diff changeset
35 rand_guid()
45d3a4773e1b propagate from branch 'im.pidgin.rlaager.merging.msnp13-and-sf-1621854-4' (head cd47bac1af94287a1145874b9ed7a153fd1fb8bd)
Richard Laager <rlaager@pidgin.im>
parents: 16144
diff changeset
36 {
45d3a4773e1b propagate from branch 'im.pidgin.rlaager.merging.msnp13-and-sf-1621854-4' (head cd47bac1af94287a1145874b9ed7a153fd1fb8bd)
Richard Laager <rlaager@pidgin.im>
parents: 16144
diff changeset
37 return g_strdup_printf("%4X%4X-%4X-%4X-%4X-%4X%4X%4X",
45d3a4773e1b propagate from branch 'im.pidgin.rlaager.merging.msnp13-and-sf-1621854-4' (head cd47bac1af94287a1145874b9ed7a153fd1fb8bd)
Richard Laager <rlaager@pidgin.im>
parents: 16144
diff changeset
38 rand() % 0xAAFF + 0x1111,
45d3a4773e1b propagate from branch 'im.pidgin.rlaager.merging.msnp13-and-sf-1621854-4' (head cd47bac1af94287a1145874b9ed7a153fd1fb8bd)
Richard Laager <rlaager@pidgin.im>
parents: 16144
diff changeset
39 rand() % 0xAAFF + 0x1111,
45d3a4773e1b propagate from branch 'im.pidgin.rlaager.merging.msnp13-and-sf-1621854-4' (head cd47bac1af94287a1145874b9ed7a153fd1fb8bd)
Richard Laager <rlaager@pidgin.im>
parents: 16144
diff changeset
40 rand() % 0xAAFF + 0x1111,
45d3a4773e1b propagate from branch 'im.pidgin.rlaager.merging.msnp13-and-sf-1621854-4' (head cd47bac1af94287a1145874b9ed7a153fd1fb8bd)
Richard Laager <rlaager@pidgin.im>
parents: 16144
diff changeset
41 rand() % 0xAAFF + 0x1111,
45d3a4773e1b propagate from branch 'im.pidgin.rlaager.merging.msnp13-and-sf-1621854-4' (head cd47bac1af94287a1145874b9ed7a153fd1fb8bd)
Richard Laager <rlaager@pidgin.im>
parents: 16144
diff changeset
42 rand() % 0xAAFF + 0x1111,
45d3a4773e1b propagate from branch 'im.pidgin.rlaager.merging.msnp13-and-sf-1621854-4' (head cd47bac1af94287a1145874b9ed7a153fd1fb8bd)
Richard Laager <rlaager@pidgin.im>
parents: 16144
diff changeset
43 rand() % 0xAAFF + 0x1111,
45d3a4773e1b propagate from branch 'im.pidgin.rlaager.merging.msnp13-and-sf-1621854-4' (head cd47bac1af94287a1145874b9ed7a153fd1fb8bd)
Richard Laager <rlaager@pidgin.im>
parents: 16144
diff changeset
44 rand() % 0xAAFF + 0x1111,
45d3a4773e1b propagate from branch 'im.pidgin.rlaager.merging.msnp13-and-sf-1621854-4' (head cd47bac1af94287a1145874b9ed7a153fd1fb8bd)
Richard Laager <rlaager@pidgin.im>
parents: 16144
diff changeset
45 rand() % 0xAAFF + 0x1111);
45d3a4773e1b propagate from branch 'im.pidgin.rlaager.merging.msnp13-and-sf-1621854-4' (head cd47bac1af94287a1145874b9ed7a153fd1fb8bd)
Richard Laager <rlaager@pidgin.im>
parents: 16144
diff changeset
46 }
5309
3178acad1449 [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
47
6358
c3347685b9ef [gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents: 6093
diff changeset
48 void
c3347685b9ef [gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents: 6093
diff changeset
49 msn_parse_format(const char *mime, char **pre_ret, char **post_ret)
5309
3178acad1449 [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
50 {
3178acad1449 [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
51 char *cur;
6358
c3347685b9ef [gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents: 6093
diff changeset
52 GString *pre = g_string_new(NULL);
c3347685b9ef [gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents: 6093
diff changeset
53 GString *post = g_string_new(NULL);
6093
2095841fde03 [gaim-migrate @ 6552]
Christian Hammond <chipx86@chipx86.com>
parents: 5964
diff changeset
54 unsigned int colors[3];
5309
3178acad1449 [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
55
6358
c3347685b9ef [gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents: 6093
diff changeset
56 if (pre_ret != NULL) *pre_ret = NULL;
c3347685b9ef [gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents: 6093
diff changeset
57 if (post_ret != NULL) *post_ret = NULL;
c3347685b9ef [gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents: 6093
diff changeset
58
5309
3178acad1449 [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
59 cur = strstr(mime, "FN=");
3178acad1449 [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
60
8518
694a8ad60edd [gaim-migrate @ 9257]
David Vermeille
parents: 8475
diff changeset
61 if (cur && (*(cur = cur + 3) != ';'))
694a8ad60edd [gaim-migrate @ 9257]
David Vermeille
parents: 8475
diff changeset
62 {
6358
c3347685b9ef [gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents: 6093
diff changeset
63 pre = g_string_append(pre, "<FONT FACE=\"");
5309
3178acad1449 [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
64
8518
694a8ad60edd [gaim-migrate @ 9257]
David Vermeille
parents: 8475
diff changeset
65 while (*cur && *cur != ';')
694a8ad60edd [gaim-migrate @ 9257]
David Vermeille
parents: 8475
diff changeset
66 {
6358
c3347685b9ef [gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents: 6093
diff changeset
67 pre = g_string_append_c(pre, *cur);
5309
3178acad1449 [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
68 cur++;
3178acad1449 [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
69 }
3178acad1449 [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
70
6358
c3347685b9ef [gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents: 6093
diff changeset
71 pre = g_string_append(pre, "\">");
c3347685b9ef [gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents: 6093
diff changeset
72 post = g_string_prepend(post, "</FONT>");
5309
3178acad1449 [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
73 }
6358
c3347685b9ef [gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents: 6093
diff changeset
74
5309
3178acad1449 [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
75 cur = strstr(mime, "EF=");
3178acad1449 [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
76
8518
694a8ad60edd [gaim-migrate @ 9257]
David Vermeille
parents: 8475
diff changeset
77 if (cur && (*(cur = cur + 3) != ';'))
694a8ad60edd [gaim-migrate @ 9257]
David Vermeille
parents: 8475
diff changeset
78 {
694a8ad60edd [gaim-migrate @ 9257]
David Vermeille
parents: 8475
diff changeset
79 while (*cur && *cur != ';')
694a8ad60edd [gaim-migrate @ 9257]
David Vermeille
parents: 8475
diff changeset
80 {
6358
c3347685b9ef [gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents: 6093
diff changeset
81 pre = g_string_append_c(pre, '<');
c3347685b9ef [gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents: 6093
diff changeset
82 pre = g_string_append_c(pre, *cur);
c3347685b9ef [gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents: 6093
diff changeset
83 pre = g_string_append_c(pre, '>');
8691
87920308f00e [gaim-migrate @ 9444]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 8678
diff changeset
84 post = g_string_prepend_c(post, '>');
87920308f00e [gaim-migrate @ 9444]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 8678
diff changeset
85 post = g_string_prepend_c(post, *cur);
87920308f00e [gaim-migrate @ 9444]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 8678
diff changeset
86 post = g_string_prepend_c(post, '/');
87920308f00e [gaim-migrate @ 9444]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 8678
diff changeset
87 post = g_string_prepend_c(post, '<');
5309
3178acad1449 [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
88 cur++;
3178acad1449 [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
89 }
3178acad1449 [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
90 }
3178acad1449 [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
91
3178acad1449 [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
92 cur = strstr(mime, "CO=");
3178acad1449 [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
93
8518
694a8ad60edd [gaim-migrate @ 9257]
David Vermeille
parents: 8475
diff changeset
94 if (cur && (*(cur = cur + 3) != ';'))
694a8ad60edd [gaim-migrate @ 9257]
David Vermeille
parents: 8475
diff changeset
95 {
6093
2095841fde03 [gaim-migrate @ 6552]
Christian Hammond <chipx86@chipx86.com>
parents: 5964
diff changeset
96 int i;
2095841fde03 [gaim-migrate @ 6552]
Christian Hammond <chipx86@chipx86.com>
parents: 5964
diff changeset
97
2095841fde03 [gaim-migrate @ 6552]
Christian Hammond <chipx86@chipx86.com>
parents: 5964
diff changeset
98 i = sscanf(cur, "%02x%02x%02x;", &colors[0], &colors[1], &colors[2]);
2095841fde03 [gaim-migrate @ 6552]
Christian Hammond <chipx86@chipx86.com>
parents: 5964
diff changeset
99
8518
694a8ad60edd [gaim-migrate @ 9257]
David Vermeille
parents: 8475
diff changeset
100 if (i > 0)
694a8ad60edd [gaim-migrate @ 9257]
David Vermeille
parents: 8475
diff changeset
101 {
5309
3178acad1449 [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
102 char tag[64];
6093
2095841fde03 [gaim-migrate @ 6552]
Christian Hammond <chipx86@chipx86.com>
parents: 5964
diff changeset
103
8518
694a8ad60edd [gaim-migrate @ 9257]
David Vermeille
parents: 8475
diff changeset
104 if (i == 1)
694a8ad60edd [gaim-migrate @ 9257]
David Vermeille
parents: 8475
diff changeset
105 {
6093
2095841fde03 [gaim-migrate @ 6552]
Christian Hammond <chipx86@chipx86.com>
parents: 5964
diff changeset
106 colors[1] = 0;
8518
694a8ad60edd [gaim-migrate @ 9257]
David Vermeille
parents: 8475
diff changeset
107 colors[2] = 0;
6093
2095841fde03 [gaim-migrate @ 6552]
Christian Hammond <chipx86@chipx86.com>
parents: 5964
diff changeset
108 }
8518
694a8ad60edd [gaim-migrate @ 9257]
David Vermeille
parents: 8475
diff changeset
109 else if (i == 2)
694a8ad60edd [gaim-migrate @ 9257]
David Vermeille
parents: 8475
diff changeset
110 {
694a8ad60edd [gaim-migrate @ 9257]
David Vermeille
parents: 8475
diff changeset
111 unsigned int temp = colors[0];
694a8ad60edd [gaim-migrate @ 9257]
David Vermeille
parents: 8475
diff changeset
112
694a8ad60edd [gaim-migrate @ 9257]
David Vermeille
parents: 8475
diff changeset
113 colors[0] = colors[1];
694a8ad60edd [gaim-migrate @ 9257]
David Vermeille
parents: 8475
diff changeset
114 colors[1] = temp;
694a8ad60edd [gaim-migrate @ 9257]
David Vermeille
parents: 8475
diff changeset
115 colors[2] = 0;
694a8ad60edd [gaim-migrate @ 9257]
David Vermeille
parents: 8475
diff changeset
116 }
694a8ad60edd [gaim-migrate @ 9257]
David Vermeille
parents: 8475
diff changeset
117 else if (i == 3)
694a8ad60edd [gaim-migrate @ 9257]
David Vermeille
parents: 8475
diff changeset
118 {
694a8ad60edd [gaim-migrate @ 9257]
David Vermeille
parents: 8475
diff changeset
119 unsigned int temp = colors[2];
694a8ad60edd [gaim-migrate @ 9257]
David Vermeille
parents: 8475
diff changeset
120
694a8ad60edd [gaim-migrate @ 9257]
David Vermeille
parents: 8475
diff changeset
121 colors[2] = colors[0];
694a8ad60edd [gaim-migrate @ 9257]
David Vermeille
parents: 8475
diff changeset
122 colors[0] = temp;
6093
2095841fde03 [gaim-migrate @ 6552]
Christian Hammond <chipx86@chipx86.com>
parents: 5964
diff changeset
123 }
2095841fde03 [gaim-migrate @ 6552]
Christian Hammond <chipx86@chipx86.com>
parents: 5964
diff changeset
124
5309
3178acad1449 [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
125 g_snprintf(tag, sizeof(tag),
3178acad1449 [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
126 "<FONT COLOR=\"#%02hhx%02hhx%02hhx\">",
8518
694a8ad60edd [gaim-migrate @ 9257]
David Vermeille
parents: 8475
diff changeset
127 colors[0], colors[1], colors[2]);
694a8ad60edd [gaim-migrate @ 9257]
David Vermeille
parents: 8475
diff changeset
128
6358
c3347685b9ef [gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents: 6093
diff changeset
129 pre = g_string_append(pre, tag);
c3347685b9ef [gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents: 6093
diff changeset
130 post = g_string_prepend(post, "</FONT>");
5309
3178acad1449 [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
131 }
3178acad1449 [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
132 }
3178acad1449 [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
133
16143
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15884
diff changeset
134 cur = strstr(mime, "RL=");
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15884
diff changeset
135
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15884
diff changeset
136 if (cur && (*(cur = cur + 3) != ';'))
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15884
diff changeset
137 {
16144
4e022531d1c9 Patch cleanups:
Richard Laager <rlaager@pidgin.im>
parents: 16143
diff changeset
138 if (*cur == '1')
4e022531d1c9 Patch cleanups:
Richard Laager <rlaager@pidgin.im>
parents: 16143
diff changeset
139 {
16143
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15884
diff changeset
140 /* RTL text was received */
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15884
diff changeset
141 pre = g_string_append(pre, "<SPAN style=\"direction:rtl;text-align:right;\">");
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15884
diff changeset
142 post = g_string_prepend(post, "</SPAN>");
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15884
diff changeset
143 }
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15884
diff changeset
144 }
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15884
diff changeset
145
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15850
diff changeset
146 cur = g_strdup(purple_url_decode(pre->str));
6358
c3347685b9ef [gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents: 6093
diff changeset
147 g_string_free(pre, TRUE);
c3347685b9ef [gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents: 6093
diff changeset
148
c3347685b9ef [gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents: 6093
diff changeset
149 if (pre_ret != NULL)
c3347685b9ef [gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents: 6093
diff changeset
150 *pre_ret = cur;
6359
5b1705ffdd55 [gaim-migrate @ 6863]
Christian Hammond <chipx86@chipx86.com>
parents: 6358
diff changeset
151 else
5b1705ffdd55 [gaim-migrate @ 6863]
Christian Hammond <chipx86@chipx86.com>
parents: 6358
diff changeset
152 g_free(cur);
5309
3178acad1449 [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
153
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15850
diff changeset
154 cur = g_strdup(purple_url_decode(post->str));
6358
c3347685b9ef [gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents: 6093
diff changeset
155 g_string_free(post, TRUE);
c3347685b9ef [gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents: 6093
diff changeset
156
c3347685b9ef [gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents: 6093
diff changeset
157 if (post_ret != NULL)
c3347685b9ef [gaim-migrate @ 6862]
Christian Hammond <chipx86@chipx86.com>
parents: 6093
diff changeset
158 *post_ret = cur;
6359
5b1705ffdd55 [gaim-migrate @ 6863]
Christian Hammond <chipx86@chipx86.com>
parents: 6358
diff changeset
159 else
5b1705ffdd55 [gaim-migrate @ 6863]
Christian Hammond <chipx86@chipx86.com>
parents: 6358
diff changeset
160 g_free(cur);
5309
3178acad1449 [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
161 }
8518
694a8ad60edd [gaim-migrate @ 9257]
David Vermeille
parents: 8475
diff changeset
162
20483
45d3a4773e1b propagate from branch 'im.pidgin.rlaager.merging.msnp13-and-sf-1621854-4' (head cd47bac1af94287a1145874b9ed7a153fd1fb8bd)
Richard Laager <rlaager@pidgin.im>
parents: 16144
diff changeset
163 /*encode the str to RFC2047 style
45d3a4773e1b propagate from branch 'im.pidgin.rlaager.merging.msnp13-and-sf-1621854-4' (head cd47bac1af94287a1145874b9ed7a153fd1fb8bd)
Richard Laager <rlaager@pidgin.im>
parents: 16144
diff changeset
164 * Currently only support the UTF-8 and base64 encode
45d3a4773e1b propagate from branch 'im.pidgin.rlaager.merging.msnp13-and-sf-1621854-4' (head cd47bac1af94287a1145874b9ed7a153fd1fb8bd)
Richard Laager <rlaager@pidgin.im>
parents: 16144
diff changeset
165 */
45d3a4773e1b propagate from branch 'im.pidgin.rlaager.merging.msnp13-and-sf-1621854-4' (head cd47bac1af94287a1145874b9ed7a153fd1fb8bd)
Richard Laager <rlaager@pidgin.im>
parents: 16144
diff changeset
166 char *
45d3a4773e1b propagate from branch 'im.pidgin.rlaager.merging.msnp13-and-sf-1621854-4' (head cd47bac1af94287a1145874b9ed7a153fd1fb8bd)
Richard Laager <rlaager@pidgin.im>
parents: 16144
diff changeset
167 msn_encode_mime(const char *str)
45d3a4773e1b propagate from branch 'im.pidgin.rlaager.merging.msnp13-and-sf-1621854-4' (head cd47bac1af94287a1145874b9ed7a153fd1fb8bd)
Richard Laager <rlaager@pidgin.im>
parents: 16144
diff changeset
168 {
21066
6c33ad65d4dc Leak fixes.
Daniel Atallah <datallah@pidgin.im>
parents: 21059
diff changeset
169 gchar *base64, *retval;
6c33ad65d4dc Leak fixes.
Daniel Atallah <datallah@pidgin.im>
parents: 21059
diff changeset
170
6c33ad65d4dc Leak fixes.
Daniel Atallah <datallah@pidgin.im>
parents: 21059
diff changeset
171 g_return_val_if_fail(str != NULL, NULL);
23441
fd45c23a3eb2 Delete trailing whitespace
Mark Doliner <markdoliner@pidgin.im>
parents: 22518
diff changeset
172
20486
26b9f3efe52d The last of the merge fix-ups.
Richard Laager <rlaager@pidgin.im>
parents: 20485
diff changeset
173 base64 = purple_base64_encode((guchar *)str, strlen(str));
21066
6c33ad65d4dc Leak fixes.
Daniel Atallah <datallah@pidgin.im>
parents: 21059
diff changeset
174 retval = g_strdup_printf("=?utf-8?B?%s?=", base64);
6c33ad65d4dc Leak fixes.
Daniel Atallah <datallah@pidgin.im>
parents: 21059
diff changeset
175 g_free(base64);
6c33ad65d4dc Leak fixes.
Daniel Atallah <datallah@pidgin.im>
parents: 21059
diff changeset
176
6c33ad65d4dc Leak fixes.
Daniel Atallah <datallah@pidgin.im>
parents: 21059
diff changeset
177 return retval;
20483
45d3a4773e1b propagate from branch 'im.pidgin.rlaager.merging.msnp13-and-sf-1621854-4' (head cd47bac1af94287a1145874b9ed7a153fd1fb8bd)
Richard Laager <rlaager@pidgin.im>
parents: 16144
diff changeset
178 }
45d3a4773e1b propagate from branch 'im.pidgin.rlaager.merging.msnp13-and-sf-1621854-4' (head cd47bac1af94287a1145874b9ed7a153fd1fb8bd)
Richard Laager <rlaager@pidgin.im>
parents: 16144
diff changeset
179
8518
694a8ad60edd [gaim-migrate @ 9257]
David Vermeille
parents: 8475
diff changeset
180 /*
694a8ad60edd [gaim-migrate @ 9257]
David Vermeille
parents: 8475
diff changeset
181 * We need this because we're only supposed to encode spaces in the font
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15850
diff changeset
182 * names. purple_url_encode() isn't acceptable.
8518
694a8ad60edd [gaim-migrate @ 9257]
David Vermeille
parents: 8475
diff changeset
183 */
11897
10853b830964 [gaim-migrate @ 14188]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 11176
diff changeset
184 static const char *
8518
694a8ad60edd [gaim-migrate @ 9257]
David Vermeille
parents: 8475
diff changeset
185 encode_spaces(const char *str)
694a8ad60edd [gaim-migrate @ 9257]
David Vermeille
parents: 8475
diff changeset
186 {
694a8ad60edd [gaim-migrate @ 9257]
David Vermeille
parents: 8475
diff changeset
187 static char buf[BUF_LEN];
694a8ad60edd [gaim-migrate @ 9257]
David Vermeille
parents: 8475
diff changeset
188 const char *c;
694a8ad60edd [gaim-migrate @ 9257]
David Vermeille
parents: 8475
diff changeset
189 char *d;
694a8ad60edd [gaim-migrate @ 9257]
David Vermeille
parents: 8475
diff changeset
190
694a8ad60edd [gaim-migrate @ 9257]
David Vermeille
parents: 8475
diff changeset
191 g_return_val_if_fail(str != NULL, NULL);
694a8ad60edd [gaim-migrate @ 9257]
David Vermeille
parents: 8475
diff changeset
192
694a8ad60edd [gaim-migrate @ 9257]
David Vermeille
parents: 8475
diff changeset
193 for (c = str, d = buf; *c != '\0'; c++)
694a8ad60edd [gaim-migrate @ 9257]
David Vermeille
parents: 8475
diff changeset
194 {
694a8ad60edd [gaim-migrate @ 9257]
David Vermeille
parents: 8475
diff changeset
195 if (*c == ' ')
694a8ad60edd [gaim-migrate @ 9257]
David Vermeille
parents: 8475
diff changeset
196 {
694a8ad60edd [gaim-migrate @ 9257]
David Vermeille
parents: 8475
diff changeset
197 *d++ = '%';
694a8ad60edd [gaim-migrate @ 9257]
David Vermeille
parents: 8475
diff changeset
198 *d++ = '2';
694a8ad60edd [gaim-migrate @ 9257]
David Vermeille
parents: 8475
diff changeset
199 *d++ = '0';
694a8ad60edd [gaim-migrate @ 9257]
David Vermeille
parents: 8475
diff changeset
200 }
694a8ad60edd [gaim-migrate @ 9257]
David Vermeille
parents: 8475
diff changeset
201 else
694a8ad60edd [gaim-migrate @ 9257]
David Vermeille
parents: 8475
diff changeset
202 *d++ = *c;
694a8ad60edd [gaim-migrate @ 9257]
David Vermeille
parents: 8475
diff changeset
203 }
22518
aa86366979ee Patch from Qulogic that fixes #4951 by making sure that the buffer is NUL-
Ka-Hing Cheung <khc@pidgin.im>
parents: 21079
diff changeset
204 *d = '\0';
8518
694a8ad60edd [gaim-migrate @ 9257]
David Vermeille
parents: 8475
diff changeset
205
694a8ad60edd [gaim-migrate @ 9257]
David Vermeille
parents: 8475
diff changeset
206 return buf;
694a8ad60edd [gaim-migrate @ 9257]
David Vermeille
parents: 8475
diff changeset
207 }
694a8ad60edd [gaim-migrate @ 9257]
David Vermeille
parents: 8475
diff changeset
208
8595
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
209 /*
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
210 * Taken from the zephyr plugin.
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
211 * This parses HTML formatting (put out by one of the gtkimhtml widgets
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
212 * and converts it to msn formatting. It doesn't deal with the tag closing,
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
213 * but gtkimhtml widgets give valid html.
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
214 * It currently deals properly with <b>, <u>, <i>, <font face=...>,
16143
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15884
diff changeset
215 * <font color=...>, <span dir=...>, <span style="direction: ...">.
8595
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
216 * It ignores <font back=...> and <font size=...>
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
217 */
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
218 void
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
219 msn_import_html(const char *html, char **attributes, char **message)
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
220 {
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
221 int len, retcount = 0;
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
222 const char *c;
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
223 char *msg;
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
224 char *fontface = NULL;
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
225 char fonteffect[4];
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
226 char fontcolor[7];
16143
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15884
diff changeset
227 char direction = '0';
8595
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
228
15850
882a2d125191 Fixed whitespace and variable naming issues with the patch I accepted in 1b4d3c82ad56354b161862e1a8ff0ebd1877dd03
Evan Schoenberg <evands@pidgin.im>
parents: 15849
diff changeset
229 gboolean has_bold = FALSE;
882a2d125191 Fixed whitespace and variable naming issues with the patch I accepted in 1b4d3c82ad56354b161862e1a8ff0ebd1877dd03
Evan Schoenberg <evands@pidgin.im>
parents: 15849
diff changeset
230 gboolean has_italic = FALSE;
882a2d125191 Fixed whitespace and variable naming issues with the patch I accepted in 1b4d3c82ad56354b161862e1a8ff0ebd1877dd03
Evan Schoenberg <evands@pidgin.im>
parents: 15849
diff changeset
231 gboolean has_underline = FALSE;
882a2d125191 Fixed whitespace and variable naming issues with the patch I accepted in 1b4d3c82ad56354b161862e1a8ff0ebd1877dd03
Evan Schoenberg <evands@pidgin.im>
parents: 15849
diff changeset
232 gboolean has_strikethrough = FALSE;
15849
1b4d3c82ad56 Patch from plivesey, submitted in Adium Trac #5753 (http://trac.adiumx.com/ticket/5753), which fixes a memory stomper which occurred if the msn prpl were passed HTML with multiple style tags of the same type. This doesn't happen in pidgin, because the gtkhtml widget knows that msn can only have one all-or-none instance of each style, but libpurple should be able to handle being passed any sort of HTML. This therefore fixes an Adium crash.
Evan Schoenberg <evands@pidgin.im>
parents: 15435
diff changeset
233
8595
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
234 g_return_if_fail(html != NULL);
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
235 g_return_if_fail(attributes != NULL);
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
236 g_return_if_fail(message != NULL);
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
237
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
238 len = strlen(html);
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
239 msg = g_malloc0(len + 1);
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
240
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
241 memset(fontcolor, 0, sizeof(fontcolor));
10093
e22f76d46b0b [gaim-migrate @ 11111]
Evan Schoenberg <evands@pidgin.im>
parents: 10041
diff changeset
242 strcat(fontcolor, "0");
10041
79adc9cc8e84 [gaim-migrate @ 11000]
Mark Doliner <markdoliner@pidgin.im>
parents: 9331
diff changeset
243 memset(fonteffect, 0, sizeof(fonteffect));
8595
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
244
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
245 for (c = html; *c != '\0';)
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
246 {
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
247 if (*c == '<')
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
248 {
8923
cadbc8e3dfe2 [gaim-migrate @ 9693]
Felipe Contreras <felipe.contreras@gmail.com>
parents: 8921
diff changeset
249 if (!g_ascii_strncasecmp(c + 1, "br>", 3))
cadbc8e3dfe2 [gaim-migrate @ 9693]
Felipe Contreras <felipe.contreras@gmail.com>
parents: 8921
diff changeset
250 {
cadbc8e3dfe2 [gaim-migrate @ 9693]
Felipe Contreras <felipe.contreras@gmail.com>
parents: 8921
diff changeset
251 msg[retcount++] = '\r';
cadbc8e3dfe2 [gaim-migrate @ 9693]
Felipe Contreras <felipe.contreras@gmail.com>
parents: 8921
diff changeset
252 msg[retcount++] = '\n';
cadbc8e3dfe2 [gaim-migrate @ 9693]
Felipe Contreras <felipe.contreras@gmail.com>
parents: 8921
diff changeset
253 c += 4;
cadbc8e3dfe2 [gaim-migrate @ 9693]
Felipe Contreras <felipe.contreras@gmail.com>
parents: 8921
diff changeset
254 }
cadbc8e3dfe2 [gaim-migrate @ 9693]
Felipe Contreras <felipe.contreras@gmail.com>
parents: 8921
diff changeset
255 else if (!g_ascii_strncasecmp(c + 1, "i>", 2))
8595
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
256 {
15850
882a2d125191 Fixed whitespace and variable naming issues with the patch I accepted in 1b4d3c82ad56354b161862e1a8ff0ebd1877dd03
Evan Schoenberg <evands@pidgin.im>
parents: 15849
diff changeset
257 if (!has_italic)
15849
1b4d3c82ad56 Patch from plivesey, submitted in Adium Trac #5753 (http://trac.adiumx.com/ticket/5753), which fixes a memory stomper which occurred if the msn prpl were passed HTML with multiple style tags of the same type. This doesn't happen in pidgin, because the gtkhtml widget knows that msn can only have one all-or-none instance of each style, but libpurple should be able to handle being passed any sort of HTML. This therefore fixes an Adium crash.
Evan Schoenberg <evands@pidgin.im>
parents: 15435
diff changeset
258 {
1b4d3c82ad56 Patch from plivesey, submitted in Adium Trac #5753 (http://trac.adiumx.com/ticket/5753), which fixes a memory stomper which occurred if the msn prpl were passed HTML with multiple style tags of the same type. This doesn't happen in pidgin, because the gtkhtml widget knows that msn can only have one all-or-none instance of each style, but libpurple should be able to handle being passed any sort of HTML. This therefore fixes an Adium crash.
Evan Schoenberg <evands@pidgin.im>
parents: 15435
diff changeset
259 strcat(fonteffect, "I");
15850
882a2d125191 Fixed whitespace and variable naming issues with the patch I accepted in 1b4d3c82ad56354b161862e1a8ff0ebd1877dd03
Evan Schoenberg <evands@pidgin.im>
parents: 15849
diff changeset
260 has_italic = TRUE;
15849
1b4d3c82ad56 Patch from plivesey, submitted in Adium Trac #5753 (http://trac.adiumx.com/ticket/5753), which fixes a memory stomper which occurred if the msn prpl were passed HTML with multiple style tags of the same type. This doesn't happen in pidgin, because the gtkhtml widget knows that msn can only have one all-or-none instance of each style, but libpurple should be able to handle being passed any sort of HTML. This therefore fixes an Adium crash.
Evan Schoenberg <evands@pidgin.im>
parents: 15435
diff changeset
261 }
8595
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
262 c += 3;
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
263 }
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
264 else if (!g_ascii_strncasecmp(c + 1, "b>", 2))
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
265 {
15850
882a2d125191 Fixed whitespace and variable naming issues with the patch I accepted in 1b4d3c82ad56354b161862e1a8ff0ebd1877dd03
Evan Schoenberg <evands@pidgin.im>
parents: 15849
diff changeset
266 if (!has_bold)
15849
1b4d3c82ad56 Patch from plivesey, submitted in Adium Trac #5753 (http://trac.adiumx.com/ticket/5753), which fixes a memory stomper which occurred if the msn prpl were passed HTML with multiple style tags of the same type. This doesn't happen in pidgin, because the gtkhtml widget knows that msn can only have one all-or-none instance of each style, but libpurple should be able to handle being passed any sort of HTML. This therefore fixes an Adium crash.
Evan Schoenberg <evands@pidgin.im>
parents: 15435
diff changeset
267 {
1b4d3c82ad56 Patch from plivesey, submitted in Adium Trac #5753 (http://trac.adiumx.com/ticket/5753), which fixes a memory stomper which occurred if the msn prpl were passed HTML with multiple style tags of the same type. This doesn't happen in pidgin, because the gtkhtml widget knows that msn can only have one all-or-none instance of each style, but libpurple should be able to handle being passed any sort of HTML. This therefore fixes an Adium crash.
Evan Schoenberg <evands@pidgin.im>
parents: 15435
diff changeset
268 strcat(fonteffect, "B");
15850
882a2d125191 Fixed whitespace and variable naming issues with the patch I accepted in 1b4d3c82ad56354b161862e1a8ff0ebd1877dd03
Evan Schoenberg <evands@pidgin.im>
parents: 15849
diff changeset
269 has_bold = TRUE;
15849
1b4d3c82ad56 Patch from plivesey, submitted in Adium Trac #5753 (http://trac.adiumx.com/ticket/5753), which fixes a memory stomper which occurred if the msn prpl were passed HTML with multiple style tags of the same type. This doesn't happen in pidgin, because the gtkhtml widget knows that msn can only have one all-or-none instance of each style, but libpurple should be able to handle being passed any sort of HTML. This therefore fixes an Adium crash.
Evan Schoenberg <evands@pidgin.im>
parents: 15435
diff changeset
270 }
8595
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
271 c += 3;
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
272 }
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
273 else if (!g_ascii_strncasecmp(c + 1, "u>", 2))
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
274 {
15850
882a2d125191 Fixed whitespace and variable naming issues with the patch I accepted in 1b4d3c82ad56354b161862e1a8ff0ebd1877dd03
Evan Schoenberg <evands@pidgin.im>
parents: 15849
diff changeset
275 if (!has_underline)
15849
1b4d3c82ad56 Patch from plivesey, submitted in Adium Trac #5753 (http://trac.adiumx.com/ticket/5753), which fixes a memory stomper which occurred if the msn prpl were passed HTML with multiple style tags of the same type. This doesn't happen in pidgin, because the gtkhtml widget knows that msn can only have one all-or-none instance of each style, but libpurple should be able to handle being passed any sort of HTML. This therefore fixes an Adium crash.
Evan Schoenberg <evands@pidgin.im>
parents: 15435
diff changeset
276 {
1b4d3c82ad56 Patch from plivesey, submitted in Adium Trac #5753 (http://trac.adiumx.com/ticket/5753), which fixes a memory stomper which occurred if the msn prpl were passed HTML with multiple style tags of the same type. This doesn't happen in pidgin, because the gtkhtml widget knows that msn can only have one all-or-none instance of each style, but libpurple should be able to handle being passed any sort of HTML. This therefore fixes an Adium crash.
Evan Schoenberg <evands@pidgin.im>
parents: 15435
diff changeset
277 strcat(fonteffect, "U");
15850
882a2d125191 Fixed whitespace and variable naming issues with the patch I accepted in 1b4d3c82ad56354b161862e1a8ff0ebd1877dd03
Evan Schoenberg <evands@pidgin.im>
parents: 15849
diff changeset
278 has_underline = TRUE;
15849
1b4d3c82ad56 Patch from plivesey, submitted in Adium Trac #5753 (http://trac.adiumx.com/ticket/5753), which fixes a memory stomper which occurred if the msn prpl were passed HTML with multiple style tags of the same type. This doesn't happen in pidgin, because the gtkhtml widget knows that msn can only have one all-or-none instance of each style, but libpurple should be able to handle being passed any sort of HTML. This therefore fixes an Adium crash.
Evan Schoenberg <evands@pidgin.im>
parents: 15435
diff changeset
279 }
8595
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
280 c += 3;
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
281 }
10274
f329b1d7fd43 [gaim-migrate @ 11424]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10093
diff changeset
282 else if (!g_ascii_strncasecmp(c + 1, "s>", 2))
f329b1d7fd43 [gaim-migrate @ 11424]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10093
diff changeset
283 {
15850
882a2d125191 Fixed whitespace and variable naming issues with the patch I accepted in 1b4d3c82ad56354b161862e1a8ff0ebd1877dd03
Evan Schoenberg <evands@pidgin.im>
parents: 15849
diff changeset
284 if (!has_strikethrough)
15849
1b4d3c82ad56 Patch from plivesey, submitted in Adium Trac #5753 (http://trac.adiumx.com/ticket/5753), which fixes a memory stomper which occurred if the msn prpl were passed HTML with multiple style tags of the same type. This doesn't happen in pidgin, because the gtkhtml widget knows that msn can only have one all-or-none instance of each style, but libpurple should be able to handle being passed any sort of HTML. This therefore fixes an Adium crash.
Evan Schoenberg <evands@pidgin.im>
parents: 15435
diff changeset
285 {
1b4d3c82ad56 Patch from plivesey, submitted in Adium Trac #5753 (http://trac.adiumx.com/ticket/5753), which fixes a memory stomper which occurred if the msn prpl were passed HTML with multiple style tags of the same type. This doesn't happen in pidgin, because the gtkhtml widget knows that msn can only have one all-or-none instance of each style, but libpurple should be able to handle being passed any sort of HTML. This therefore fixes an Adium crash.
Evan Schoenberg <evands@pidgin.im>
parents: 15435
diff changeset
286 strcat(fonteffect, "S");
15850
882a2d125191 Fixed whitespace and variable naming issues with the patch I accepted in 1b4d3c82ad56354b161862e1a8ff0ebd1877dd03
Evan Schoenberg <evands@pidgin.im>
parents: 15849
diff changeset
287 has_strikethrough = TRUE;
15849
1b4d3c82ad56 Patch from plivesey, submitted in Adium Trac #5753 (http://trac.adiumx.com/ticket/5753), which fixes a memory stomper which occurred if the msn prpl were passed HTML with multiple style tags of the same type. This doesn't happen in pidgin, because the gtkhtml widget knows that msn can only have one all-or-none instance of each style, but libpurple should be able to handle being passed any sort of HTML. This therefore fixes an Adium crash.
Evan Schoenberg <evands@pidgin.im>
parents: 15435
diff changeset
288 }
10274
f329b1d7fd43 [gaim-migrate @ 11424]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10093
diff changeset
289 c += 3;
f329b1d7fd43 [gaim-migrate @ 11424]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10093
diff changeset
290 }
8595
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
291 else if (!g_ascii_strncasecmp(c + 1, "a href=\"", 8))
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
292 {
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
293 c += 9;
10274
f329b1d7fd43 [gaim-migrate @ 11424]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10093
diff changeset
294
9331
adae1d519c83 [gaim-migrate @ 10139]
Nelson Elhage
parents: 9264
diff changeset
295 if (!g_ascii_strncasecmp(c, "mailto:", 7))
adae1d519c83 [gaim-migrate @ 10139]
Nelson Elhage
parents: 9264
diff changeset
296 c += 7;
8595
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
297
11176
a7b860aa756e [gaim-migrate @ 13283]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10274
diff changeset
298 while ((*c != '\0') && g_ascii_strncasecmp(c, "\">", 2))
8595
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
299 msg[retcount++] = *c++;
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
300
11176
a7b860aa756e [gaim-migrate @ 13283]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10274
diff changeset
301 if (*c != '\0')
a7b860aa756e [gaim-migrate @ 13283]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10274
diff changeset
302 c += 2;
8595
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
303
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
304 /* ignore descriptive string */
11176
a7b860aa756e [gaim-migrate @ 13283]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10274
diff changeset
305 while ((*c != '\0') && g_ascii_strncasecmp(c, "</a>", 4))
8595
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
306 c++;
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
307
11176
a7b860aa756e [gaim-migrate @ 13283]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10274
diff changeset
308 if (*c != '\0')
a7b860aa756e [gaim-migrate @ 13283]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10274
diff changeset
309 c += 4;
8595
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
310 }
16143
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15884
diff changeset
311 else if (!g_ascii_strncasecmp(c + 1, "span", 4))
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15884
diff changeset
312 {
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15884
diff changeset
313 /* Bi-directional text support using CSS properties in span tags */
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15884
diff changeset
314 c += 5;
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15884
diff changeset
315
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15884
diff changeset
316 while (*c != '\0' && *c != '>')
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15884
diff changeset
317 {
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15884
diff changeset
318 while (*c == ' ')
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15884
diff changeset
319 c++;
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15884
diff changeset
320 if (!g_ascii_strncasecmp(c, "dir=\"rtl\"", 9))
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15884
diff changeset
321 {
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15884
diff changeset
322 c += 9;
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15884
diff changeset
323 direction = '1';
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15884
diff changeset
324 }
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15884
diff changeset
325 else if (!g_ascii_strncasecmp(c, "style=\"", 7))
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15884
diff changeset
326 {
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15884
diff changeset
327 /* Parse inline CSS attributes */
16144
4e022531d1c9 Patch cleanups:
Richard Laager <rlaager@pidgin.im>
parents: 16143
diff changeset
328 char *attributes;
16143
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15884
diff changeset
329 int attr_len = 0;
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15884
diff changeset
330 c += 7;
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15884
diff changeset
331 while (*(c + attr_len) != '\0' && *(c + attr_len) != '"')
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15884
diff changeset
332 attr_len++;
16144
4e022531d1c9 Patch cleanups:
Richard Laager <rlaager@pidgin.im>
parents: 16143
diff changeset
333 if (*(c + attr_len) == '"')
16143
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15884
diff changeset
334 {
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15884
diff changeset
335 char *attr_dir;
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15884
diff changeset
336 attributes = g_strndup(c, attr_len);
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15884
diff changeset
337 attr_dir = purple_markup_get_css_property(attributes, "direction");
18552
810a338ef085 Use the glib strcasecmp functions everywhere, as we've had reports of
Richard Laager <rlaager@pidgin.im>
parents: 16144
diff changeset
338 if (attr_dir && (!g_ascii_strncasecmp(attr_dir, "RTL", 3)))
16143
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15884
diff changeset
339 direction = '1';
16144
4e022531d1c9 Patch cleanups:
Richard Laager <rlaager@pidgin.im>
parents: 16143
diff changeset
340 g_free(attr_dir);
4e022531d1c9 Patch cleanups:
Richard Laager <rlaager@pidgin.im>
parents: 16143
diff changeset
341 g_free(attributes);
16143
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15884
diff changeset
342 }
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15884
diff changeset
343
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15884
diff changeset
344 }
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15884
diff changeset
345 else
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15884
diff changeset
346 {
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15884
diff changeset
347 c++;
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15884
diff changeset
348 }
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15884
diff changeset
349 }
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15884
diff changeset
350 if (*c == '>')
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15884
diff changeset
351 c++;
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15884
diff changeset
352 }
8595
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
353 else if (!g_ascii_strncasecmp(c + 1, "font", 4))
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
354 {
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
355 c += 5;
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
356
11176
a7b860aa756e [gaim-migrate @ 13283]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10274
diff changeset
357 while ((*c != '\0') && !g_ascii_strncasecmp(c, " ", 1))
8595
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
358 c++;
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
359
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
360 if (!g_ascii_strncasecmp(c, "color=\"#", 7))
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
361 {
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
362 c += 8;
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
363
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
364 fontcolor[0] = *(c + 4);
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
365 fontcolor[1] = *(c + 5);
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
366 fontcolor[2] = *(c + 2);
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
367 fontcolor[3] = *(c + 3);
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
368 fontcolor[4] = *c;
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
369 fontcolor[5] = *(c + 1);
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
370
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
371 c += 8;
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
372 }
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
373 else if (!g_ascii_strncasecmp(c, "face=\"", 6))
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
374 {
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
375 const char *end = NULL;
8921
5daa40528148 [gaim-migrate @ 9691]
Felipe Contreras <felipe.contreras@gmail.com>
parents: 8691
diff changeset
376 const char *comma = NULL;
8595
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
377 unsigned int namelen = 0;
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
378
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
379 c += 6;
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
380 end = strchr(c, '\"');
8921
5daa40528148 [gaim-migrate @ 9691]
Felipe Contreras <felipe.contreras@gmail.com>
parents: 8691
diff changeset
381 comma = strchr(c, ',');
5daa40528148 [gaim-migrate @ 9691]
Felipe Contreras <felipe.contreras@gmail.com>
parents: 8691
diff changeset
382
9090
2c7655380bf5 [gaim-migrate @ 9867]
Christian Hammond <chipx86@chipx86.com>
parents: 8923
diff changeset
383 if (comma == NULL || comma > end)
2c7655380bf5 [gaim-migrate @ 9867]
Christian Hammond <chipx86@chipx86.com>
parents: 8923
diff changeset
384 namelen = (unsigned int)(end - c);
2c7655380bf5 [gaim-migrate @ 9867]
Christian Hammond <chipx86@chipx86.com>
parents: 8923
diff changeset
385 else
2c7655380bf5 [gaim-migrate @ 9867]
Christian Hammond <chipx86@chipx86.com>
parents: 8923
diff changeset
386 namelen = (unsigned int)(comma - c);
8921
5daa40528148 [gaim-migrate @ 9691]
Felipe Contreras <felipe.contreras@gmail.com>
parents: 8691
diff changeset
387
8595
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
388 fontface = g_strndup(c, namelen);
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
389 c = end + 2;
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
390 }
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
391 else
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
392 {
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
393 /* Drop all unrecognized/misparsed font tags */
11176
a7b860aa756e [gaim-migrate @ 13283]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10274
diff changeset
394 while ((*c != '\0') && g_ascii_strncasecmp(c, "\">", 2))
8595
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
395 c++;
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
396
11176
a7b860aa756e [gaim-migrate @ 13283]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10274
diff changeset
397 if (*c != '\0')
a7b860aa756e [gaim-migrate @ 13283]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10274
diff changeset
398 c += 2;
8595
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
399 }
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
400 }
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
401 else
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
402 {
11176
a7b860aa756e [gaim-migrate @ 13283]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10274
diff changeset
403 while ((*c != '\0') && (*c != '>'))
8595
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
404 c++;
11176
a7b860aa756e [gaim-migrate @ 13283]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10274
diff changeset
405 if (*c != '\0')
a7b860aa756e [gaim-migrate @ 13283]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 10274
diff changeset
406 c++;
8595
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
407 }
8921
5daa40528148 [gaim-migrate @ 9691]
Felipe Contreras <felipe.contreras@gmail.com>
parents: 8691
diff changeset
408 }
5daa40528148 [gaim-migrate @ 9691]
Felipe Contreras <felipe.contreras@gmail.com>
parents: 8691
diff changeset
409 else if (*c == '&')
5daa40528148 [gaim-migrate @ 9691]
Felipe Contreras <felipe.contreras@gmail.com>
parents: 8691
diff changeset
410 {
5daa40528148 [gaim-migrate @ 9691]
Felipe Contreras <felipe.contreras@gmail.com>
parents: 8691
diff changeset
411 if (!g_ascii_strncasecmp(c, "&lt;", 4))
5daa40528148 [gaim-migrate @ 9691]
Felipe Contreras <felipe.contreras@gmail.com>
parents: 8691
diff changeset
412 {
8678
28a0fcb15385 [gaim-migrate @ 9431]
Sean Egan <seanegan@pidgin.im>
parents: 8646
diff changeset
413 msg[retcount++] = '<';
28a0fcb15385 [gaim-migrate @ 9431]
Sean Egan <seanegan@pidgin.im>
parents: 8646
diff changeset
414 c += 4;
8921
5daa40528148 [gaim-migrate @ 9691]
Felipe Contreras <felipe.contreras@gmail.com>
parents: 8691
diff changeset
415 }
5daa40528148 [gaim-migrate @ 9691]
Felipe Contreras <felipe.contreras@gmail.com>
parents: 8691
diff changeset
416 else if (!g_ascii_strncasecmp(c, "&gt;", 4))
5daa40528148 [gaim-migrate @ 9691]
Felipe Contreras <felipe.contreras@gmail.com>
parents: 8691
diff changeset
417 {
8678
28a0fcb15385 [gaim-migrate @ 9431]
Sean Egan <seanegan@pidgin.im>
parents: 8646
diff changeset
418 msg[retcount++] = '>';
28a0fcb15385 [gaim-migrate @ 9431]
Sean Egan <seanegan@pidgin.im>
parents: 8646
diff changeset
419 c += 4;
8921
5daa40528148 [gaim-migrate @ 9691]
Felipe Contreras <felipe.contreras@gmail.com>
parents: 8691
diff changeset
420 }
9264
082e824358cf [gaim-migrate @ 10063]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 9198
diff changeset
421 else if (!g_ascii_strncasecmp(c, "&nbsp;", 6))
082e824358cf [gaim-migrate @ 10063]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 9198
diff changeset
422 {
082e824358cf [gaim-migrate @ 10063]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 9198
diff changeset
423 msg[retcount++] = ' ';
082e824358cf [gaim-migrate @ 10063]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 9198
diff changeset
424 c += 6;
082e824358cf [gaim-migrate @ 10063]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 9198
diff changeset
425 }
8921
5daa40528148 [gaim-migrate @ 9691]
Felipe Contreras <felipe.contreras@gmail.com>
parents: 8691
diff changeset
426 else if (!g_ascii_strncasecmp(c, "&quot;", 6))
5daa40528148 [gaim-migrate @ 9691]
Felipe Contreras <felipe.contreras@gmail.com>
parents: 8691
diff changeset
427 {
8678
28a0fcb15385 [gaim-migrate @ 9431]
Sean Egan <seanegan@pidgin.im>
parents: 8646
diff changeset
428 msg[retcount++] = '"';
28a0fcb15385 [gaim-migrate @ 9431]
Sean Egan <seanegan@pidgin.im>
parents: 8646
diff changeset
429 c += 6;
8921
5daa40528148 [gaim-migrate @ 9691]
Felipe Contreras <felipe.contreras@gmail.com>
parents: 8691
diff changeset
430 }
5daa40528148 [gaim-migrate @ 9691]
Felipe Contreras <felipe.contreras@gmail.com>
parents: 8691
diff changeset
431 else if (!g_ascii_strncasecmp(c, "&amp;", 5))
5daa40528148 [gaim-migrate @ 9691]
Felipe Contreras <felipe.contreras@gmail.com>
parents: 8691
diff changeset
432 {
8678
28a0fcb15385 [gaim-migrate @ 9431]
Sean Egan <seanegan@pidgin.im>
parents: 8646
diff changeset
433 msg[retcount++] = '&';
28a0fcb15385 [gaim-migrate @ 9431]
Sean Egan <seanegan@pidgin.im>
parents: 8646
diff changeset
434 c += 5;
28a0fcb15385 [gaim-migrate @ 9431]
Sean Egan <seanegan@pidgin.im>
parents: 8646
diff changeset
435 }
9264
082e824358cf [gaim-migrate @ 10063]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 9198
diff changeset
436 else if (!g_ascii_strncasecmp(c, "&apos;", 6))
082e824358cf [gaim-migrate @ 10063]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 9198
diff changeset
437 {
082e824358cf [gaim-migrate @ 10063]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 9198
diff changeset
438 msg[retcount++] = '\'';
082e824358cf [gaim-migrate @ 10063]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 9198
diff changeset
439 c += 6;
082e824358cf [gaim-migrate @ 10063]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 9198
diff changeset
440 }
082e824358cf [gaim-migrate @ 10063]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 9198
diff changeset
441 else
082e824358cf [gaim-migrate @ 10063]
Stu Tomlinson <nosnilmot@pidgin.im>
parents: 9198
diff changeset
442 msg[retcount++] = *c++;
8921
5daa40528148 [gaim-migrate @ 9691]
Felipe Contreras <felipe.contreras@gmail.com>
parents: 8691
diff changeset
443 }
5daa40528148 [gaim-migrate @ 9691]
Felipe Contreras <felipe.contreras@gmail.com>
parents: 8691
diff changeset
444 else
8595
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
445 msg[retcount++] = *c++;
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
446 }
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
447
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
448 if (fontface == NULL)
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
449 fontface = g_strdup("MS Sans Serif");
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
450
16143
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15884
diff changeset
451 *attributes = g_strdup_printf("FN=%s; EF=%s; CO=%s; PF=0; RL=%c",
8595
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
452 encode_spaces(fontface),
16143
6393e5b11ff5 Patch from shlomil in ticket #78.
Shlomi Loubaton <shlomister@gmail.com>
parents: 15884
diff changeset
453 fonteffect, fontcolor, direction);
21059
eb2a23e2dd0f Avoid unnecessary alloc/free.
Daniel Atallah <datallah@pidgin.im>
parents: 20747
diff changeset
454 *message = msg;
8595
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
455
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
456 g_free(fontface);
c751f6b0260e [gaim-migrate @ 9346]
Christian Hammond <chipx86@chipx86.com>
parents: 8530
diff changeset
457 }
9193
6e76f1367896 [gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents: 9090
diff changeset
458
6e76f1367896 [gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents: 9090
diff changeset
459 void
6e76f1367896 [gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents: 9090
diff changeset
460 msn_parse_socket(const char *str, char **ret_host, int *ret_port)
6e76f1367896 [gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents: 9090
diff changeset
461 {
6e76f1367896 [gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents: 9090
diff changeset
462 char *host;
6e76f1367896 [gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents: 9090
diff changeset
463 char *c;
6e76f1367896 [gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents: 9090
diff changeset
464 int port;
6e76f1367896 [gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents: 9090
diff changeset
465
6e76f1367896 [gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents: 9090
diff changeset
466 host = g_strdup(str);
6e76f1367896 [gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents: 9090
diff changeset
467
23808
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
468 if ((c = strchr(host, ':')) != NULL) {
9193
6e76f1367896 [gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents: 9090
diff changeset
469 *c = '\0';
6e76f1367896 [gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents: 9090
diff changeset
470 port = atoi(c + 1);
23808
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
471 } else {
20483
45d3a4773e1b propagate from branch 'im.pidgin.rlaager.merging.msnp13-and-sf-1621854-4' (head cd47bac1af94287a1145874b9ed7a153fd1fb8bd)
Richard Laager <rlaager@pidgin.im>
parents: 16144
diff changeset
472 port = 1863;
9193
6e76f1367896 [gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents: 9090
diff changeset
473 }
6e76f1367896 [gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents: 9090
diff changeset
474
6e76f1367896 [gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents: 9090
diff changeset
475 *ret_host = host;
6e76f1367896 [gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents: 9090
diff changeset
476 *ret_port = port;
6e76f1367896 [gaim-migrate @ 9988]
Felipe Contreras <felipe.contreras@gmail.com>
parents: 9090
diff changeset
477 }
20483
45d3a4773e1b propagate from branch 'im.pidgin.rlaager.merging.msnp13-and-sf-1621854-4' (head cd47bac1af94287a1145874b9ed7a153fd1fb8bd)
Richard Laager <rlaager@pidgin.im>
parents: 16144
diff changeset
478
45d3a4773e1b propagate from branch 'im.pidgin.rlaager.merging.msnp13-and-sf-1621854-4' (head cd47bac1af94287a1145874b9ed7a153fd1fb8bd)
Richard Laager <rlaager@pidgin.im>
parents: 16144
diff changeset
479 /***************************************************************************
45d3a4773e1b propagate from branch 'im.pidgin.rlaager.merging.msnp13-and-sf-1621854-4' (head cd47bac1af94287a1145874b9ed7a153fd1fb8bd)
Richard Laager <rlaager@pidgin.im>
parents: 16144
diff changeset
480 * MSN Challenge Computing Function
45d3a4773e1b propagate from branch 'im.pidgin.rlaager.merging.msnp13-and-sf-1621854-4' (head cd47bac1af94287a1145874b9ed7a153fd1fb8bd)
Richard Laager <rlaager@pidgin.im>
parents: 16144
diff changeset
481 ***************************************************************************/
45d3a4773e1b propagate from branch 'im.pidgin.rlaager.merging.msnp13-and-sf-1621854-4' (head cd47bac1af94287a1145874b9ed7a153fd1fb8bd)
Richard Laager <rlaager@pidgin.im>
parents: 16144
diff changeset
482
45d3a4773e1b propagate from branch 'im.pidgin.rlaager.merging.msnp13-and-sf-1621854-4' (head cd47bac1af94287a1145874b9ed7a153fd1fb8bd)
Richard Laager <rlaager@pidgin.im>
parents: 16144
diff changeset
483 /*
23808
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
484 * Handle MSN Challenge computation
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
485 * This algorithm references
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
486 * http://imfreedom.org/wiki/index.php/MSN:NS/Challenges
20483
45d3a4773e1b propagate from branch 'im.pidgin.rlaager.merging.msnp13-and-sf-1621854-4' (head cd47bac1af94287a1145874b9ed7a153fd1fb8bd)
Richard Laager <rlaager@pidgin.im>
parents: 16144
diff changeset
487 */
45d3a4773e1b propagate from branch 'im.pidgin.rlaager.merging.msnp13-and-sf-1621854-4' (head cd47bac1af94287a1145874b9ed7a153fd1fb8bd)
Richard Laager <rlaager@pidgin.im>
parents: 16144
diff changeset
488 #define BUFSIZE 256
23441
fd45c23a3eb2 Delete trailing whitespace
Mark Doliner <markdoliner@pidgin.im>
parents: 22518
diff changeset
489 void
20483
45d3a4773e1b propagate from branch 'im.pidgin.rlaager.merging.msnp13-and-sf-1621854-4' (head cd47bac1af94287a1145874b9ed7a153fd1fb8bd)
Richard Laager <rlaager@pidgin.im>
parents: 16144
diff changeset
490 msn_handle_chl(char *input, char *output)
45d3a4773e1b propagate from branch 'im.pidgin.rlaager.merging.msnp13-and-sf-1621854-4' (head cd47bac1af94287a1145874b9ed7a153fd1fb8bd)
Richard Laager <rlaager@pidgin.im>
parents: 16144
diff changeset
491 {
23808
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
492 PurpleCipher *cipher;
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
493 PurpleCipherContext *context;
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
494 const guchar productKey[] = MSNP15_WLM_PRODUCT_KEY;
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
495 const guchar productID[] = MSNP15_WLM_PRODUCT_ID;
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
496 const char hexChars[] = "0123456789abcdef";
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
497 char buf[BUFSIZE];
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
498 unsigned char md5Hash[16];
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
499 unsigned char *newHash;
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
500 unsigned int *md5Parts;
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
501 unsigned int *chlStringParts;
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
502 unsigned int newHashParts[5];
20483
45d3a4773e1b propagate from branch 'im.pidgin.rlaager.merging.msnp13-and-sf-1621854-4' (head cd47bac1af94287a1145874b9ed7a153fd1fb8bd)
Richard Laager <rlaager@pidgin.im>
parents: 16144
diff changeset
503
23808
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
504 long long nHigh = 0, nLow = 0;
20483
45d3a4773e1b propagate from branch 'im.pidgin.rlaager.merging.msnp13-and-sf-1621854-4' (head cd47bac1af94287a1145874b9ed7a153fd1fb8bd)
Richard Laager <rlaager@pidgin.im>
parents: 16144
diff changeset
505
23808
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
506 int len;
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
507 int i;
20483
45d3a4773e1b propagate from branch 'im.pidgin.rlaager.merging.msnp13-and-sf-1621854-4' (head cd47bac1af94287a1145874b9ed7a153fd1fb8bd)
Richard Laager <rlaager@pidgin.im>
parents: 16144
diff changeset
508
23808
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
509 /* Create the MD5 hash by using Purple MD5 algorithm */
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
510 cipher = purple_ciphers_find_cipher("md5");
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
511 context = purple_cipher_context_new(cipher, NULL);
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
512
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
513 purple_cipher_context_append(context, (guchar *)input, strlen(input));
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
514 purple_cipher_context_append(context, productKey, sizeof(productKey) - 1);
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
515 purple_cipher_context_digest(context, sizeof(md5Hash), md5Hash, NULL);
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
516 purple_cipher_context_destroy(context);
20483
45d3a4773e1b propagate from branch 'im.pidgin.rlaager.merging.msnp13-and-sf-1621854-4' (head cd47bac1af94287a1145874b9ed7a153fd1fb8bd)
Richard Laager <rlaager@pidgin.im>
parents: 16144
diff changeset
517
23808
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
518 /* Split it into four integers */
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
519 md5Parts = (unsigned int *)md5Hash;
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
520 for (i = 0; i < 4; i++) {
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
521 /* adjust endianess */
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
522 md5Parts[i] = GUINT_TO_LE(md5Parts[i]);
20483
45d3a4773e1b propagate from branch 'im.pidgin.rlaager.merging.msnp13-and-sf-1621854-4' (head cd47bac1af94287a1145874b9ed7a153fd1fb8bd)
Richard Laager <rlaager@pidgin.im>
parents: 16144
diff changeset
523
23808
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
524 /* & each integer with 0x7FFFFFFF */
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
525 /* and save one unmodified array for later */
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
526 newHashParts[i] = md5Parts[i];
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
527 md5Parts[i] &= 0x7FFFFFFF;
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
528 }
20483
45d3a4773e1b propagate from branch 'im.pidgin.rlaager.merging.msnp13-and-sf-1621854-4' (head cd47bac1af94287a1145874b9ed7a153fd1fb8bd)
Richard Laager <rlaager@pidgin.im>
parents: 16144
diff changeset
529
23808
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
530 /* make a new string and pad with '0' to length that's a multiple of 8 */
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
531 snprintf(buf, BUFSIZE - 5, "%s%s", input, productID);
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
532 len = strlen(buf);
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
533 if ((len % 8) != 0) {
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
534 int fix = 8 - (len % 8);
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
535 memset(&buf[len], '0', fix);
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
536 buf[len + fix] = '\0';
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
537 len += fix;
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
538 }
20483
45d3a4773e1b propagate from branch 'im.pidgin.rlaager.merging.msnp13-and-sf-1621854-4' (head cd47bac1af94287a1145874b9ed7a153fd1fb8bd)
Richard Laager <rlaager@pidgin.im>
parents: 16144
diff changeset
539
23808
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
540 /* split into integers */
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
541 chlStringParts = (unsigned int *)buf;
20483
45d3a4773e1b propagate from branch 'im.pidgin.rlaager.merging.msnp13-and-sf-1621854-4' (head cd47bac1af94287a1145874b9ed7a153fd1fb8bd)
Richard Laager <rlaager@pidgin.im>
parents: 16144
diff changeset
542
23808
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
543 /* this is magic */
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
544 for (i = 0; i < (strlen(buf) / 4); i += 2) {
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
545 long long temp;
20483
45d3a4773e1b propagate from branch 'im.pidgin.rlaager.merging.msnp13-and-sf-1621854-4' (head cd47bac1af94287a1145874b9ed7a153fd1fb8bd)
Richard Laager <rlaager@pidgin.im>
parents: 16144
diff changeset
546
23808
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
547 chlStringParts[i] = GUINT_TO_LE(chlStringParts[i]);
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
548 chlStringParts[i + 1] = GUINT_TO_LE(chlStringParts[i + 1]);
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
549
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
550 temp = (0x0E79A9C1 * (long long)chlStringParts[i]) % 0x7FFFFFFF;
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
551 temp = (md5Parts[0] * (temp + nLow) + md5Parts[1]) % 0x7FFFFFFF;
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
552 nHigh += temp;
20483
45d3a4773e1b propagate from branch 'im.pidgin.rlaager.merging.msnp13-and-sf-1621854-4' (head cd47bac1af94287a1145874b9ed7a153fd1fb8bd)
Richard Laager <rlaager@pidgin.im>
parents: 16144
diff changeset
553
23808
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
554 temp = ((long long)chlStringParts[i + 1] + temp) % 0x7FFFFFFF;
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
555 nLow = (md5Parts[2] * temp + md5Parts[3]) % 0x7FFFFFFF;
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
556 nHigh += nLow;
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
557 }
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
558 nLow = (nLow + md5Parts[1]) % 0x7FFFFFFF;
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
559 nHigh = (nHigh + md5Parts[3]) % 0x7FFFFFFF;
20483
45d3a4773e1b propagate from branch 'im.pidgin.rlaager.merging.msnp13-and-sf-1621854-4' (head cd47bac1af94287a1145874b9ed7a153fd1fb8bd)
Richard Laager <rlaager@pidgin.im>
parents: 16144
diff changeset
560
23808
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
561 newHashParts[0] ^= nLow;
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
562 newHashParts[1] ^= nHigh;
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
563 newHashParts[2] ^= nLow;
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
564 newHashParts[3] ^= nHigh;
20483
45d3a4773e1b propagate from branch 'im.pidgin.rlaager.merging.msnp13-and-sf-1621854-4' (head cd47bac1af94287a1145874b9ed7a153fd1fb8bd)
Richard Laager <rlaager@pidgin.im>
parents: 16144
diff changeset
565
23808
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
566 /* adjust endianness */
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
567 for(i = 0; i < 4; i++)
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
568 newHashParts[i] = GUINT_TO_LE(newHashParts[i]);
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
569
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
570 /* make a string of the parts */
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
571 newHash = (unsigned char *)newHashParts;
20483
45d3a4773e1b propagate from branch 'im.pidgin.rlaager.merging.msnp13-and-sf-1621854-4' (head cd47bac1af94287a1145874b9ed7a153fd1fb8bd)
Richard Laager <rlaager@pidgin.im>
parents: 16144
diff changeset
572
23808
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
573 /* convert to hexadecimal */
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
574 for (i = 0; i < 16; i++)
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
575 {
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
576 output[i * 2] = hexChars[(newHash[i] >> 4) & 0xF];
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
577 output[(i * 2) + 1] = hexChars[newHash[i] & 0xF];
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
578 }
20483
45d3a4773e1b propagate from branch 'im.pidgin.rlaager.merging.msnp13-and-sf-1621854-4' (head cd47bac1af94287a1145874b9ed7a153fd1fb8bd)
Richard Laager <rlaager@pidgin.im>
parents: 16144
diff changeset
579
23808
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
580 output[32] = '\0';
20483
45d3a4773e1b propagate from branch 'im.pidgin.rlaager.merging.msnp13-and-sf-1621854-4' (head cd47bac1af94287a1145874b9ed7a153fd1fb8bd)
Richard Laager <rlaager@pidgin.im>
parents: 16144
diff changeset
581 }
23808
4586e4ec8831 Fix calculating the response to MSN Challenge strings that are an exact
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 23776
diff changeset
582

mercurial