comparison libpurple/protocols/msn/object.c @ 23129:ac567757d236

propagate from branch 'im.pidgin.pidgin' (head 6be4a11c3e1bf403bbb6e1a7a754e4b99e7d9a44) to branch 'im.pidgin.pidgin.custom_smiley' (head fb801dc3cb44bc81a383a9e0a44ba099a3e99d1e)
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Wed, 07 May 2008 03:32:43 +0000
parents b65997110933
children 5cdd93dac7a2
comparison
equal deleted inserted replaced
22859:4409f8a0d7aa 23129:ac567757d236
21 * along with this program; if not, write to the Free Software 21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA 22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
23 */ 23 */
24 #include "object.h" 24 #include "object.h"
25 #include "debug.h" 25 #include "debug.h"
26 /* Sha1 stuff */
27 #include "cipher.h"
28 /* Base64 stuff */
29 #include "util.h"
26 30
27 #define GET_STRING_TAG(field, id) \ 31 #define GET_STRING_TAG(field, id) \
28 if ((tag = strstr(str, id "=\"")) != NULL) \ 32 if ((tag = strstr(str, id "=\"")) != NULL) \
29 { \ 33 { \
30 tag += strlen(id "=\""); \ 34 tag += strlen(id "=\""); \
102 } 106 }
103 107
104 return obj; 108 return obj;
105 } 109 }
106 110
111 MsnObject*
112 msn_object_new_from_image(PurpleStoredImage *img, const char *location,
113 const char *creator, MsnObjectType type)
114 {
115 MsnObject *msnobj;
116
117 PurpleCipherContext *ctx;
118 char *buf;
119 gconstpointer data;
120 size_t size;
121 char *base64;
122 unsigned char digest[20];
123
124 msnobj = NULL;
125
126 if (img == NULL)
127 return msnobj;
128
129 size = purple_imgstore_get_size(img);
130 data = purple_imgstore_get_data(img);
131
132 /* New object */
133 msnobj = msn_object_new();
134 msn_object_set_local(msnobj);
135 msn_object_set_type(msnobj, type);
136 msn_object_set_location(msnobj, location);
137 msn_object_set_creator(msnobj, creator);
138
139 msn_object_set_image(msnobj, img);
140
141 /* Compute the SHA1D field. */
142 memset(digest, 0, sizeof(digest));
143
144 ctx = purple_cipher_context_new_by_name("sha1", NULL);
145 purple_cipher_context_append(ctx, data, size);
146 purple_cipher_context_digest(ctx, sizeof(digest), digest, NULL);
147
148 base64 = purple_base64_encode(digest, sizeof(digest));
149 msn_object_set_sha1d(msnobj, base64);
150 g_free(base64);
151
152 msn_object_set_size(msnobj, size);
153
154 /* Compute the SHA1C field. */
155 buf = g_strdup_printf(
156 "Creator%sSize%dType%dLocation%sFriendly%sSHA1D%s",
157 msn_object_get_creator(msnobj),
158 msn_object_get_size(msnobj),
159 msn_object_get_type(msnobj),
160 msn_object_get_location(msnobj),
161 msn_object_get_friendly(msnobj),
162 msn_object_get_sha1d(msnobj));
163
164 memset(digest, 0, sizeof(digest));
165
166 purple_cipher_context_reset(ctx, NULL);
167 purple_cipher_context_append(ctx, (const guchar *)buf, strlen(buf));
168 purple_cipher_context_digest(ctx, sizeof(digest), digest, NULL);
169 purple_cipher_context_destroy(ctx);
170 g_free(buf);
171
172 base64 = purple_base64_encode(digest, sizeof(digest));
173 msn_object_set_sha1c(msnobj, base64);
174 g_free(base64);
175
176 return msnobj;
177 }
178
107 void 179 void
108 msn_object_destroy(MsnObject *obj) 180 msn_object_destroy(MsnObject *obj)
109 { 181 {
110 g_return_if_fail(obj != NULL); 182 g_return_if_fail(obj != NULL);
111 183