Mercurial > pidgin
annotate src/protocols/msn/object.c @ 9246:e20af87d8721
[gaim-migrate @ 10045]
Patch from Felipe Contreras that fixes corrupt buddy icon checksums and
adds a menu item called "Update Buddy Icon."
committer: Tailor Script <tailor@pidgin.im>
| author | Christian Hammond <chipx86@chipx86.com> |
|---|---|
| date | Wed, 09 Jun 2004 05:32:17 +0000 |
| parents | ab6636c5a136 |
| children | 1e5ef71c9583 |
| rev | line source |
|---|---|
| 9193 | 1 /** |
| 2 * @file object.c MSNObject API | |
| 3 * | |
| 4 * gaim | |
| 5 * | |
|
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
6 * Gaim is the legal property of its developers, whose names are too numerous |
|
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
7 * to list here. Please refer to the COPYRIGHT file distributed with this |
|
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
8 * source distribution. |
| 9193 | 9 * |
| 10 * This program is free software; you can redistribute it and/or modify | |
| 11 * it under the terms of the GNU General Public License as published by | |
| 12 * the Free Software Foundation; either version 2 of the License, or | |
| 13 * (at your option) any later version. | |
| 14 * | |
| 15 * This program is distributed in the hope that it will be useful, | |
| 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 18 * GNU General Public License for more details. | |
| 19 * | |
| 20 * You should have received a copy of the GNU General Public License | |
| 21 * along with this program; if not, write to the Free Software | |
| 22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 23 */ | |
| 24 #include "object.h" | |
| 25 | |
| 26 #define GET_STRING_TAG(field, id) \ | |
| 27 if ((tag = strstr(str, id "=\"")) != NULL) \ | |
| 28 { \ | |
| 29 tag += strlen(id "=\""); \ | |
| 30 c = strchr(tag, '"'); \ | |
| 31 obj->field = g_strndup(tag, c - tag); \ | |
| 32 } | |
| 33 | |
| 34 #define GET_INT_TAG(field, id) \ | |
| 35 if ((tag = strstr(str, id "=\"")) != NULL) \ | |
| 36 { \ | |
| 37 char buf[16]; \ | |
| 38 tag += strlen(id "=\""); \ | |
| 39 c = strchr(tag, '"'); \ | |
| 40 strncpy(buf, tag, c - tag); \ | |
| 41 buf[c - tag] = '\0'; \ | |
| 42 obj->field = atoi(buf); \ | |
| 43 } | |
| 44 | |
| 45 static GList *local_objs; | |
| 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 | |
| 82 void | |
| 83 msn_object_destroy(MsnObject *obj) | |
| 84 { | |
| 85 g_return_if_fail(obj != NULL); | |
| 86 | |
| 87 if (obj->creator != NULL) | |
| 88 g_free(obj->creator); | |
| 89 | |
| 90 if (obj->location != NULL) | |
| 91 g_free(obj->location); | |
| 92 | |
| 93 if (obj->friendly != NULL) | |
| 94 g_free(obj->friendly); | |
| 95 | |
| 96 if (obj->sha1d != NULL) | |
| 97 g_free(obj->sha1d); | |
| 98 | |
| 99 if (obj->sha1c != NULL) | |
| 100 g_free(obj->sha1c); | |
|
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
101 |
| 9193 | 102 if (obj->local) |
| 103 local_objs = g_list_remove(local_objs, obj); | |
| 104 | |
| 105 g_free(obj); | |
| 106 } | |
| 107 | |
| 108 char * | |
| 109 msn_object_to_string(const MsnObject *obj) | |
| 110 { | |
| 111 char *str; | |
| 112 | |
| 113 g_return_val_if_fail(obj != NULL, NULL); | |
| 114 | |
| 115 str = g_strdup_printf("<msnobj Creator=\"%s\" Size=\"%d\" Type=\"%d\" " | |
| 116 "Location=\"%s\" Friendly=\"%s\" SHA1D=\"%s\" " | |
| 117 "SHA1C=\"%s\"/>", | |
| 118 msn_object_get_creator(obj), | |
| 119 msn_object_get_size(obj), | |
| 120 msn_object_get_type(obj), | |
| 121 msn_object_get_location(obj), | |
| 122 msn_object_get_friendly(obj), | |
| 123 msn_object_get_sha1d(obj), | |
| 124 msn_object_get_sha1c(obj)); | |
| 125 | |
| 126 return str; | |
| 127 } | |
| 128 | |
| 129 void | |
| 130 msn_object_set_creator(MsnObject *obj, const char *creator) | |
| 131 { | |
| 132 g_return_if_fail(obj != NULL); | |
| 133 | |
| 134 if (obj->creator != NULL) | |
| 135 g_free(obj->creator); | |
| 136 | |
| 137 obj->creator = (creator == NULL ? NULL : g_strdup(creator)); | |
| 138 } | |
| 139 | |
| 140 void | |
| 141 msn_object_set_size(MsnObject *obj, int size) | |
| 142 { | |
| 143 g_return_if_fail(obj != NULL); | |
| 144 | |
| 145 obj->size = size; | |
| 146 } | |
| 147 | |
| 148 void | |
| 149 msn_object_set_type(MsnObject *obj, MsnObjectType type) | |
| 150 { | |
| 151 g_return_if_fail(obj != NULL); | |
| 152 | |
| 153 obj->type = type; | |
| 154 } | |
| 155 | |
| 156 void | |
| 157 msn_object_set_location(MsnObject *obj, const char *location) | |
| 158 { | |
| 159 g_return_if_fail(obj != NULL); | |
| 160 | |
| 161 if (obj->location != NULL) | |
| 162 g_free(obj->location); | |
| 163 | |
| 164 obj->location = (location == NULL ? NULL : g_strdup(location)); | |
| 165 } | |
| 166 | |
| 167 void | |
| 168 msn_object_set_friendly(MsnObject *obj, const char *friendly) | |
| 169 { | |
| 170 g_return_if_fail(obj != NULL); | |
| 171 | |
| 172 if (obj->friendly != NULL) | |
| 173 g_free(obj->friendly); | |
| 174 | |
| 175 obj->friendly = (friendly == NULL ? NULL : g_strdup(friendly)); | |
| 176 } | |
| 177 | |
| 178 void | |
| 179 msn_object_set_sha1d(MsnObject *obj, const char *sha1d) | |
| 180 { | |
| 181 g_return_if_fail(obj != NULL); | |
| 182 | |
| 183 if (obj->sha1d != NULL) | |
| 184 g_free(obj->sha1d); | |
| 185 | |
| 186 obj->sha1d = (sha1d == NULL ? NULL : g_strdup(sha1d)); | |
| 187 } | |
| 188 | |
| 189 void | |
| 190 msn_object_set_sha1c(MsnObject *obj, const char *sha1c) | |
| 191 { | |
| 192 g_return_if_fail(obj != NULL); | |
| 193 | |
| 194 if (obj->sha1c != NULL) | |
| 195 g_free(obj->sha1c); | |
| 196 | |
| 197 obj->sha1c = (sha1c == NULL ? NULL : g_strdup(sha1c)); | |
| 198 } | |
| 199 | |
| 200 const char * | |
| 201 msn_object_get_creator(const MsnObject *obj) | |
| 202 { | |
| 203 g_return_val_if_fail(obj != NULL, NULL); | |
| 204 | |
| 205 return obj->creator; | |
| 206 } | |
| 207 | |
| 208 int | |
| 209 msn_object_get_size(const MsnObject *obj) | |
| 210 { | |
| 211 g_return_val_if_fail(obj != NULL, 0); | |
| 212 | |
| 213 return obj->size; | |
| 214 } | |
| 215 | |
| 216 MsnObjectType | |
| 217 msn_object_get_type(const MsnObject *obj) | |
| 218 { | |
| 219 g_return_val_if_fail(obj != NULL, MSN_OBJECT_UNKNOWN); | |
| 220 | |
| 221 return obj->type; | |
| 222 } | |
| 223 | |
| 224 const char * | |
| 225 msn_object_get_location(const MsnObject *obj) | |
| 226 { | |
| 227 g_return_val_if_fail(obj != NULL, NULL); | |
| 228 | |
| 229 return obj->location; | |
| 230 } | |
| 231 | |
| 232 const char * | |
| 233 msn_object_get_friendly(const MsnObject *obj) | |
| 234 { | |
| 235 g_return_val_if_fail(obj != NULL, NULL); | |
| 236 | |
| 237 return obj->friendly; | |
| 238 } | |
| 239 | |
| 240 const char * | |
| 241 msn_object_get_sha1d(const MsnObject *obj) | |
| 242 { | |
| 243 g_return_val_if_fail(obj != NULL, NULL); | |
| 244 | |
| 245 return obj->sha1d; | |
| 246 } | |
| 247 | |
| 248 const char * | |
| 249 msn_object_get_sha1c(const MsnObject *obj) | |
| 250 { | |
| 251 g_return_val_if_fail(obj != NULL, NULL); | |
| 252 | |
| 253 return obj->sha1c; | |
| 254 } | |
| 255 | |
| 256 MsnObject * | |
| 257 msn_object_find_local(const char *sha1c) | |
| 258 { | |
| 259 GList *l; | |
|
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
260 |
| 9193 | 261 g_return_val_if_fail(sha1c != NULL, NULL); |
| 262 | |
| 263 for (l = local_objs; l != NULL; l = l->next) | |
| 264 { | |
| 265 MsnObject *local_obj = l->data; | |
| 266 | |
| 267 if (!strcmp(msn_object_get_sha1c(local_obj), sha1c)) | |
| 268 return local_obj; | |
| 269 } | |
| 270 | |
| 271 return NULL; | |
| 272 | |
| 273 } | |
| 274 | |
| 275 void | |
| 276 msn_object_set_local(MsnObject *obj) | |
| 277 { | |
| 278 g_return_if_fail(obj != NULL); | |
| 279 | |
| 280 obj->local = TRUE; | |
| 281 | |
| 282 local_objs = g_list_append(local_objs, obj); | |
| 283 } | |
| 284 | |
| 285 void | |
| 286 msn_object_set_real_location(MsnObject *obj, const char *real_location) | |
| 287 { | |
| 288 g_return_if_fail(obj != NULL); | |
|
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
289 |
| 9193 | 290 /* obj->local = TRUE; */ |
| 291 | |
| 292 if (obj->real_location != NULL) | |
| 293 g_free(obj->real_location); | |
| 294 | |
| 295 obj->real_location = | |
| 296 (real_location == NULL ? NULL : g_strdup(real_location)); | |
| 297 } | |
| 298 | |
| 299 const char * | |
| 300 msn_object_get_real_location(const MsnObject *obj) | |
| 301 { | |
| 302 MsnObject *local_obj; | |
|
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
303 |
| 9193 | 304 g_return_val_if_fail(obj != NULL, NULL); |
| 305 | |
| 306 local_obj = msn_object_find_local(msn_object_get_sha1c(obj)); | |
| 307 | |
| 308 if (local_obj != NULL) | |
| 309 return local_obj->real_location; | |
|
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
310 |
| 9193 | 311 return NULL; |
| 312 } |
