| | 1204 | def sort_identities_func(i1, i2): |
| | 1205 | cat1 = i1['category'] |
| | 1206 | cat2 = i2['category'] |
| | 1207 | if cat1 < cat2: |
| | 1208 | return -1 |
| | 1209 | if cat1 > cat2: |
| | 1210 | return 1 |
| | 1211 | if i1.has_key('type'): |
| | 1212 | type1 = i1['type'] |
| | 1213 | else: |
| | 1214 | type1 = '' |
| | 1215 | if i2.has_key('type'): |
| | 1216 | type2 = i2['type'] |
| | 1217 | else: |
| | 1218 | type2 = '' |
| | 1219 | if type1 < type2: |
| | 1220 | return -1 |
| | 1221 | if type1 > type2: |
| | 1222 | return 1 |
| | 1223 | if i1.has_key('xml:lang'): |
| | 1224 | lang1 = i1['xml:lang'] |
| | 1225 | else: |
| | 1226 | lang1 = '' |
| | 1227 | if i2.has_key('xml:lang'): |
| | 1228 | lang2 = i2['xml:lang'] |
| | 1229 | else: |
| | 1230 | lang2 = '' |
| | 1231 | if lang1 < lang2: |
| | 1232 | return -1 |
| | 1233 | if lang1 > lang2: |
| | 1234 | return 1 |
| | 1235 | return 0 |
| | 1236 | |
| | 1237 | def compute_caps_hash(identities, features, hash_method='sha-1'): |
| | 1238 | S = '' |
| | 1239 | identities.sort(cmp=sort_identities_func) |
| | 1240 | for i in identities: |
| | 1241 | c = i['category'] |
| | 1242 | if i.has_key('type'): |
| | 1243 | type_ = i['type'] |
| | 1244 | else: |
| | 1245 | type_ = '' |
| | 1246 | if i.has_key('xml:lang'): |
| | 1247 | lang = i['xml:lang'] |
| | 1248 | else: |
| | 1249 | lang = '' |
| | 1250 | if i.has_key('name'): |
| | 1251 | name = i['name'] |
| | 1252 | else: |
| | 1253 | name = '' |
| | 1254 | S += '%s/%s/%s/%s<' % (c, type_, lang, name) |
| | 1255 | features.sort() |
| | 1256 | for f in features: |
| | 1257 | S += '%s<' % f |
| | 1258 | if hash_method == 'sha-1': |
| | 1259 | hash = hashlib.sha1(S) |
| | 1260 | elif hash_method == 'md5': |
| | 1261 | hash = hashlib.md5(S) |
| | 1262 | else: |
| | 1263 | return '' |
| | 1264 | return base64.b64encode(hash.digest()) |
| | 1265 | |
| | 1266 | def update_optional_features(): |
| | 1267 | gajim.gajim_optional_features = [] |
| | 1268 | if gajim.config.get('publish_mood'): |
| | 1269 | gajim.gajim_optional_features.append(xmpp.NS_MOOD) |
| | 1270 | if gajim.config.get('subscribe_mood'): |
| | 1271 | gajim.gajim_optional_features.append(xmpp.NS_MOOD + '+notify') |
| | 1272 | if gajim.config.get('publish_activity'): |
| | 1273 | gajim.gajim_optional_features.append(xmpp.NS_ACTIVITY) |
| | 1274 | if gajim.config.get('subscribe_activity'): |
| | 1275 | gajim.gajim_optional_features.append(xmpp.NS_ACTIVITY + '+notify') |
| | 1276 | if gajim.config.get('publish_tune'): |
| | 1277 | gajim.gajim_optional_features.append(xmpp.NS_TUNE) |
| | 1278 | if gajim.config.get('subscribe_tune'): |
| | 1279 | gajim.gajim_optional_features.append(xmpp.NS_TUNE + '+notify') |
| | 1280 | if gajim.config.get('outgoing_chat_state_notifactions') != 'disabled': |
| | 1281 | gajim.gajim_optional_features.append(xmpp.NS_CHATSTATES) |
| | 1282 | if not gajim.config.get('ignore_incoming_xhtml'): |
| | 1283 | gajim.gajim_optional_features.append(xmpp.NS_XHTML_IM) |
| | 1284 | if gajim.HAVE_PYCRYPTO: |
| | 1285 | gajim.gajim_optional_features.append(xmpp.NS_ESESSION_INIT) |
| | 1286 | gajim.caps_hash = compute_caps_hash([gajim.gajim_identity], |
| | 1287 | gajim.gajim_common_features + gajim.gajim_optional_features) |
| | 1288 | # re-send presence with new hash |
| | 1289 | for account in gajim.connections: |
| | 1290 | connected = gajim.connections[account].connected |
| | 1291 | if connected > 1 and gajim.SHOW_LIST[connected] != 'invisible': |
| | 1292 | gajim.connections[account].change_status(gajim.SHOW_LIST[connected], |
| | 1293 | gajim.connections[account].status) |