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