pidgin: 73581f49: Remove some duplicate code.
qulogic at pidgin.im
qulogic at pidgin.im
Fri May 21 18:03:31 EDT 2010
-----------------------------------------------------------------
Revision: 73581f49564a5040aa639bed28fed8f6f7db1094
Ancestor: e2e108d13dda5ace4cdfa56a394d045311a86b3b
Author: qulogic at pidgin.im
Date: 2010-04-24T20:37:49
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/73581f49564a5040aa639bed28fed8f6f7db1094
Modified files:
libpurple/protocols/msn/directconn.c
ChangeLog:
Remove some duplicate code.
-------------- next part --------------
============================================================
--- libpurple/protocols/msn/directconn.c a004ef0ee4f8109efd61908794f29a66797b1471
+++ libpurple/protocols/msn/directconn.c f46ef076ad5762766d2e834e6ebb9fa082014cf4
@@ -47,27 +47,22 @@ static void
#define DC_MAX_PACKET_SIZE (DC_PACKET_HEADER_SIZE + DC_MAX_BODY_SIZE)
static void
-msn_dc_generate_nonce(MsnDirectConn *dc)
+msn_dc_calculate_nonce_hash(MsnDirectConnNonceType type,
+ const guchar nonce[16], gchar nonce_hash[37])
{
- guint32 *nonce;
- int i;
guchar digest[20];
- nonce = (guint32 *)&dc->nonce;
- for (i = 0; i < 4; i++)
- nonce[i] = rand();
-
- if (dc->nonce_type == DC_NONCE_SHA1) {
+ if (type == DC_NONCE_SHA1) {
PurpleCipher *cipher = purple_ciphers_find_cipher("sha1");
PurpleCipherContext *context = purple_cipher_context_new(cipher, NULL);
- purple_cipher_context_append(context, dc->nonce, sizeof(dc->nonce));
+ purple_cipher_context_append(context, nonce, sizeof(nonce));
purple_cipher_context_digest(context, sizeof(digest), digest, NULL);
purple_cipher_context_destroy(context);
- } else if (dc->nonce_type == DC_NONCE_PLAIN) {
+ } else if (type == DC_NONCE_PLAIN) {
memcpy(digest, nonce, 16);
}
- g_sprintf(dc->nonce_hash,
+ g_sprintf(nonce_hash,
"%08X-%04X-%04X-%04X-%08X%04X",
GUINT32_FROM_LE(*((guint32 *)(digest + 0))),
GUINT16_FROM_LE(*((guint16 *)(digest + 4))),
@@ -76,7 +71,20 @@ msn_dc_generate_nonce(MsnDirectConn *dc)
GUINT32_FROM_BE(*((guint32 *)(digest + 10))),
GUINT16_FROM_BE(*((guint16 *)(digest + 14)))
);
+}
+static void
+msn_dc_generate_nonce(MsnDirectConn *dc)
+{
+ guint32 *nonce;
+ int i;
+
+ nonce = (guint32 *)&dc->nonce;
+ for (i = 0; i < 4; i++)
+ nonce[i] = rand();
+
+ msn_dc_calculate_nonce_hash(dc->nonce_type, dc->nonce, dc->nonce_hash);
+
if (purple_debug_is_verbose())
purple_debug_info("msn", "DC %p generated nonce %s\n", dc, dc->nonce_hash);
}
@@ -690,10 +698,7 @@ msn_dc_verify_handshake(MsnDirectConn *d
static gboolean
msn_dc_verify_handshake(MsnDirectConn *dc, guint32 packet_length)
{
- PurpleCipherContext *context;
- PurpleCipher *cipher;
guchar nonce[16];
- guchar digest[20];
gchar nonce_hash[37];
if (packet_length != DC_PACKET_HEADER_SIZE)
@@ -701,26 +706,8 @@ msn_dc_verify_handshake(MsnDirectConn *d
memcpy(nonce, dc->in_buffer + 4 + offsetof(MsnDcContext, ack_id), 16);
- if (dc->nonce_type == DC_NONCE_SHA1) {
- cipher = purple_ciphers_find_cipher("sha1");
- context = purple_cipher_context_new(cipher, NULL);
- purple_cipher_context_append(context, nonce, sizeof(nonce));
- purple_cipher_context_digest(context, sizeof(digest), digest, NULL);
- purple_cipher_context_destroy(context);
- } else if (dc->nonce_type == DC_NONCE_PLAIN) {
- memcpy(digest, nonce, 16);
- }
+ msn_dc_calculate_nonce_hash(dc->nonce_type, nonce, nonce_hash);
- g_sprintf(nonce_hash,
- "%08X-%04X-%04X-%04X-%08X%04X",
- GUINT32_FROM_LE(*((guint32 *)(digest + 0))),
- GUINT16_FROM_LE(*((guint16 *)(digest + 4))),
- GUINT16_FROM_LE(*((guint16 *)(digest + 6))),
- GUINT16_FROM_BE(*((guint16 *)(digest + 8))),
- GUINT32_FROM_BE(*((guint32 *)(digest + 10))),
- GUINT16_FROM_BE(*((guint16 *)(digest + 14)))
- );
-
if (g_str_equal(dc->remote_nonce, nonce_hash)) {
purple_debug_info("msn",
"Received nonce %s from buddy request "
More information about the Commits
mailing list