Mercurial > pidgin.yaz
annotate src/protocols/msn/msnobject.c @ 9087:f32ee2e97b37
[gaim-migrate @ 9864]
Several small MSN bug fixes by Finlay Dobbie. These ones fix some problems
in the MSNSLP and MSNObject code.
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Thu, 27 May 2004 06:06:03 +0000 |
parents | 06f57183e29f |
children | ab6636c5a136 |
rev | line source |
---|---|
6701 | 1 /** |
2 * @file msnobject.c MSNObject API | |
3 * | |
4 * gaim | |
5 * | |
8475
06f57183e29f
[gaim-migrate @ 9208]
Christian Hammond <chipx86@chipx86.com>
parents:
7933
diff
changeset
|
6 * Copyright (C) 2003-2004 Christian Hammond <chipx86@gnupdate.org> |
6701 | 7 * |
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 "msnobject.h" | |
23 | |
24 #define GET_STRING_TAG(field, id) \ | |
25 if ((tag = strstr(str, id "=\"")) != NULL) \ | |
26 { \ | |
27 tag += strlen(id "=\""); \ | |
28 c = strchr(tag, '"'); \ | |
7933
f0784ce8189a
[gaim-migrate @ 8604]
Christian Hammond <chipx86@chipx86.com>
parents:
6790
diff
changeset
|
29 if (c != NULL) \ |
f0784ce8189a
[gaim-migrate @ 8604]
Christian Hammond <chipx86@chipx86.com>
parents:
6790
diff
changeset
|
30 obj->field = g_strndup(tag, c - tag); \ |
6701 | 31 } |
32 | |
33 #define GET_INT_TAG(field, id) \ | |
34 if ((tag = strstr(str, id "=\"")) != NULL) \ | |
35 { \ | |
36 char buf[16]; \ | |
37 tag += strlen(id "=\""); \ | |
38 c = strchr(tag, '"'); \ | |
7933
f0784ce8189a
[gaim-migrate @ 8604]
Christian Hammond <chipx86@chipx86.com>
parents:
6790
diff
changeset
|
39 if (c != NULL) \ |
f0784ce8189a
[gaim-migrate @ 8604]
Christian Hammond <chipx86@chipx86.com>
parents:
6790
diff
changeset
|
40 { \ |
f0784ce8189a
[gaim-migrate @ 8604]
Christian Hammond <chipx86@chipx86.com>
parents:
6790
diff
changeset
|
41 strncpy(buf, tag, c - tag); \ |
9087
f32ee2e97b37
[gaim-migrate @ 9864]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
42 buf[c - tag] = '\0'; \ |
7933
f0784ce8189a
[gaim-migrate @ 8604]
Christian Hammond <chipx86@chipx86.com>
parents:
6790
diff
changeset
|
43 obj->field = atoi(buf); \ |
f0784ce8189a
[gaim-migrate @ 8604]
Christian Hammond <chipx86@chipx86.com>
parents:
6790
diff
changeset
|
44 } \ |
6701 | 45 } |
46 | |
47 MsnObject * | |
48 msn_object_new(void) | |
49 { | |
50 MsnObject *obj; | |
51 | |
52 obj = g_new0(MsnObject, 1); | |
53 | |
54 msn_object_set_type(obj, MSN_OBJECT_UNKNOWN); | |
55 msn_object_set_friendly(obj, "AAA="); | |
56 | |
57 return obj; | |
58 } | |
59 | |
60 MsnObject * | |
61 msn_object_new_from_string(const char *str) | |
62 { | |
63 MsnObject *obj; | |
64 char *tag, *c; | |
65 | |
66 g_return_val_if_fail(str != NULL, NULL); | |
67 g_return_val_if_fail(!strncmp(str, "<msnobj ", 8), NULL); | |
68 | |
69 obj = msn_object_new(); | |
70 | |
71 GET_STRING_TAG(creator, "Creator"); | |
72 GET_INT_TAG(size, "Size"); | |
73 GET_INT_TAG(type, "Type"); | |
74 GET_STRING_TAG(location, "Location"); | |
75 GET_STRING_TAG(friendly, "Friendly"); | |
76 GET_STRING_TAG(sha1d, "SHA1D"); | |
77 GET_STRING_TAG(sha1c, "SHA1C"); | |
78 | |
79 return obj; | |
80 } | |
81 | |
6789
94b575afb77e
[gaim-migrate @ 7328]
Christian Hammond <chipx86@chipx86.com>
parents:
6701
diff
changeset
|
82 void |
94b575afb77e
[gaim-migrate @ 7328]
Christian Hammond <chipx86@chipx86.com>
parents:
6701
diff
changeset
|
83 msn_object_destroy(MsnObject *obj) |
94b575afb77e
[gaim-migrate @ 7328]
Christian Hammond <chipx86@chipx86.com>
parents:
6701
diff
changeset
|
84 { |
94b575afb77e
[gaim-migrate @ 7328]
Christian Hammond <chipx86@chipx86.com>
parents:
6701
diff
changeset
|
85 g_return_if_fail(obj != NULL); |
94b575afb77e
[gaim-migrate @ 7328]
Christian Hammond <chipx86@chipx86.com>
parents:
6701
diff
changeset
|
86 |
94b575afb77e
[gaim-migrate @ 7328]
Christian Hammond <chipx86@chipx86.com>
parents:
6701
diff
changeset
|
87 if (obj->creator != NULL) |
94b575afb77e
[gaim-migrate @ 7328]
Christian Hammond <chipx86@chipx86.com>
parents:
6701
diff
changeset
|
88 g_free(obj->creator); |
94b575afb77e
[gaim-migrate @ 7328]
Christian Hammond <chipx86@chipx86.com>
parents:
6701
diff
changeset
|
89 |
94b575afb77e
[gaim-migrate @ 7328]
Christian Hammond <chipx86@chipx86.com>
parents:
6701
diff
changeset
|
90 if (obj->location != NULL) |
94b575afb77e
[gaim-migrate @ 7328]
Christian Hammond <chipx86@chipx86.com>
parents:
6701
diff
changeset
|
91 g_free(obj->location); |
94b575afb77e
[gaim-migrate @ 7328]
Christian Hammond <chipx86@chipx86.com>
parents:
6701
diff
changeset
|
92 |
94b575afb77e
[gaim-migrate @ 7328]
Christian Hammond <chipx86@chipx86.com>
parents:
6701
diff
changeset
|
93 if (obj->friendly != NULL) |
94b575afb77e
[gaim-migrate @ 7328]
Christian Hammond <chipx86@chipx86.com>
parents:
6701
diff
changeset
|
94 g_free(obj->friendly); |
94b575afb77e
[gaim-migrate @ 7328]
Christian Hammond <chipx86@chipx86.com>
parents:
6701
diff
changeset
|
95 |
94b575afb77e
[gaim-migrate @ 7328]
Christian Hammond <chipx86@chipx86.com>
parents:
6701
diff
changeset
|
96 if (obj->sha1d != NULL) |
94b575afb77e
[gaim-migrate @ 7328]
Christian Hammond <chipx86@chipx86.com>
parents:
6701
diff
changeset
|
97 g_free(obj->sha1d); |
94b575afb77e
[gaim-migrate @ 7328]
Christian Hammond <chipx86@chipx86.com>
parents:
6701
diff
changeset
|
98 |
94b575afb77e
[gaim-migrate @ 7328]
Christian Hammond <chipx86@chipx86.com>
parents:
6701
diff
changeset
|
99 if (obj->sha1c != NULL) |
94b575afb77e
[gaim-migrate @ 7328]
Christian Hammond <chipx86@chipx86.com>
parents:
6701
diff
changeset
|
100 g_free(obj->sha1c); |
94b575afb77e
[gaim-migrate @ 7328]
Christian Hammond <chipx86@chipx86.com>
parents:
6701
diff
changeset
|
101 |
94b575afb77e
[gaim-migrate @ 7328]
Christian Hammond <chipx86@chipx86.com>
parents:
6701
diff
changeset
|
102 g_free(obj); |
94b575afb77e
[gaim-migrate @ 7328]
Christian Hammond <chipx86@chipx86.com>
parents:
6701
diff
changeset
|
103 } |
94b575afb77e
[gaim-migrate @ 7328]
Christian Hammond <chipx86@chipx86.com>
parents:
6701
diff
changeset
|
104 |
6701 | 105 char * |
106 msn_object_to_string(const MsnObject *obj) | |
107 { | |
108 char *str; | |
109 | |
110 g_return_val_if_fail(obj != NULL, NULL); | |
111 | |
112 str = g_strdup_printf("<msnobj Creator=\"%s\" Size=\"%d\" Type=\"%d\" " | |
113 "Location=\"%s\" Friendly=\"%s\" SHA1D=\"%s\" " | |
114 "SHA1C=\"%s\"/>", | |
115 msn_object_get_creator(obj), | |
116 msn_object_get_size(obj), | |
117 msn_object_get_type(obj), | |
118 msn_object_get_location(obj), | |
119 msn_object_get_friendly(obj), | |
120 msn_object_get_sha1d(obj), | |
121 msn_object_get_sha1c(obj)); | |
122 | |
123 return str; | |
124 } | |
125 | |
126 void | |
127 msn_object_set_creator(MsnObject *obj, const char *creator) | |
128 { | |
129 g_return_if_fail(obj != NULL); | |
130 | |
131 if (obj->creator != NULL) | |
132 g_free(obj->creator); | |
133 | |
134 obj->creator = (creator == NULL ? NULL : g_strdup(creator)); | |
135 } | |
136 | |
137 void | |
138 msn_object_set_size(MsnObject *obj, int size) | |
139 { | |
140 g_return_if_fail(obj != NULL); | |
141 | |
142 obj->size = size; | |
143 } | |
144 | |
145 void | |
146 msn_object_set_type(MsnObject *obj, MsnObjectType type) | |
147 { | |
148 g_return_if_fail(obj != NULL); | |
149 | |
150 obj->type = type; | |
151 } | |
152 | |
153 void | |
154 msn_object_set_location(MsnObject *obj, const char *location) | |
155 { | |
156 g_return_if_fail(obj != NULL); | |
157 | |
158 if (obj->location != NULL) | |
159 g_free(obj->location); | |
160 | |
161 obj->location = (location == NULL ? NULL : g_strdup(location)); | |
162 } | |
163 | |
164 void | |
165 msn_object_set_friendly(MsnObject *obj, const char *friendly) | |
166 { | |
167 g_return_if_fail(obj != NULL); | |
168 | |
169 if (obj->friendly != NULL) | |
170 g_free(obj->friendly); | |
171 | |
172 obj->friendly = (friendly == NULL ? NULL : g_strdup(friendly)); | |
173 } | |
174 | |
175 void | |
176 msn_object_set_sha1d(MsnObject *obj, const char *sha1d) | |
177 { | |
178 g_return_if_fail(obj != NULL); | |
179 | |
180 if (obj->sha1d != NULL) | |
181 g_free(obj->sha1d); | |
182 | |
183 obj->sha1d = (sha1d == NULL ? NULL : g_strdup(sha1d)); | |
184 } | |
185 | |
186 void | |
187 msn_object_set_sha1c(MsnObject *obj, const char *sha1c) | |
188 { | |
189 g_return_if_fail(obj != NULL); | |
190 | |
191 if (obj->sha1c != NULL) | |
192 g_free(obj->sha1c); | |
193 | |
194 obj->sha1c = (sha1c == NULL ? NULL : g_strdup(sha1c)); | |
195 } | |
196 | |
197 const char * | |
198 msn_object_get_creator(const MsnObject *obj) | |
199 { | |
200 g_return_val_if_fail(obj != NULL, NULL); | |
201 | |
202 return obj->creator; | |
203 } | |
204 | |
205 int | |
206 msn_object_get_size(const MsnObject *obj) | |
207 { | |
208 g_return_val_if_fail(obj != NULL, 0); | |
209 | |
210 return obj->size; | |
211 } | |
212 | |
213 MsnObjectType | |
214 msn_object_get_type(const MsnObject *obj) | |
215 { | |
216 g_return_val_if_fail(obj != NULL, MSN_OBJECT_UNKNOWN); | |
217 | |
218 return obj->type; | |
219 } | |
220 | |
221 const char * | |
222 msn_object_get_location(const MsnObject *obj) | |
223 { | |
224 g_return_val_if_fail(obj != NULL, NULL); | |
225 | |
226 return obj->location; | |
227 } | |
228 | |
229 const char * | |
230 msn_object_get_friendly(const MsnObject *obj) | |
231 { | |
232 g_return_val_if_fail(obj != NULL, NULL); | |
233 | |
234 return obj->friendly; | |
235 } | |
236 | |
237 const char * | |
238 msn_object_get_sha1d(const MsnObject *obj) | |
239 { | |
240 g_return_val_if_fail(obj != NULL, NULL); | |
241 | |
242 return obj->sha1d; | |
243 } | |
244 | |
245 const char * | |
246 msn_object_get_sha1c(const MsnObject *obj) | |
247 { | |
248 g_return_val_if_fail(obj != NULL, NULL); | |
249 | |
250 return obj->sha1c; | |
251 } |