comparison src/protocols/msn/msnobject.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
children 94b575afb77e
comparison
equal deleted inserted replaced
6700:57161e3abbb5 6701:b7e113a59b51
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
79 char *
80 msn_object_to_string(const MsnObject *obj)
81 {
82 char *str;
83
84 g_return_val_if_fail(obj != NULL, NULL);
85
86 str = g_strdup_printf("<msnobj Creator=\"%s\" Size=\"%d\" Type=\"%d\" "
87 "Location=\"%s\" Friendly=\"%s\" SHA1D=\"%s\" "
88 "SHA1C=\"%s\"/>",
89 msn_object_get_creator(obj),
90 msn_object_get_size(obj),
91 msn_object_get_type(obj),
92 msn_object_get_location(obj),
93 msn_object_get_friendly(obj),
94 msn_object_get_sha1d(obj),
95 msn_object_get_sha1c(obj));
96
97 return str;
98 }
99
100 void
101 msn_object_set_creator(MsnObject *obj, const char *creator)
102 {
103 g_return_if_fail(obj != NULL);
104
105 if (obj->creator != NULL)
106 g_free(obj->creator);
107
108 obj->creator = (creator == NULL ? NULL : g_strdup(creator));
109 }
110
111 void
112 msn_object_set_size(MsnObject *obj, int size)
113 {
114 g_return_if_fail(obj != NULL);
115
116 obj->size = size;
117 }
118
119 void
120 msn_object_set_type(MsnObject *obj, MsnObjectType type)
121 {
122 g_return_if_fail(obj != NULL);
123
124 obj->type = type;
125 }
126
127 void
128 msn_object_set_location(MsnObject *obj, const char *location)
129 {
130 g_return_if_fail(obj != NULL);
131
132 if (obj->location != NULL)
133 g_free(obj->location);
134
135 obj->location = (location == NULL ? NULL : g_strdup(location));
136 }
137
138 void
139 msn_object_set_friendly(MsnObject *obj, const char *friendly)
140 {
141 g_return_if_fail(obj != NULL);
142
143 if (obj->friendly != NULL)
144 g_free(obj->friendly);
145
146 obj->friendly = (friendly == NULL ? NULL : g_strdup(friendly));
147 }
148
149 void
150 msn_object_set_sha1d(MsnObject *obj, const char *sha1d)
151 {
152 g_return_if_fail(obj != NULL);
153
154 if (obj->sha1d != NULL)
155 g_free(obj->sha1d);
156
157 obj->sha1d = (sha1d == NULL ? NULL : g_strdup(sha1d));
158 }
159
160 void
161 msn_object_set_sha1c(MsnObject *obj, const char *sha1c)
162 {
163 g_return_if_fail(obj != NULL);
164
165 if (obj->sha1c != NULL)
166 g_free(obj->sha1c);
167
168 obj->sha1c = (sha1c == NULL ? NULL : g_strdup(sha1c));
169 }
170
171 const char *
172 msn_object_get_creator(const MsnObject *obj)
173 {
174 g_return_val_if_fail(obj != NULL, NULL);
175
176 return obj->creator;
177 }
178
179 int
180 msn_object_get_size(const MsnObject *obj)
181 {
182 g_return_val_if_fail(obj != NULL, 0);
183
184 return obj->size;
185 }
186
187 MsnObjectType
188 msn_object_get_type(const MsnObject *obj)
189 {
190 g_return_val_if_fail(obj != NULL, MSN_OBJECT_UNKNOWN);
191
192 return obj->type;
193 }
194
195 const char *
196 msn_object_get_location(const MsnObject *obj)
197 {
198 g_return_val_if_fail(obj != NULL, NULL);
199
200 return obj->location;
201 }
202
203 const char *
204 msn_object_get_friendly(const MsnObject *obj)
205 {
206 g_return_val_if_fail(obj != NULL, NULL);
207
208 return obj->friendly;
209 }
210
211 const char *
212 msn_object_get_sha1d(const MsnObject *obj)
213 {
214 g_return_val_if_fail(obj != NULL, NULL);
215
216 return obj->sha1d;
217 }
218
219 const char *
220 msn_object_get_sha1c(const MsnObject *obj)
221 {
222 g_return_val_if_fail(obj != NULL, NULL);
223
224 return obj->sha1c;
225 }