annotate src/protocols/msn/msn-utils.c @ 19788:8b4653986e8e

[gaim-migrate @ 16600] change to add SOAP HTTP header retrieve Now Can do the OIM Message XML process submitted by Ma Yuan<mayuan2006@gmail.com> committer: Ethan Blanton <elb@pidgin.im>
author Ma Yuan <mayuan2006@gmail.com>
date Sun, 30 Jul 2006 13:44:34 +0000
parents 852b32710df0
children b22d13f55232
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13627
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
1 /**
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
2 * @file msn-utils.c Utility functions
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
3 *
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
4 * gaim
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
5 *
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
6 * Gaim is the legal property of its developers, whose names are too numerous
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
7 * to list here. Please refer to the COPYRIGHT file distributed with this
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
8 * source distribution.
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
9 *
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
10 * This program is free software; you can redistribute it and/or modify
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
11 * it under the terms of the GNU General Public License as published by
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
12 * the Free Software Foundation; either version 2 of the License, or
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
13 * (at your option) any later version.
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
14 *
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
15 * This program is distributed in the hope that it will be useful,
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
18 * GNU General Public License for more details.
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
19 *
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
20 * You should have received a copy of the GNU General Public License
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
21 * along with this program; if not, write to the Free Software
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
23 */
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
24 #include "msn.h"
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
25 #include "msn-utils.h"
19785
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
26 //#include <openssl/md5.h>
13627
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
27
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
28 void
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
29 msn_parse_format(const char *mime, char **pre_ret, char **post_ret)
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
30 {
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
31 char *cur;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
32 GString *pre = g_string_new(NULL);
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
33 GString *post = g_string_new(NULL);
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
34 unsigned int colors[3];
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
35
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
36 if (pre_ret != NULL) *pre_ret = NULL;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
37 if (post_ret != NULL) *post_ret = NULL;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
38
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
39 cur = strstr(mime, "FN=");
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
40
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
41 if (cur && (*(cur = cur + 3) != ';'))
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
42 {
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
43 pre = g_string_append(pre, "<FONT FACE=\"");
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
44
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
45 while (*cur && *cur != ';')
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
46 {
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
47 pre = g_string_append_c(pre, *cur);
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
48 cur++;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
49 }
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
50
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
51 pre = g_string_append(pre, "\">");
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
52 post = g_string_prepend(post, "</FONT>");
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
53 }
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
54
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
55 cur = strstr(mime, "EF=");
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
56
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
57 if (cur && (*(cur = cur + 3) != ';'))
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
58 {
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
59 while (*cur && *cur != ';')
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
60 {
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
61 pre = g_string_append_c(pre, '<');
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
62 pre = g_string_append_c(pre, *cur);
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
63 pre = g_string_append_c(pre, '>');
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
64 post = g_string_prepend_c(post, '>');
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
65 post = g_string_prepend_c(post, *cur);
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
66 post = g_string_prepend_c(post, '/');
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
67 post = g_string_prepend_c(post, '<');
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
68 cur++;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
69 }
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
70 }
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
71
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
72 cur = strstr(mime, "CO=");
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
73
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
74 if (cur && (*(cur = cur + 3) != ';'))
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
75 {
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
76 int i;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
77
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
78 i = sscanf(cur, "%02x%02x%02x;", &colors[0], &colors[1], &colors[2]);
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
79
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
80 if (i > 0)
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
81 {
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
82 char tag[64];
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
83
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
84 if (i == 1)
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
85 {
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
86 colors[1] = 0;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
87 colors[2] = 0;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
88 }
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
89 else if (i == 2)
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
90 {
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
91 unsigned int temp = colors[0];
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
92
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
93 colors[0] = colors[1];
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
94 colors[1] = temp;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
95 colors[2] = 0;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
96 }
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
97 else if (i == 3)
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
98 {
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
99 unsigned int temp = colors[2];
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
100
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
101 colors[2] = colors[0];
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
102 colors[0] = temp;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
103 }
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
104
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
105 g_snprintf(tag, sizeof(tag),
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
106 "<FONT COLOR=\"#%02hhx%02hhx%02hhx\">",
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
107 colors[0], colors[1], colors[2]);
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
108
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
109 pre = g_string_append(pre, tag);
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
110 post = g_string_prepend(post, "</FONT>");
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
111 }
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
112 }
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
113
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
114 cur = g_strdup(gaim_url_decode(pre->str));
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
115 g_string_free(pre, TRUE);
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
116
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
117 if (pre_ret != NULL)
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
118 *pre_ret = cur;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
119 else
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
120 g_free(cur);
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
121
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
122 cur = g_strdup(gaim_url_decode(post->str));
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
123 g_string_free(post, TRUE);
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
124
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
125 if (post_ret != NULL)
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
126 *post_ret = cur;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
127 else
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
128 g_free(cur);
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
129 }
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
130
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
131 /*
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
132 * We need this because we're only supposed to encode spaces in the font
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
133 * names. gaim_url_encode() isn't acceptable.
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
134 */
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
135 static const char *
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
136 encode_spaces(const char *str)
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
137 {
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
138 static char buf[BUF_LEN];
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
139 const char *c;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
140 char *d;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
141
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
142 g_return_val_if_fail(str != NULL, NULL);
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
143
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
144 for (c = str, d = buf; *c != '\0'; c++)
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
145 {
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
146 if (*c == ' ')
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
147 {
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
148 *d++ = '%';
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
149 *d++ = '2';
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
150 *d++ = '0';
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
151 }
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
152 else
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
153 *d++ = *c;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
154 }
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
155
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
156 return buf;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
157 }
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
158
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
159 /*
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
160 * Taken from the zephyr plugin.
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
161 * This parses HTML formatting (put out by one of the gtkimhtml widgets
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
162 * and converts it to msn formatting. It doesn't deal with the tag closing,
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
163 * but gtkimhtml widgets give valid html.
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
164 * It currently deals properly with <b>, <u>, <i>, <font face=...>,
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
165 * <font color=...>.
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
166 * It ignores <font back=...> and <font size=...>
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
167 */
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
168 void
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
169 msn_import_html(const char *html, char **attributes, char **message)
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
170 {
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
171 int len, retcount = 0;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
172 const char *c;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
173 char *msg;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
174 char *fontface = NULL;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
175 char fonteffect[4];
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
176 char fontcolor[7];
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
177
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
178 g_return_if_fail(html != NULL);
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
179 g_return_if_fail(attributes != NULL);
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
180 g_return_if_fail(message != NULL);
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
181
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
182 len = strlen(html);
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
183 msg = g_malloc0(len + 1);
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
184
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
185 memset(fontcolor, 0, sizeof(fontcolor));
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
186 strcat(fontcolor, "0");
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
187 memset(fonteffect, 0, sizeof(fonteffect));
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
188
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
189 for (c = html; *c != '\0';)
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
190 {
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
191 if (*c == '<')
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
192 {
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
193 if (!g_ascii_strncasecmp(c + 1, "br>", 3))
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
194 {
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
195 msg[retcount++] = '\r';
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
196 msg[retcount++] = '\n';
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
197 c += 4;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
198 }
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
199 else if (!g_ascii_strncasecmp(c + 1, "i>", 2))
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
200 {
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
201 strcat(fonteffect, "I");
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
202 c += 3;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
203 }
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
204 else if (!g_ascii_strncasecmp(c + 1, "b>", 2))
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
205 {
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
206 strcat(fonteffect, "B");
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
207 c += 3;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
208 }
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
209 else if (!g_ascii_strncasecmp(c + 1, "u>", 2))
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
210 {
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
211 strcat(fonteffect, "U");
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
212 c += 3;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
213 }
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
214 else if (!g_ascii_strncasecmp(c + 1, "s>", 2))
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
215 {
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
216 strcat(fonteffect, "S");
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
217 c += 3;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
218 }
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
219 else if (!g_ascii_strncasecmp(c + 1, "a href=\"", 8))
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
220 {
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
221 c += 9;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
222
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
223 if (!g_ascii_strncasecmp(c, "mailto:", 7))
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
224 c += 7;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
225
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
226 while ((*c != '\0') && g_ascii_strncasecmp(c, "\">", 2))
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
227 msg[retcount++] = *c++;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
228
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
229 if (*c != '\0')
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
230 c += 2;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
231
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
232 /* ignore descriptive string */
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
233 while ((*c != '\0') && g_ascii_strncasecmp(c, "</a>", 4))
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
234 c++;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
235
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
236 if (*c != '\0')
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
237 c += 4;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
238 }
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
239 else if (!g_ascii_strncasecmp(c + 1, "font", 4))
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
240 {
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
241 c += 5;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
242
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
243 while ((*c != '\0') && !g_ascii_strncasecmp(c, " ", 1))
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
244 c++;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
245
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
246 if (!g_ascii_strncasecmp(c, "color=\"#", 7))
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
247 {
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
248 c += 8;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
249
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
250 fontcolor[0] = *(c + 4);
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
251 fontcolor[1] = *(c + 5);
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
252 fontcolor[2] = *(c + 2);
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
253 fontcolor[3] = *(c + 3);
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
254 fontcolor[4] = *c;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
255 fontcolor[5] = *(c + 1);
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
256
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
257 c += 8;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
258 }
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
259 else if (!g_ascii_strncasecmp(c, "face=\"", 6))
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
260 {
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
261 const char *end = NULL;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
262 const char *comma = NULL;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
263 unsigned int namelen = 0;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
264
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
265 c += 6;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
266 end = strchr(c, '\"');
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
267 comma = strchr(c, ',');
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
268
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
269 if (comma == NULL || comma > end)
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
270 namelen = (unsigned int)(end - c);
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
271 else
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
272 namelen = (unsigned int)(comma - c);
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
273
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
274 fontface = g_strndup(c, namelen);
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
275 c = end + 2;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
276 }
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
277 else
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
278 {
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
279 /* Drop all unrecognized/misparsed font tags */
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
280 while ((*c != '\0') && g_ascii_strncasecmp(c, "\">", 2))
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
281 c++;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
282
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
283 if (*c != '\0')
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
284 c += 2;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
285 }
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
286 }
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
287 else
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
288 {
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
289 while ((*c != '\0') && (*c != '>'))
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
290 c++;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
291 if (*c != '\0')
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
292 c++;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
293 }
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
294 }
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
295 else if (*c == '&')
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
296 {
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
297 if (!g_ascii_strncasecmp(c, "&lt;", 4))
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
298 {
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
299 msg[retcount++] = '<';
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
300 c += 4;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
301 }
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
302 else if (!g_ascii_strncasecmp(c, "&gt;", 4))
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
303 {
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
304 msg[retcount++] = '>';
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
305 c += 4;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
306 }
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
307 else if (!g_ascii_strncasecmp(c, "&nbsp;", 6))
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
308 {
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
309 msg[retcount++] = ' ';
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
310 c += 6;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
311 }
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
312 else if (!g_ascii_strncasecmp(c, "&quot;", 6))
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
313 {
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
314 msg[retcount++] = '"';
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
315 c += 6;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
316 }
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
317 else if (!g_ascii_strncasecmp(c, "&amp;", 5))
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
318 {
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
319 msg[retcount++] = '&';
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
320 c += 5;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
321 }
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
322 else if (!g_ascii_strncasecmp(c, "&apos;", 6))
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
323 {
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
324 msg[retcount++] = '\'';
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
325 c += 6;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
326 }
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
327 else
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
328 msg[retcount++] = *c++;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
329 }
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
330 else
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
331 msg[retcount++] = *c++;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
332 }
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
333
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
334 if (fontface == NULL)
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
335 fontface = g_strdup("MS Sans Serif");
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
336
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
337 *attributes = g_strdup_printf("FN=%s; EF=%s; CO=%s; PF=0",
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
338 encode_spaces(fontface),
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
339 fonteffect, fontcolor);
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
340 *message = g_strdup(msg);
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
341
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
342 g_free(fontface);
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
343 g_free(msg);
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
344 }
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
345
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
346 void
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
347 msn_parse_socket(const char *str, char **ret_host, int *ret_port)
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
348 {
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
349 char *host;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
350 char *c;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
351 int port;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
352
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
353 host = g_strdup(str);
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
354
19784
bc30c6270d9f [gaim-migrate @ 16473]
Ma Yuan <mayuan2006@gmail.com>
parents: 13627
diff changeset
355 if ((c = strchr(host, ':')) != NULL){
13627
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
356 *c = '\0';
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
357 port = atoi(c + 1);
19784
bc30c6270d9f [gaim-migrate @ 16473]
Ma Yuan <mayuan2006@gmail.com>
parents: 13627
diff changeset
358 }else{
bc30c6270d9f [gaim-migrate @ 16473]
Ma Yuan <mayuan2006@gmail.com>
parents: 13627
diff changeset
359 port = 1863;
13627
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
360 }
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
361
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
362 *ret_host = host;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
363 *ret_port = port;
3cfdf1653a64 [gaim-migrate @ 16014]
Evan Schoenberg <evan.s@dreskin.net>
parents:
diff changeset
364 }
19784
bc30c6270d9f [gaim-migrate @ 16473]
Ma Yuan <mayuan2006@gmail.com>
parents: 13627
diff changeset
365
19785
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
366 /*check the edian of system*/
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
367 int
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
368 isBigEndian(void)
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
369 {
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
370 short int word = 0x0100;
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
371 char *byte = (char *)&word;
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
372
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
373 return(byte[0]);
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
374 }
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
375
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
376 /*swap utility*/
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
377 unsigned int
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
378 swapInt(unsigned int dw)
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
379 {
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
380 unsigned int tmp;
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
381 tmp = (dw & 0x000000FF);
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
382 tmp = ((dw & 0x0000FF00) >> 0x08) | (tmp << 0x08);
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
383 tmp = ((dw & 0x00FF0000) >> 0x10) | (tmp << 0x08);
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
384 tmp = ((dw & 0xFF000000) >> 0x18) | (tmp << 0x08);
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
385 return(tmp);
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
386 }
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
387
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
388 /*
19788
8b4653986e8e [gaim-migrate @ 16600]
Ma Yuan <mayuan2006@gmail.com>
parents: 19785
diff changeset
389 * Handle MSN Chanllege computation
19785
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
390 *This algorithm reference with http://msnpiki.msnfanatic.com/index.php/MSNP11:Challenges
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
391 */
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
392 #define BUFSIZE 256
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
393 void
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
394 msn_handle_chl(char *input, char *output)
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
395 {
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
396 GaimCipher *cipher;
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
397 GaimCipherContext *context;
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
398 char *productKey = MSNP13_WLM_PRODUCT_KEY,
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
399 *productID = MSNP13_WLM_PRODUCT_ID,
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
400 *hexChars = "0123456789abcdef",
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
401 buf[BUFSIZE];
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
402 unsigned char md5Hash[16], *newHash;
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
403 unsigned int *md5Parts, *chlStringParts, newHashParts[5];
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
404
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
405 long long nHigh=0, nLow=0;
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
406
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
407 int i, bigEndian;
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
408
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
409 /* Determine our endianess */
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
410 bigEndian = isBigEndian();
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
411
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
412 /* Create the MD5 hash by using Gaim MD5 algorithm*/
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
413 cipher = gaim_ciphers_find_cipher("md5");
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
414 context = gaim_cipher_context_new(cipher, NULL);
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
415
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
416 gaim_cipher_context_append(context, (const guchar *)input,
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
417 strlen(input));
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
418 gaim_cipher_context_append(context, (const guchar *)productKey,
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
419 strlen(productKey));
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
420 gaim_cipher_context_digest(context, sizeof(md5Hash), md5Hash, NULL);
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
421 gaim_cipher_context_destroy(context);
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
422
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
423 /* Split it into four integers */
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
424 md5Parts = (unsigned int *)md5Hash;
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
425 for(i=0; i<4; i++){
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
426 /* check for endianess */
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
427 if(bigEndian)
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
428 md5Parts[i] = swapInt(md5Parts[i]);
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
429
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
430 /* & each integer with 0x7FFFFFFF */
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
431 /* and save one unmodified array for later */
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
432 newHashParts[i] = md5Parts[i];
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
433 md5Parts[i] &= 0x7FFFFFFF;
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
434 }
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
435
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
436 /* make a new string and pad with '0' */
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
437 snprintf(buf, BUFSIZE-5, "%s%s", input, productID);
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
438 i = strlen(buf);
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
439 memset(&buf[i], '0', 8 - (i % 8));
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
440 buf[i + (8 - (i % 8))]='\0';
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
441
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
442 /* split into integers */
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
443 chlStringParts = (unsigned int *)buf;
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
444
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
445 /* this is magic */
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
446 for (i=0; i<(strlen(buf)/4)-1; i+=2){
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
447 long long temp;
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
448
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
449 if(bigEndian){
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
450 chlStringParts[i] = swapInt(chlStringParts[i]);
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
451 chlStringParts[i+1] = swapInt(chlStringParts[i+1]);
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
452 }
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
453
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
454 temp=(md5Parts[0] * (((0x0E79A9C1 * (long long)chlStringParts[i]) % 0x7FFFFFFF)+nHigh) + md5Parts[1])%0x7FFFFFFF;
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
455 nHigh=(md5Parts[2] * (((long long)chlStringParts[i+1]+temp) % 0x7FFFFFFF) + md5Parts[3]) % 0x7FFFFFFF;
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
456 nLow=nLow + nHigh + temp;
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
457 }
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
458 nHigh=(nHigh+md5Parts[1]) % 0x7FFFFFFF;
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
459 nLow=(nLow+md5Parts[3]) % 0x7FFFFFFF;
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
460
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
461 newHashParts[0]^=nHigh;
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
462 newHashParts[1]^=nLow;
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
463 newHashParts[2]^=nHigh;
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
464 newHashParts[3]^=nLow;
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
465
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
466 /* swap more bytes if big endian */
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
467 for(i=0; i<4 && bigEndian; i++)
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
468 newHashParts[i] = swapInt(newHashParts[i]);
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
469
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
470 /* make a string of the parts */
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
471 newHash = (unsigned char *)newHashParts;
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
472
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
473 /* convert to hexadecimal */
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
474 for (i=0; i<16; i++)
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
475 {
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
476 output[i*2]=hexChars[(newHash[i]>>4)&0xF];
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
477 output[(i*2)+1]=hexChars[newHash[i]&0xF];
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
478 }
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
479
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
480 output[32]='\0';
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
481
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
482 // gaim_debug_info("MaYuan","chl output{%s}\n",output);
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
483 }
852b32710df0 [gaim-migrate @ 16507]
Ma Yuan <mayuan2006@gmail.com>
parents: 19784
diff changeset
484