~ted/pidgin/11_buddy_list_really_show.patch

« back to all changes in this revision

Viewing changes to libpurple/protocols/msnp9/object.c

  • Committer: Bazaar Package Importer
  • Date: 2008-10-31 18:38:59 UTC
  • Revision ID: jamesw@ubuntu.com-20081031183859-yj2xlz1megi5k5w9
Tags: upstream-ubuntu-2.5.0
ImportĀ upstreamĀ versionĀ 2.5.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
 */
24
24
#include "object.h"
25
25
#include "debug.h"
 
26
/* Sha1 stuff */
 
27
#include "cipher.h"
 
28
/* Base64 stuff */
 
29
#include "util.h"
26
30
 
27
31
#define GET_STRING_TAG(field, id) \
28
32
        if ((tag = strstr(str, id "=\"")) != NULL) \
104
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
179
void
108
180
msn_object_destroy(MsnObject *obj)
109
181
{