Mercurial > pidgin.yaz
annotate src/protocols/msn/page.c @ 8357:1f56ea865926
[gaim-migrate @ 9081]
" This fixes some bugs in joining a yahoo chat after
you've already joined a yahoo chat. these bugs were
introduced by me of course. Well, they're half my
changes I made in CVS, and half the odd way I coded
yahoo chat support to begin with. So yeah, all my fault...
This also adds a pos++ like nosnilmot was saying." --Tim (marv) Ringenbach
committer: Tailor Script <tailor@pidgin.im>
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Sat, 28 Feb 2004 05:48:01 +0000 |
parents | 4ab8ec97576c |
children | 06f57183e29f |
rev | line source |
---|---|
5370 | 1 /** |
2 * @file page.c Paging functions | |
3 * | |
4 * gaim | |
5 * | |
6 * Copyright (C) 2003 Christian Hammond <chipx86@gnupdate.org> | |
6701
b7e113a59b51
[gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents:
5370
diff
changeset
|
7 * |
5370 | 8 * This program is free software; you can redistribute it and/or modify |
9 * it under the terms of the GNU General Public License as published by | |
10 * the Free Software Foundation; either version 2 of the License, or | |
11 * (at your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, | |
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 * GNU General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU General Public License | |
19 * along with this program; if not, write to the Free Software | |
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
21 */ | |
22 #include "msn.h" | |
23 #include "page.h" | |
24 | |
25 #define GET_NEXT(tmp) \ | |
26 while (*(tmp) && *(tmp) != ' ' && *(tmp) != '\r') \ | |
27 (tmp)++; \ | |
28 if (*(tmp) != '\0') *(tmp)++ = '\0'; \ | |
29 if (*(tmp) == '\n') *(tmp)++; \ | |
30 while (*(tmp) && *(tmp) == ' ') \ | |
31 (tmp)++ | |
32 | |
33 #define GET_NEXT_LINE(tmp) \ | |
34 while (*(tmp) && *(tmp) != '\r') \ | |
35 (tmp)++; \ | |
36 if (*(tmp) != '\0') *(tmp)++ = '\0'; \ | |
37 if (*(tmp) == '\n') *(tmp)++ | |
38 | |
39 /* | |
7468
4ab8ec97576c
[gaim-migrate @ 8081]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
40 * <TEXT xml:space="preserve" enc="utf-8"> == 39 |
4ab8ec97576c
[gaim-migrate @ 8081]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
41 * </TEXT> == 7 |
4ab8ec97576c
[gaim-migrate @ 8081]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
42 * ---- |
4ab8ec97576c
[gaim-migrate @ 8081]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
43 * 46 |
5370 | 44 */ |
7468
4ab8ec97576c
[gaim-migrate @ 8081]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
45 #define MSN_PAGE_BASE_SIZE 46 |
5370 | 46 |
47 MsnPage * | |
48 msn_page_new(void) | |
49 { | |
50 MsnPage *page; | |
51 | |
52 page = g_new0(MsnPage, 1); | |
53 | |
54 page->size = MSN_PAGE_BASE_SIZE; | |
55 | |
56 return page; | |
57 } | |
58 | |
59 MsnPage * | |
60 msn_page_new_from_str(MsnSession *session, const char *str) | |
61 { | |
62 g_return_val_if_fail(str != NULL, NULL); | |
63 | |
64 return NULL; | |
65 } | |
66 | |
67 void | |
68 msn_page_destroy(MsnPage *page) | |
69 { | |
70 g_return_if_fail(page != NULL); | |
71 | |
72 if (page->sender != NULL) | |
73 msn_user_unref(page->sender); | |
74 | |
75 if (page->receiver != NULL) | |
76 msn_user_unref(page->receiver); | |
77 | |
78 if (page->body != NULL) | |
79 g_free(page->body); | |
80 | |
81 if (page->from_location != NULL) | |
82 g_free(page->from_location); | |
83 | |
84 if (page->from_phone != NULL) | |
85 g_free(page->from_phone); | |
86 | |
87 g_free(page); | |
88 } | |
89 | |
90 char * | |
91 msn_page_build_string(const MsnPage *page) | |
92 { | |
93 char *page_start; | |
94 char *str; | |
95 char buf[MSN_BUF_LEN]; | |
96 int len; | |
97 | |
98 /* | |
99 * Okay, how we do things here is just bad. I don't like writing to | |
100 * a static buffer and then copying to the string. Unfortunately, | |
101 * just trying to append to the string is causing issues.. Such as | |
102 * the string you're appending to being erased. Ugh. So, this is | |
103 * good enough for now. | |
104 * | |
105 * -- ChipX86 | |
106 */ | |
107 g_return_val_if_fail(page != NULL, NULL); | |
108 | |
109 if (msn_page_is_incoming(page)) { | |
110 /* We don't know this yet :) */ | |
111 return NULL; | |
112 } | |
113 else { | |
114 MsnUser *receiver = msn_page_get_receiver(page); | |
115 | |
7468
4ab8ec97576c
[gaim-migrate @ 8081]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
116 g_snprintf(buf, sizeof(buf), "PGD %d %s 1 %d\r\n", |
5370 | 117 msn_page_get_transaction_id(page), |
118 msn_user_get_passport(receiver), | |
7386 | 119 (int)page->size); |
5370 | 120 } |
121 | |
122 len = strlen(buf) + page->size + 1; | |
123 | |
124 str = g_new0(char, len); | |
125 | |
126 g_strlcpy(str, buf, len); | |
127 | |
128 page_start = str + strlen(str); | |
129 | |
7468
4ab8ec97576c
[gaim-migrate @ 8081]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
130 g_snprintf(buf, sizeof(buf), |
4ab8ec97576c
[gaim-migrate @ 8081]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
131 "<TEXT xml:space=\"preserve\" enc=\"utf-8\">%s</TEXT>", |
4ab8ec97576c
[gaim-migrate @ 8081]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
132 msn_page_get_body(page)); |
5370 | 133 |
134 g_strlcat(str, buf, len); | |
135 | |
136 if (page->size != strlen(page_start)) { | |
137 gaim_debug(GAIM_DEBUG_ERROR, "msn", | |
138 "Outgoing page size (%d) and string length (%d) " | |
139 "do not match!\n", page->size, strlen(page_start)); | |
140 } | |
141 | |
142 return str; | |
143 } | |
144 | |
145 gboolean | |
146 msn_page_is_outgoing(const MsnPage *page) | |
147 { | |
148 g_return_val_if_fail(page != NULL, FALSE); | |
149 | |
150 return !page->incoming; | |
151 } | |
152 | |
153 gboolean | |
154 msn_page_is_incoming(const MsnPage *page) | |
155 { | |
156 g_return_val_if_fail(page != NULL, FALSE); | |
157 | |
158 return page->incoming; | |
159 } | |
160 | |
161 void | |
162 msn_page_set_sender(MsnPage *page, MsnUser *user) | |
163 { | |
164 g_return_if_fail(page != NULL); | |
165 g_return_if_fail(user != NULL); | |
166 | |
167 page->sender = user; | |
7468
4ab8ec97576c
[gaim-migrate @ 8081]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
168 |
5370 | 169 msn_user_ref(page->sender); |
170 } | |
171 | |
172 MsnUser * | |
173 msn_page_get_sender(const MsnPage *page) | |
174 { | |
175 g_return_val_if_fail(page != NULL, NULL); | |
176 | |
177 return page->sender; | |
178 } | |
179 | |
180 void | |
181 msn_page_set_receiver(MsnPage *page, MsnUser *user) | |
182 { | |
183 g_return_if_fail(page != NULL); | |
184 g_return_if_fail(user != NULL); | |
185 | |
186 page->receiver = user; | |
7468
4ab8ec97576c
[gaim-migrate @ 8081]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
187 |
5370 | 188 msn_user_ref(page->receiver); |
189 } | |
190 | |
191 MsnUser * | |
192 msn_page_get_receiver(const MsnPage *page) | |
193 { | |
194 g_return_val_if_fail(page != NULL, NULL); | |
195 | |
196 return page->receiver; | |
197 } | |
198 | |
199 void | |
200 msn_page_set_transaction_id(MsnPage *page, unsigned int tid) | |
201 { | |
202 g_return_if_fail(page != NULL); | |
203 g_return_if_fail(tid > 0); | |
204 | |
205 page->trId = tid; | |
206 } | |
207 | |
208 unsigned int | |
209 msn_page_get_transaction_id(const MsnPage *page) | |
210 { | |
211 g_return_val_if_fail(page != NULL, 0); | |
212 | |
213 return page->trId; | |
214 } | |
215 | |
216 void | |
217 msn_page_set_body(MsnPage *page, const char *body) | |
218 { | |
219 g_return_if_fail(page != NULL); | |
220 g_return_if_fail(body != NULL); | |
221 | |
222 if (page->body != NULL) { | |
223 page->size -= strlen(page->body); | |
224 g_free(page->body); | |
225 } | |
226 | |
227 page->body = g_strdup(body); | |
228 | |
229 page->size += strlen(body); | |
230 } | |
231 | |
232 const char * | |
233 msn_page_get_body(const MsnPage *page) | |
234 { | |
235 g_return_val_if_fail(page != NULL, NULL); | |
236 | |
237 return page->body; | |
238 } | |
239 |