Mercurial > ~mikael > mcabber > hg
comparison mcabber/src/jabglue.c @ 1016:4d3c48844746
Add /roster note
Implement XEP-0145 (Annotations)
Usage: /roster note [-|note_text]
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Wed, 15 Nov 2006 00:04:57 +0100 |
parents | 579299b1c9b2 |
children | 41f9a2a4c1de |
comparison
equal
deleted
inserted
replaced
1015:579299b1c9b2 | 1016:4d3c48844746 |
---|---|
1225 xmlnode_insert_cdata(xmlnode_insert_tag(x, "password"), passwd, -1); | 1225 xmlnode_insert_cdata(xmlnode_insert_tag(x, "password"), passwd, -1); |
1226 } | 1226 } |
1227 | 1227 |
1228 if (online) | 1228 if (online) |
1229 send_storage_bookmarks(); | 1229 send_storage_bookmarks(); |
1230 else | |
1231 scr_LogPrint(LPRINT_LOGNORM, | |
1232 "Warning: you're not connected to the server."); | |
1233 } | |
1234 | |
1235 // jb_get_storage_rosternotes(barejid) | |
1236 // Return thenote associated to this jid. | |
1237 // The caller should g_free the string after use. | |
1238 char *jb_get_storage_rosternotes(const char *barejid) | |
1239 { | |
1240 xmlnode x; | |
1241 | |
1242 if (!barejid) | |
1243 return NULL; | |
1244 | |
1245 // If we have no rosternotes, probably the server doesn't support them. | |
1246 if (!rosternotes) { | |
1247 scr_LogPrint(LPRINT_LOGNORM, | |
1248 "Sorry, your server doesn't seem to support private storage."); | |
1249 return NULL; | |
1250 } | |
1251 | |
1252 // Walk through the storage tags | |
1253 x = xmlnode_get_firstchild(rosternotes); | |
1254 for ( ; x; x = xmlnode_get_nextsibling(x)) { | |
1255 const char *jid; | |
1256 const char *p; | |
1257 p = xmlnode_get_name(x); | |
1258 // If the current node is a conference item, see if we have to replace it. | |
1259 if (p && !strcmp(p, "note")) { | |
1260 jid = xmlnode_get_attrib(x, "jid"); | |
1261 if (!jid) | |
1262 continue; | |
1263 if (!strcmp(jid, barejid)) { | |
1264 // We've found a note for this contact. | |
1265 return g_strdup(xmlnode_get_data(x)); | |
1266 } | |
1267 } | |
1268 } | |
1269 return NULL; // No note found | |
1270 } | |
1271 | |
1272 // jb_set_storage_rosternotes(barejid, note) | |
1273 // Update the private storage rosternotes: add/delete a note. | |
1274 // If note is nil, we remove the existing note. | |
1275 void jb_set_storage_rosternotes(const char *barejid, const char *note) | |
1276 { | |
1277 xmlnode x; | |
1278 | |
1279 if (!barejid) | |
1280 return; | |
1281 | |
1282 // If we have no rosternotes, probably the server doesn't support them. | |
1283 if (!rosternotes) { | |
1284 scr_LogPrint(LPRINT_LOGNORM, | |
1285 "Sorry, your server doesn't seem to support private storage."); | |
1286 return; | |
1287 } | |
1288 | |
1289 // Walk through the storage tags | |
1290 x = xmlnode_get_firstchild(rosternotes); | |
1291 for ( ; x; x = xmlnode_get_nextsibling(x)) { | |
1292 const char *jid; | |
1293 const char *p; | |
1294 p = xmlnode_get_name(x); | |
1295 // If the current node is a conference item, see if we have to replace it. | |
1296 if (p && !strcmp(p, "note")) { | |
1297 jid = xmlnode_get_attrib(x, "jid"); | |
1298 if (!jid) | |
1299 continue; | |
1300 if (!strcmp(jid, barejid)) { | |
1301 // We've found a note for this jid. Let's hide it and we'll | |
1302 // create a new one. | |
1303 xmlnode_hide(x); | |
1304 break; | |
1305 } | |
1306 } | |
1307 } | |
1308 | |
1309 // Let's create a node for this jid, if the note is not NULL. | |
1310 if (note) { | |
1311 x = xmlnode_insert_tag(rosternotes, "note"); | |
1312 xmlnode_put_attrib(x, "jid", barejid); | |
1313 xmlnode_insert_cdata(x, note, -1); | |
1314 } | |
1315 | |
1316 if (online) | |
1317 send_storage_rosternotes(); | |
1230 else | 1318 else |
1231 scr_LogPrint(LPRINT_LOGNORM, | 1319 scr_LogPrint(LPRINT_LOGNORM, |
1232 "Warning: you're not connected to the server."); | 1320 "Warning: you're not connected to the server."); |
1233 } | 1321 } |
1234 | 1322 |