annotate src/protocols/msn/msg.c @ 6701:b7e113a59b51

[gaim-migrate @ 7227] Updated to MSN Protocol 9. committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Tue, 02 Sep 2003 04:32:16 +0000
parents 29fef9695c4d
children cebd49f42b56
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4542
86b0a0243be8 [gaim-migrate @ 4821]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
1 /**
86b0a0243be8 [gaim-migrate @ 4821]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
2 * @file msg.c Message functions
86b0a0243be8 [gaim-migrate @ 4821]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
3 *
86b0a0243be8 [gaim-migrate @ 4821]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
4 * gaim
86b0a0243be8 [gaim-migrate @ 4821]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
5 *
5309
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
6 * Copyright (C) 2003 Christian Hammond <chipx86@gnupdate.org>
6701
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
7 *
4542
86b0a0243be8 [gaim-migrate @ 4821]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
8 * This program is free software; you can redistribute it and/or modify
86b0a0243be8 [gaim-migrate @ 4821]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
9 * it under the terms of the GNU General Public License as published by
86b0a0243be8 [gaim-migrate @ 4821]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or
86b0a0243be8 [gaim-migrate @ 4821]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
11 * (at your option) any later version.
86b0a0243be8 [gaim-migrate @ 4821]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
12 *
86b0a0243be8 [gaim-migrate @ 4821]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful,
86b0a0243be8 [gaim-migrate @ 4821]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
86b0a0243be8 [gaim-migrate @ 4821]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
86b0a0243be8 [gaim-migrate @ 4821]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
16 * GNU General Public License for more details.
86b0a0243be8 [gaim-migrate @ 4821]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
17 *
86b0a0243be8 [gaim-migrate @ 4821]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
86b0a0243be8 [gaim-migrate @ 4821]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
19 * along with this program; if not, write to the Free Software
86b0a0243be8 [gaim-migrate @ 4821]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
86b0a0243be8 [gaim-migrate @ 4821]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
21 */
86b0a0243be8 [gaim-migrate @ 4821]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
22 #include "msn.h"
5309
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
23 #include "msg.h"
4542
86b0a0243be8 [gaim-migrate @ 4821]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
24
5309
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
25 #define GET_NEXT(tmp) \
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
26 while (*(tmp) && *(tmp) != ' ' && *(tmp) != '\r') \
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
27 (tmp)++; \
5315
b1c430fbf9d5 [gaim-migrate @ 5687]
Christian Hammond <chipx86@chipx86.com>
parents: 5310
diff changeset
28 if (*(tmp) != '\0') *(tmp)++ = '\0'; \
6075
f7ddc1f6227e [gaim-migrate @ 6534]
Christian Hammond <chipx86@chipx86.com>
parents: 6011
diff changeset
29 if (*(tmp) == '\n') (tmp)++; \
5309
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
30 while (*(tmp) && *(tmp) == ' ') \
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
31 (tmp)++
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
32
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
33 #define GET_NEXT_LINE(tmp) \
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
34 while (*(tmp) && *(tmp) != '\r') \
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
35 (tmp)++; \
5315
b1c430fbf9d5 [gaim-migrate @ 5687]
Christian Hammond <chipx86@chipx86.com>
parents: 5310
diff changeset
36 if (*(tmp) != '\0') *(tmp)++ = '\0'; \
6075
f7ddc1f6227e [gaim-migrate @ 6534]
Christian Hammond <chipx86@chipx86.com>
parents: 6011
diff changeset
37 if (*(tmp) == '\n') (tmp)++
5309
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
38
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
39 /*
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
40 * "MIME-Version: 1.0\r\n" == 19
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
41 * "Content-Type: " == 14
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
42 * "\r\n" == 2
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
43 * "\r\n" before body == 2
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
44 * ----
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
45 * 37
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
46 * MATH PAYS OFF!!
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
47 */
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
48 #define MSN_MESSAGE_BASE_SIZE 37
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
49
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
50 MsnMessage *
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
51 msn_message_new(void)
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
52 {
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
53 MsnMessage *msg;
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
54
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
55 msg = g_new0(MsnMessage, 1);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
56
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
57 msg->attr_table = g_hash_table_new_full(g_str_hash, g_str_equal,
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
58 g_free, g_free);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
59 msg->size = MSN_MESSAGE_BASE_SIZE;
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
60
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
61 msn_message_set_attr(msg, "User-Agent", "Gaim/" VERSION);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
62 msn_message_set_content_type(msg, "text/plain");
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
63 msn_message_set_charset(msg, "UTF-8");
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
64 msn_message_set_flag(msg, 'N');
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
65
5506
4f72b611f0ee [gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents: 5478
diff changeset
66 msn_message_ref(msg);
4f72b611f0ee [gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents: 5478
diff changeset
67
5309
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
68 return msg;
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
69 }
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
70
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
71 MsnMessage *
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
72 msn_message_new_from_str(MsnSession *session, const char *str)
4542
86b0a0243be8 [gaim-migrate @ 4821]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
73 {
5309
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
74 MsnMessage *msg;
6701
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
75 char *tmp_base, *msg_base, *tmp, *field1, *field2, *c;
5309
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
76
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
77 g_return_val_if_fail(str != NULL, NULL);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
78 g_return_val_if_fail(!g_ascii_strncasecmp(str, "MSG", 3), NULL);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
79
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
80 msg = msn_message_new();
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
81
5454
c6efac0e28ff [gaim-migrate @ 5842]
Christian Hammond <chipx86@chipx86.com>
parents: 5315
diff changeset
82 /* Clear out the old stuff. */
c6efac0e28ff [gaim-migrate @ 5842]
Christian Hammond <chipx86@chipx86.com>
parents: 5315
diff changeset
83 msn_message_set_attr(msg, "User-Agent", NULL);
5455
f9658a84d1ed [gaim-migrate @ 5843]
Christian Hammond <chipx86@chipx86.com>
parents: 5454
diff changeset
84 msn_message_set_content_type(msg, NULL);
f9658a84d1ed [gaim-migrate @ 5843]
Christian Hammond <chipx86@chipx86.com>
parents: 5454
diff changeset
85 msn_message_set_charset(msg, NULL);
5454
c6efac0e28ff [gaim-migrate @ 5842]
Christian Hammond <chipx86@chipx86.com>
parents: 5315
diff changeset
86
6011
b8abf266dd3b [gaim-migrate @ 6459]
Christian Hammond <chipx86@chipx86.com>
parents: 5506
diff changeset
87 tmp_base = tmp = g_strdup(str);
5309
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
88
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
89 GET_NEXT(tmp); /* Skip MSG */
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
90 field1 = tmp;
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
91
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
92 GET_NEXT(tmp); /* Skip the passport or TID */
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
93 field2 = tmp;
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
94
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
95 GET_NEXT(tmp); /* Skip the username or flag */
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
96 msg->size = atoi(tmp);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
97
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
98 if (msg->size != strlen(strchr(str, '\n') + 1)) {
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
99 gaim_debug(GAIM_DEBUG_ERROR, "msn",
5310
f4912a833ff6 [gaim-migrate @ 5682]
Christian Hammond <chipx86@chipx86.com>
parents: 5309
diff changeset
100 "Incoming message size (%d) and string length (%d) "
5309
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
101 "do not match!\n", msg->size, strlen(str));
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
102 }
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
103
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
104 /*
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
105 * We're going to make sure this is incoming by checking field1.
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
106 * If it has any non-numbers in it, it's incoming. Otherwise, outgoing.
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
107 */
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
108 msg->incoming = FALSE;
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
109
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
110 for (c = field1; *c != '\0'; c++) {
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
111 if (*c < '0' || *c > '9') {
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
112 msg->incoming = TRUE;
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
113 break;
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
114 }
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
115 }
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
116
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
117 if (msg->incoming) {
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
118 msg->sender = msn_users_find_with_passport(session->users, field1);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
119
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
120 if (msg->sender == NULL)
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
121 msg->sender = msn_user_new(session, field1, field2);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
122 else
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
123 msn_user_ref(msg->sender);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
124 }
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
125 else {
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
126 msg->tid = atoi(field1);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
127 msg->flag = *field2;
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
128 }
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
129
6701
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
130 msg_base = tmp;
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
131
5309
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
132 /* Back to the parsination. */
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
133 while (*tmp != '\r') {
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
134 char *key, *value;
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
135
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
136 key = tmp;
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
137
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
138 GET_NEXT(tmp); /* Key */
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
139
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
140 value = tmp;
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
141
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
142 GET_NEXT_LINE(tmp); /* Value */
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
143
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
144 if ((c = strchr(key, ':')) != NULL)
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
145 *c = '\0';
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
146
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
147 if (!g_ascii_strcasecmp(key, "Content-Type")) {
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
148 char *charset;
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
149
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
150 if ((c = strchr(value, ';')) != NULL) {
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
151 if ((charset = strchr(c, '=')) != NULL) {
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
152 charset++;
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
153 msn_message_set_charset(msg, charset);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
154 }
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
155
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
156 *c = '\0';
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
157 }
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
158
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
159 msn_message_set_content_type(msg, value);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
160 }
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
161 else
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
162 msn_message_set_attr(msg, key, value);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
163 }
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
164
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
165 /* "\r\n" */
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
166 tmp += 2;
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
167
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
168 /* Now we *should* be at the body. */
6701
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
169 if (!strcmp(msn_message_get_content_type(msg), "application/x-msnmsgrp2p"))
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
170 {
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
171 msn_message_set_body(msg, tmp);
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
172 }
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
173 else
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
174 {
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
175 char header[48];
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
176 char footer[4];
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
177
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
178 msg->msnslp_message = TRUE;
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
179
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
180 memcpy(header, tmp, 48);
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
181
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
182 tmp += 48;
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
183
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
184 msg->body = g_memdup(tmp, msg->size - (tmp - msg_base) + 1);
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
185
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
186 tmp++;
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
187
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
188 memcpy(footer, tmp, 4);
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
189
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
190 /* Import the header. */
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
191 memcpy(&msg->msnslp_header.session_id, tmp, 4); tmp += 4;
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
192 memcpy(&msg->msnslp_header.id, tmp, 4); tmp += 4;
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
193 memcpy(&msg->msnslp_header.offset, tmp, 4); tmp += 8;
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
194 memcpy(&msg->msnslp_header.total_size, tmp, 4); tmp += 8;
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
195 memcpy(&msg->msnslp_header.length, tmp, 4); tmp += 4;
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
196 memcpy(&msg->msnslp_header.flags, tmp, 4); tmp += 4;
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
197 memcpy(&msg->msnslp_header.prev_id, tmp, 4); tmp += 4;
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
198 memcpy(&msg->msnslp_header.prev_f9, tmp, 4); tmp += 4;
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
199 memcpy(&msg->msnslp_header.prev_total_size, tmp, 4); tmp += 8;
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
200
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
201 /* Convert to the right endianness */
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
202 msg->msnslp_header.session_id = ntohs(msg->msnslp_header.session_id);
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
203 msg->msnslp_header.id = ntohs(msg->msnslp_header.id);
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
204 msg->msnslp_header.length = ntohs(msg->msnslp_header.length);
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
205 msg->msnslp_header.flags = ntohs(msg->msnslp_header.flags);
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
206 msg->msnslp_header.prev_id = ntohs(msg->msnslp_header.prev_id);
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
207 msg->msnslp_header.prev_f9 = ntohs(msg->msnslp_header.prev_f9);
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
208
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
209 /* Import the footer. */
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
210 msg->msnslp_footer.app_id = (long)footer;
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
211 }
5309
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
212
6011
b8abf266dd3b [gaim-migrate @ 6459]
Christian Hammond <chipx86@chipx86.com>
parents: 5506
diff changeset
213 g_free(tmp_base);
b8abf266dd3b [gaim-migrate @ 6459]
Christian Hammond <chipx86@chipx86.com>
parents: 5506
diff changeset
214
5309
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
215 /* Done! */
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
216
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
217 return msg;
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
218 }
4542
86b0a0243be8 [gaim-migrate @ 4821]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
219
5309
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
220 void
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
221 msn_message_destroy(MsnMessage *msg)
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
222 {
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
223 g_return_if_fail(msg != NULL);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
224
5506
4f72b611f0ee [gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents: 5478
diff changeset
225 if (msg->ref_count > 0) {
4f72b611f0ee [gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents: 5478
diff changeset
226 msn_message_unref(msg);
4f72b611f0ee [gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents: 5478
diff changeset
227
4f72b611f0ee [gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents: 5478
diff changeset
228 return;
4f72b611f0ee [gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents: 5478
diff changeset
229 }
4f72b611f0ee [gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents: 5478
diff changeset
230
5309
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
231 if (msg->sender != NULL)
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
232 msn_user_unref(msg->sender);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
233
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
234 if (msg->receiver != NULL)
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
235 msn_user_unref(msg->receiver);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
236
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
237 if (msg->body != NULL)
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
238 g_free(msg->body);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
239
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
240 if (msg->content_type != NULL)
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
241 g_free(msg->content_type);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
242
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
243 if (msg->charset != NULL)
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
244 g_free(msg->charset);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
245
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
246 g_hash_table_destroy(msg->attr_table);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
247 g_list_free(msg->attr_list);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
248
5506
4f72b611f0ee [gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents: 5478
diff changeset
249 gaim_debug(GAIM_DEBUG_INFO, "msn", "Destroying message\n");
5309
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
250 g_free(msg);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
251 }
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
252
5506
4f72b611f0ee [gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents: 5478
diff changeset
253 MsnMessage *
4f72b611f0ee [gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents: 5478
diff changeset
254 msn_message_ref(MsnMessage *msg)
4f72b611f0ee [gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents: 5478
diff changeset
255 {
4f72b611f0ee [gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents: 5478
diff changeset
256 g_return_val_if_fail(msg != NULL, NULL);
4f72b611f0ee [gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents: 5478
diff changeset
257
4f72b611f0ee [gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents: 5478
diff changeset
258 msg->ref_count++;
4f72b611f0ee [gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents: 5478
diff changeset
259
4f72b611f0ee [gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents: 5478
diff changeset
260 return msg;
4f72b611f0ee [gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents: 5478
diff changeset
261 }
4f72b611f0ee [gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents: 5478
diff changeset
262
4f72b611f0ee [gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents: 5478
diff changeset
263 MsnMessage *
4f72b611f0ee [gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents: 5478
diff changeset
264 msn_message_unref(MsnMessage *msg)
4f72b611f0ee [gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents: 5478
diff changeset
265 {
4f72b611f0ee [gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents: 5478
diff changeset
266 g_return_val_if_fail(msg != NULL, NULL);
4f72b611f0ee [gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents: 5478
diff changeset
267
4f72b611f0ee [gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents: 5478
diff changeset
268 if (msg->ref_count <= 0)
4f72b611f0ee [gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents: 5478
diff changeset
269 return NULL;
4f72b611f0ee [gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents: 5478
diff changeset
270
4f72b611f0ee [gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents: 5478
diff changeset
271 msg->ref_count--;
4f72b611f0ee [gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents: 5478
diff changeset
272
4f72b611f0ee [gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents: 5478
diff changeset
273 if (msg->ref_count == 0) {
4f72b611f0ee [gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents: 5478
diff changeset
274 msn_message_destroy(msg);
4f72b611f0ee [gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents: 5478
diff changeset
275
4f72b611f0ee [gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents: 5478
diff changeset
276 return NULL;
4f72b611f0ee [gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents: 5478
diff changeset
277 }
4f72b611f0ee [gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents: 5478
diff changeset
278
4f72b611f0ee [gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents: 5478
diff changeset
279 return msg;
4f72b611f0ee [gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents: 5478
diff changeset
280 }
4f72b611f0ee [gaim-migrate @ 5905]
Christian Hammond <chipx86@chipx86.com>
parents: 5478
diff changeset
281
5309
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
282 char *
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
283 msn_message_build_string(const MsnMessage *msg)
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
284 {
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
285 GList *l;
5310
f4912a833ff6 [gaim-migrate @ 5682]
Christian Hammond <chipx86@chipx86.com>
parents: 5309
diff changeset
286 char *msg_start;
5309
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
287 char *str;
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
288 char buf[MSN_BUF_LEN];
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
289 int len;
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
290
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
291 /*
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
292 * Okay, how we do things here is just bad. I don't like writing to
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
293 * a static buffer and then copying to the string. Unfortunately,
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
294 * just trying to append to the string is causing issues.. Such as
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
295 * the string you're appending to being erased. Ugh. So, this is
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
296 * good enough for now.
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
297 *
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
298 * -- ChipX86
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
299 */
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
300 g_return_val_if_fail(msg != NULL, NULL);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
301
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
302 if (msn_message_is_incoming(msg)) {
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
303 MsnUser *sender = msn_message_get_sender(msg);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
304
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
305 g_snprintf(buf, sizeof(buf), "MSG %s %s %d\r\n",
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
306 msn_user_get_passport(sender), msn_user_get_name(sender),
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
307 msg->size);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
308 }
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
309 else {
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
310 g_snprintf(buf, sizeof(buf), "MSG %d %c %d\r\n",
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
311 msn_message_get_transaction_id(msg),
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
312 msn_message_get_flag(msg), msg->size);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
313 }
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
314
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
315 len = strlen(buf) + msg->size + 1;
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
316
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
317 str = g_new0(char, len);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
318
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
319 g_strlcpy(str, buf, len);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
320
5310
f4912a833ff6 [gaim-migrate @ 5682]
Christian Hammond <chipx86@chipx86.com>
parents: 5309
diff changeset
321 msg_start = str + strlen(str);
f4912a833ff6 [gaim-migrate @ 5682]
Christian Hammond <chipx86@chipx86.com>
parents: 5309
diff changeset
322
5309
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
323 /* Standard header. */
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
324 if (msg->charset == NULL) {
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
325 g_snprintf(buf, sizeof(buf),
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
326 "MIME-Version: 1.0\r\n"
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
327 "Content-Type: %s\r\n",
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
328 msg->content_type);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
329 }
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
330 else {
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
331 g_snprintf(buf, sizeof(buf),
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
332 "MIME-Version: 1.0\r\n"
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
333 "Content-Type: %s; charset=%s\r\n",
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
334 msg->content_type, msg->charset);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
335 }
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
336
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
337 g_strlcat(str, buf, len);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
338
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
339 for (l = msg->attr_list; l != NULL; l = l->next) {
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
340 const char *key = (char *)l->data;
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
341 const char *value;
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
342
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
343 value = msn_message_get_attr(msg, key);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
344
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
345 g_snprintf(buf, sizeof(buf), "%s: %s\r\n", key, value);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
346
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
347 g_strlcat(str, buf, len);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
348 }
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
349
6701
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
350 if (msg->msnslp_message)
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
351 {
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
352 char *c;
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
353 char blank[4];
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
354 int session_id, id, offset, total_size, length, flags;
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
355 int prev_id, prev_f9, prev_total_size;
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
356
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
357 memcpy(blank, 0, 4);
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
358
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
359 c = str + strlen(str);
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
360
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
361 session_id = htons(msg->msnslp_header.session_id);
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
362 id = htons(msg->msnslp_header.id);
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
363 offset = htons(msg->msnslp_header.offset);
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
364 total_size = htons(msg->msnslp_header.total_size);
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
365 length = htons(msg->msnslp_header.length);
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
366 flags = htons(msg->msnslp_header.flags);
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
367 prev_id = htons(msg->msnslp_header.prev_id);
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
368 prev_f9 = htons(msg->msnslp_header.prev_f9);
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
369 prev_total_size = htons(msg->msnslp_header.prev_total_size);
5309
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
370
6701
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
371 memcpy(c, &session_id, 4); c += 4;
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
372 memcpy(c, &id, 4); c += 4;
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
373 memcpy(c, &offset, 4); c += 4;
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
374 memcpy(c, blank, 4); c += 4;
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
375 memcpy(c, &total_size, 4); c += 4;
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
376 memcpy(c, blank, 4); c += 4;
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
377 memcpy(c, &length, 4); c += 4;
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
378 memcpy(c, &flags, 4); c += 4;
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
379 memcpy(c, &prev_id, 4); c += 4;
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
380 memcpy(c, &prev_f9, 4); c += 4;
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
381 memcpy(c, &prev_total_size, 4); c += 4;
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
382 memcpy(c, blank, 4); c += 4;
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
383
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
384 strncpy(c, msn_message_get_body(msg), len);
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
385
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
386 c += strlen(msn_message_get_body(msg));
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
387
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
388 memcpy(c, blank, 1); c++;
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
389 memcpy(c, &msg->msnslp_footer.app_id, 4); c += 4;
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
390 }
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
391 else
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
392 {
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
393 g_snprintf(buf, sizeof(buf), "\r\n%s", msn_message_get_body(msg));
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
394
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
395 g_strlcat(str, buf, len);
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 6181
diff changeset
396 }
5309
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
397
5310
f4912a833ff6 [gaim-migrate @ 5682]
Christian Hammond <chipx86@chipx86.com>
parents: 5309
diff changeset
398 if (msg->size != strlen(msg_start)) {
f4912a833ff6 [gaim-migrate @ 5682]
Christian Hammond <chipx86@chipx86.com>
parents: 5309
diff changeset
399 gaim_debug(GAIM_DEBUG_ERROR, "msn",
f4912a833ff6 [gaim-migrate @ 5682]
Christian Hammond <chipx86@chipx86.com>
parents: 5309
diff changeset
400 "Outgoing message size (%d) and string length (%d) "
f4912a833ff6 [gaim-migrate @ 5682]
Christian Hammond <chipx86@chipx86.com>
parents: 5309
diff changeset
401 "do not match!\n", msg->size, strlen(msg_start));
f4912a833ff6 [gaim-migrate @ 5682]
Christian Hammond <chipx86@chipx86.com>
parents: 5309
diff changeset
402 }
f4912a833ff6 [gaim-migrate @ 5682]
Christian Hammond <chipx86@chipx86.com>
parents: 5309
diff changeset
403
5309
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
404 return str;
4542
86b0a0243be8 [gaim-migrate @ 4821]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
405 }
86b0a0243be8 [gaim-migrate @ 4821]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
406
5309
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
407 gboolean
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
408 msn_message_is_outgoing(const MsnMessage *msg)
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
409 {
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
410 g_return_val_if_fail(msg != NULL, FALSE);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
411
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
412 return !msg->incoming;
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
413 }
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
414
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
415 gboolean
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
416 msn_message_is_incoming(const MsnMessage *msg)
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
417 {
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
418 g_return_val_if_fail(msg != NULL, FALSE);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
419
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
420 return msg->incoming;
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
421 }
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
422
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
423 void
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
424 msn_message_set_sender(MsnMessage *msg, MsnUser *user)
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
425 {
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
426 g_return_if_fail(msg != NULL);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
427 g_return_if_fail(user != NULL);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
428
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
429 msg->sender = user;
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
430
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
431 msn_user_ref(msg->sender);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
432 }
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
433
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
434 MsnUser *
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
435 msn_message_get_sender(const MsnMessage *msg)
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
436 {
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
437 g_return_val_if_fail(msg != NULL, NULL);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
438
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
439 return msg->sender;
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
440 }
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
441
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
442 void
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
443 msn_message_set_receiver(MsnMessage *msg, MsnUser *user)
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
444 {
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
445 g_return_if_fail(msg != NULL);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
446 g_return_if_fail(user != NULL);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
447
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
448 msg->receiver = user;
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
449
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
450 msn_user_ref(msg->receiver);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
451 }
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
452
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
453 MsnUser *
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
454 msn_message_get_receiver(const MsnMessage *msg)
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
455 {
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
456 g_return_val_if_fail(msg != NULL, NULL);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
457
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
458 return msg->receiver;
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
459 }
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
460
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
461 void
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
462 msn_message_set_transaction_id(MsnMessage *msg, unsigned int tid)
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
463 {
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
464 g_return_if_fail(msg != NULL);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
465 g_return_if_fail(tid > 0);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
466
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
467 msg->tid = tid;
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
468 }
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
469
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
470 unsigned int
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
471 msn_message_get_transaction_id(const MsnMessage *msg)
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
472 {
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
473 g_return_val_if_fail(msg != NULL, 0);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
474
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
475 return msg->tid;
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
476 }
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
477
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
478 void
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
479 msn_message_set_flag(MsnMessage *msg, char flag)
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
480 {
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
481 g_return_if_fail(msg != NULL);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
482 g_return_if_fail(flag != 0);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
483
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
484 msg->flag = flag;
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
485 }
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
486
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
487 char
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
488 msn_message_get_flag(const MsnMessage *msg)
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
489 {
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
490 g_return_val_if_fail(msg != NULL, 0);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
491
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
492 return msg->flag;
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
493 }
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
494
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
495 void
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
496 msn_message_set_body(MsnMessage *msg, const char *body)
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
497 {
6181
29fef9695c4d [gaim-migrate @ 6667]
Christian Hammond <chipx86@chipx86.com>
parents: 6075
diff changeset
498 const char *c;
29fef9695c4d [gaim-migrate @ 6667]
Christian Hammond <chipx86@chipx86.com>
parents: 6075
diff changeset
499 char *buf, *d;
29fef9695c4d [gaim-migrate @ 6667]
Christian Hammond <chipx86@chipx86.com>
parents: 6075
diff changeset
500 int newline_count = 0;
29fef9695c4d [gaim-migrate @ 6667]
Christian Hammond <chipx86@chipx86.com>
parents: 6075
diff changeset
501 size_t new_len;
29fef9695c4d [gaim-migrate @ 6667]
Christian Hammond <chipx86@chipx86.com>
parents: 6075
diff changeset
502
5309
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
503 g_return_if_fail(msg != NULL);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
504 g_return_if_fail(body != NULL);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
505
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
506 if (msg->body != NULL) {
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
507 msg->size -= strlen(msg->body);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
508 g_free(msg->body);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
509 }
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
510
6181
29fef9695c4d [gaim-migrate @ 6667]
Christian Hammond <chipx86@chipx86.com>
parents: 6075
diff changeset
511 for (c = body; *c != '\0'; c++) {
29fef9695c4d [gaim-migrate @ 6667]
Christian Hammond <chipx86@chipx86.com>
parents: 6075
diff changeset
512 if (*c == '\n' && (c == body || *(c - 1) != '\r'))
29fef9695c4d [gaim-migrate @ 6667]
Christian Hammond <chipx86@chipx86.com>
parents: 6075
diff changeset
513 newline_count++;
29fef9695c4d [gaim-migrate @ 6667]
Christian Hammond <chipx86@chipx86.com>
parents: 6075
diff changeset
514 }
29fef9695c4d [gaim-migrate @ 6667]
Christian Hammond <chipx86@chipx86.com>
parents: 6075
diff changeset
515
29fef9695c4d [gaim-migrate @ 6667]
Christian Hammond <chipx86@chipx86.com>
parents: 6075
diff changeset
516 new_len = strlen(body) + newline_count;
29fef9695c4d [gaim-migrate @ 6667]
Christian Hammond <chipx86@chipx86.com>
parents: 6075
diff changeset
517
29fef9695c4d [gaim-migrate @ 6667]
Christian Hammond <chipx86@chipx86.com>
parents: 6075
diff changeset
518 buf = g_new0(char, new_len + 1);
5309
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
519
6181
29fef9695c4d [gaim-migrate @ 6667]
Christian Hammond <chipx86@chipx86.com>
parents: 6075
diff changeset
520 for (c = body, d = buf; *c != '\0'; c++) {
29fef9695c4d [gaim-migrate @ 6667]
Christian Hammond <chipx86@chipx86.com>
parents: 6075
diff changeset
521 if (*c == '\n' && (c == body || *(c - 1) != '\r')) {
29fef9695c4d [gaim-migrate @ 6667]
Christian Hammond <chipx86@chipx86.com>
parents: 6075
diff changeset
522 *d++ = '\r';
29fef9695c4d [gaim-migrate @ 6667]
Christian Hammond <chipx86@chipx86.com>
parents: 6075
diff changeset
523 *d++ = '\n';
29fef9695c4d [gaim-migrate @ 6667]
Christian Hammond <chipx86@chipx86.com>
parents: 6075
diff changeset
524 }
29fef9695c4d [gaim-migrate @ 6667]
Christian Hammond <chipx86@chipx86.com>
parents: 6075
diff changeset
525 else
29fef9695c4d [gaim-migrate @ 6667]
Christian Hammond <chipx86@chipx86.com>
parents: 6075
diff changeset
526 *d++ = *c;
29fef9695c4d [gaim-migrate @ 6667]
Christian Hammond <chipx86@chipx86.com>
parents: 6075
diff changeset
527 }
29fef9695c4d [gaim-migrate @ 6667]
Christian Hammond <chipx86@chipx86.com>
parents: 6075
diff changeset
528
29fef9695c4d [gaim-migrate @ 6667]
Christian Hammond <chipx86@chipx86.com>
parents: 6075
diff changeset
529 msg->body = buf;
29fef9695c4d [gaim-migrate @ 6667]
Christian Hammond <chipx86@chipx86.com>
parents: 6075
diff changeset
530
29fef9695c4d [gaim-migrate @ 6667]
Christian Hammond <chipx86@chipx86.com>
parents: 6075
diff changeset
531 msg->size += new_len;
5309
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
532 }
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
533
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
534 const char *
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
535 msn_message_get_body(const MsnMessage *msg)
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
536 {
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
537 g_return_val_if_fail(msg != NULL, NULL);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
538
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
539 return msg->body;
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
540 }
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
541
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
542 void
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
543 msn_message_set_content_type(MsnMessage *msg, const char *type)
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
544 {
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
545 g_return_if_fail(msg != NULL);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
546
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
547 if (msg->content_type != NULL) {
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
548 msg->size -= strlen(msg->content_type);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
549 g_free(msg->content_type);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
550 }
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
551
5478
bae3c48b9b4c [gaim-migrate @ 5874]
Christian Hammond <chipx86@chipx86.com>
parents: 5455
diff changeset
552 if (type != NULL) {
bae3c48b9b4c [gaim-migrate @ 5874]
Christian Hammond <chipx86@chipx86.com>
parents: 5455
diff changeset
553 msg->content_type = g_strdup(type);
5309
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
554
5478
bae3c48b9b4c [gaim-migrate @ 5874]
Christian Hammond <chipx86@chipx86.com>
parents: 5455
diff changeset
555 msg->size += strlen(type);
bae3c48b9b4c [gaim-migrate @ 5874]
Christian Hammond <chipx86@chipx86.com>
parents: 5455
diff changeset
556 }
bae3c48b9b4c [gaim-migrate @ 5874]
Christian Hammond <chipx86@chipx86.com>
parents: 5455
diff changeset
557 else
bae3c48b9b4c [gaim-migrate @ 5874]
Christian Hammond <chipx86@chipx86.com>
parents: 5455
diff changeset
558 msg->content_type = NULL;
5309
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
559 }
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
560
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
561 const char *
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
562 msn_message_get_content_type(const MsnMessage *msg)
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
563 {
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
564 g_return_val_if_fail(msg != NULL, NULL);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
565
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
566 return msg->content_type;
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
567 }
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
568
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
569 void
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
570 msn_message_set_charset(MsnMessage *msg, const char *charset)
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
571 {
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
572 g_return_if_fail(msg != NULL);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
573
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
574 if (msg->charset != NULL) {
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
575 msg->size -= strlen(msg->charset) + strlen("; charset=");
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
576 g_free(msg->charset);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
577 }
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
578
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
579 if (charset != NULL) {
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
580 msg->charset = g_strdup(charset);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
581
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
582 msg->size += strlen(charset) + strlen("; charset=");
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
583 }
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
584 else
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
585 msg->charset = NULL;
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
586 }
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
587
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
588 const char *
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
589 msn_message_get_charset(const MsnMessage *msg)
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
590 {
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
591 g_return_val_if_fail(msg != NULL, NULL);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
592
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
593 return msg->charset;
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
594 }
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
595
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
596 void
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
597 msn_message_set_attr(MsnMessage *msg, const char *attr, const char *value)
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
598 {
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
599 const char *temp;
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
600 char *new_attr;
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
601
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
602 g_return_if_fail(msg != NULL);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
603 g_return_if_fail(attr != NULL);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
604
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
605 temp = msn_message_get_attr(msg, attr);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
606
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
607 if (value == NULL) {
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
608 if (temp != NULL) {
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
609 GList *l;
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
610
5310
f4912a833ff6 [gaim-migrate @ 5682]
Christian Hammond <chipx86@chipx86.com>
parents: 5309
diff changeset
611 msg->size -= strlen(temp) + strlen(attr) + 4;
f4912a833ff6 [gaim-migrate @ 5682]
Christian Hammond <chipx86@chipx86.com>
parents: 5309
diff changeset
612
5309
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
613 for (l = msg->attr_list; l != NULL; l = l->next) {
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
614 if (!g_ascii_strcasecmp(l->data, attr)) {
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
615 msg->attr_list = g_list_remove(msg->attr_list, l->data);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
616
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
617 break;
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
618 }
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
619 }
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
620
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
621 g_hash_table_remove(msg->attr_table, attr);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
622 }
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
623
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
624 return;
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
625 }
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
626
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
627 new_attr = g_strdup(attr);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
628
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
629 g_hash_table_insert(msg->attr_table, new_attr, g_strdup(value));
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
630
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
631 if (temp == NULL) {
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
632 msg->attr_list = g_list_append(msg->attr_list, new_attr);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
633 msg->size += strlen(attr) + 4;
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
634 }
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
635 else
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
636 msg->size -= strlen(temp);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
637
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
638 msg->size += strlen(value);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
639 }
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
640
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
641 const char *
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
642 msn_message_get_attr(const MsnMessage *msg, const char *attr)
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
643 {
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
644 g_return_val_if_fail(msg != NULL, NULL);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
645 g_return_val_if_fail(attr != NULL, NULL);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
646
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
647 return g_hash_table_lookup(msg->attr_table, attr);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
648 }
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
649
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
650 GHashTable *
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
651 msn_message_get_hashtable_from_body(const MsnMessage *msg)
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
652 {
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
653 GHashTable *table;
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
654 char *body, *s, *c;
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
655
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
656 g_return_val_if_fail(msg != NULL, NULL);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
657 g_return_val_if_fail(msn_message_get_body(msg) != NULL, NULL);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
658
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
659 s = body = g_strdup(msn_message_get_body(msg));
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
660
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
661 table = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
662
5315
b1c430fbf9d5 [gaim-migrate @ 5687]
Christian Hammond <chipx86@chipx86.com>
parents: 5310
diff changeset
663 while (*s != '\r' && *s != '\0') {
5309
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
664 char *key, *value;
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
665
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
666 key = s;
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
667
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
668 GET_NEXT(s);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
669
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
670 value = s;
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
671
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
672 GET_NEXT_LINE(s);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
673
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
674 if ((c = strchr(key, ':')) != NULL) {
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
675 *c = '\0';
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
676
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
677 g_hash_table_insert(table, g_strdup(key), g_strdup(value));
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
678 }
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
679 }
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
680
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
681 g_free(body);
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
682
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
683 return table;
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
684 }
e2e53316a21d [gaim-migrate @ 5681]
Christian Hammond <chipx86@chipx86.com>
parents: 5221
diff changeset
685