Changeset 9640
- Timestamp:
- 05/14/08 20:30:39 (3 months ago)
- Location:
- trunk/src/common
- Files:
-
- 2 modified
-
caps.py (modified) (1 diff)
-
helpers.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/common/caps.py
r9532 r9640 237 237 node, hash = node.split('#', 1) 238 238 computed_hash = helpers.compute_caps_hash(identities, features, 239 contact.caps_hash_method)239 dataforms=dataforms, hash_method=contact.caps_hash_method) 240 240 if computed_hash != hash: 241 241 # wrong hash, forget it -
trunk/src/common/helpers.py
r9610 r9640 1246 1246 return 0 1247 1247 1248 def compute_caps_hash(identities, features, hash_method='sha-1'): 1248 def sort_dataforms_func(d1, d2): 1249 f1 = d1.getField('FORM_TYPE') 1250 f2 = d2.getField('FORM_TYPE') 1251 if f1 and f2 and (f1.getValue() < f2.getValue()): 1252 return -1 1253 return 1 1254 1255 def compute_caps_hash(identities, features, dataforms=[], hash_method='sha-1'): 1256 '''Compute caps hash according to XEP-0115, V1.5 1257 1258 dataforms are xmpp.DataForms objects as common.dataforms don't allow several 1259 values without a field type list-multi''' 1249 1260 S = '' 1250 1261 identities.sort(cmp=sort_identities_func) … … 1267 1278 for f in features: 1268 1279 S += '%s<' % f 1280 dataforms.sort(cmp=sort_dataforms_func) 1281 for dataform in dataforms: 1282 # fields indexed by var 1283 fields = {} 1284 for f in dataform.getChildren(): 1285 fields[f.getVar()] = f 1286 form_type = fields.get('FORM_TYPE') 1287 if form_type: 1288 S += form_type.getValue() + '<' 1289 del fields['FORM_TYPE'] 1290 vars = fields.keys() 1291 vars.sort() 1292 for var in vars: 1293 S += '%s<' % var 1294 values = fields[var].getValues() 1295 values.sort() 1296 for value in values: 1297 S += '%s<' % value 1298 1299 print S 1269 1300 if hash_method == 'sha-1': 1270 1301 hash = hash_sha1(S)
