diff options
author | Evgeniy Khramtsov <ekhramtsov@process-one.net> | 2010-08-07 22:04:57 +1000 |
---|---|---|
committer | Evgeniy Khramtsov <ekhramtsov@process-one.net> | 2010-08-07 22:04:57 +1000 |
commit | d2d8a09b4afdb5f77b903411ff16fbb0b739d3e4 (patch) | |
tree | 7cc9c6958cb9f055084a60c0bebd79e12e59215d /src/mod_caps.erl | |
parent | Make xml.c correctly compiles on R14A (EJAB-1288) (diff) |
Make MD2 autodetected (EJAB-1285)
Diffstat (limited to 'src/mod_caps.erl')
-rw-r--r-- | src/mod_caps.erl | 82 |
1 files changed, 62 insertions, 20 deletions
diff --git a/src/mod_caps.erl b/src/mod_caps.erl index 7fb011ef9..d9f4f30c8 100644 --- a/src/mod_caps.erl +++ b/src/mod_caps.erl @@ -276,25 +276,8 @@ feature_response(#iq{type = result, sub_el = [{xmlelement, _, _, Els}]}, Host, From, Caps, [SubNode | SubNodes]) -> BinaryNode = node_to_binary(Caps#caps.node, SubNode), - IsValid = case Caps#caps.hash of - "md2" -> - Caps#caps.version == make_disco_hash(Els, md2); - "md5" -> - Caps#caps.version == make_disco_hash(Els, md5); - "sha-1" -> - Caps#caps.version == make_disco_hash(Els, sha1); - "sha-224" -> - Caps#caps.version == make_disco_hash(Els, sha224); - "sha-256" -> - Caps#caps.version == make_disco_hash(Els, sha256); - "sha-384" -> - Caps#caps.version == make_disco_hash(Els, sha384); - "sha-512" -> - Caps#caps.version == make_disco_hash(Els, sha512); - _ -> - true - end, - if IsValid -> + case check_hash(Caps, Els) of + true -> Features = lists:flatmap( fun({xmlelement, "feature", FAttrs, _}) -> [xml:get_attr_s("var", FAttrs)]; @@ -304,7 +287,7 @@ feature_response(#iq{type = result, mnesia:dirty_write( #caps_features{node_pair = BinaryNode, features = features_to_binary(Features)}); - true -> + false -> mnesia:dirty_write(#caps_features{node_pair = BinaryNode}) end, feature_request(Host, From, Caps, SubNodes); @@ -349,6 +332,7 @@ make_my_disco_hash(Host) -> "" end. +-ifdef(HAVE_MD2). make_disco_hash(DiscoEls, Algo) -> Concat = [concat_identities(DiscoEls), concat_features(DiscoEls), @@ -370,6 +354,64 @@ make_disco_hash(DiscoEls, Algo) -> sha:sha512(Concat) end). +check_hash(Caps, Els) -> + case Caps#caps.hash of + "md2" -> + Caps#caps.version == make_disco_hash(Els, md2); + "md5" -> + Caps#caps.version == make_disco_hash(Els, md5); + "sha-1" -> + Caps#caps.version == make_disco_hash(Els, sha1); + "sha-224" -> + Caps#caps.version == make_disco_hash(Els, sha224); + "sha-256" -> + Caps#caps.version == make_disco_hash(Els, sha256); + "sha-384" -> + Caps#caps.version == make_disco_hash(Els, sha384); + "sha-512" -> + Caps#caps.version == make_disco_hash(Els, sha512); + _ -> + true + end. +-else. +make_disco_hash(DiscoEls, Algo) -> + Concat = [concat_identities(DiscoEls), + concat_features(DiscoEls), + concat_info(DiscoEls)], + base64:encode_to_string( + if Algo == md5 -> + crypto:md5(Concat); + Algo == sha1 -> + crypto:sha(Concat); + Algo == sha224 -> + sha:sha224(Concat); + Algo == sha256 -> + sha:sha256(Concat); + Algo == sha384 -> + sha:sha384(Concat); + Algo == sha512 -> + sha:sha512(Concat) + end). + +check_hash(Caps, Els) -> + case Caps#caps.hash of + "md5" -> + Caps#caps.version == make_disco_hash(Els, md5); + "sha-1" -> + Caps#caps.version == make_disco_hash(Els, sha1); + "sha-224" -> + Caps#caps.version == make_disco_hash(Els, sha224); + "sha-256" -> + Caps#caps.version == make_disco_hash(Els, sha256); + "sha-384" -> + Caps#caps.version == make_disco_hash(Els, sha384); + "sha-512" -> + Caps#caps.version == make_disco_hash(Els, sha512); + _ -> + true + end. +-endif. + concat_features(Els) -> lists:usort( lists:flatmap( |