Make return clearer
[pidgin-git.git] / libpurple / protocols / simple / http.c
blob1b67275cb1244a0ca20d52dfa216c68b320dc329
1 /* purple
3 * Purple is the legal property of its developers, whose names are too numerous
4 * to list here. Please refer to the COPYRIGHT file distributed with this
5 * source distribution.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
23 #include "internal.h"
25 #include <glib.h>
27 /* plugin includes */
28 #include "http.h"
30 gchar *
31 simple_http_digest_calculate_session_key(const gchar *username,
32 const gchar *realm,
33 const gchar *password,
34 const gchar *nonce)
36 GChecksum *hasher;
37 gchar *hash;
39 g_return_val_if_fail(username != NULL, NULL);
40 g_return_val_if_fail(realm != NULL, NULL);
41 g_return_val_if_fail(password != NULL, NULL);
42 g_return_val_if_fail(nonce != NULL, NULL);
44 hasher = g_checksum_new(G_CHECKSUM_MD5);
45 g_return_val_if_fail(hasher != NULL, NULL);
47 g_checksum_update(hasher, (guchar *)username, -1);
48 g_checksum_update(hasher, (guchar *)":", -1);
49 g_checksum_update(hasher, (guchar *)realm, -1);
50 g_checksum_update(hasher, (guchar *)":", -1);
51 g_checksum_update(hasher, (guchar *)password, -1);
53 hash = g_strdup(g_checksum_get_string(hasher));
54 g_checksum_free(hasher);
56 return hash;
59 gchar *
60 simple_http_digest_calculate_response(const gchar *method,
61 const gchar *digest_uri,
62 const gchar *nonce,
63 const gchar *nonce_count,
64 const gchar *session_key)
66 GChecksum *hash;
67 gchar *hash2;
69 g_return_val_if_fail(method != NULL, NULL);
70 g_return_val_if_fail(digest_uri != NULL, NULL);
71 g_return_val_if_fail(nonce != NULL, NULL);
72 g_return_val_if_fail(session_key != NULL, NULL);
74 hash = g_checksum_new(G_CHECKSUM_MD5);
75 g_return_val_if_fail(hash != NULL, NULL);
77 g_checksum_update(hash, (guchar *)method, -1);
78 g_checksum_update(hash, (guchar *)":", -1);
79 g_checksum_update(hash, (guchar *)digest_uri, -1);
81 hash2 = g_strdup(g_checksum_get_string(hash));
82 g_checksum_reset(hash);
84 if (hash2 == NULL) {
85 g_checksum_free(hash);
86 g_return_val_if_reached(NULL);
89 g_checksum_update(hash, (guchar *)session_key, -1);
90 g_checksum_update(hash, (guchar *)":", -1);
91 g_checksum_update(hash, (guchar *)nonce, -1);
92 g_checksum_update(hash, (guchar *)":", -1);
94 g_checksum_update(hash, (guchar *)hash2, -1);
95 g_free(hash2);
97 hash2 = g_strdup(g_checksum_get_string(hash));
98 g_checksum_free(hash);
100 return hash2;