mcabber/src/jabglue.c
changeset 1022 4c8d7b558e83
parent 1019 9d5f6e0ea7b3
child 1023 94d9a3cbb211
equal deleted inserted replaced
1021:97f862e44d5d 1022:4c8d7b558e83
  1236   else
  1236   else
  1237     scr_LogPrint(LPRINT_LOGNORM,
  1237     scr_LogPrint(LPRINT_LOGNORM,
  1238                  "Warning: you're not connected to the server.");
  1238                  "Warning: you're not connected to the server.");
  1239 }
  1239 }
  1240 
  1240 
       
  1241 static struct annotation *parse_storage_rosternote(xmlnode notenode)
       
  1242 {
       
  1243   const char *p;
       
  1244   struct annotation *note = g_new0(struct annotation, 1);
       
  1245   p = xmlnode_get_attrib(notenode, "cdate");
       
  1246   if (p)
       
  1247     note->cdate = from_iso8601(p, 1);
       
  1248   p = xmlnode_get_attrib(notenode, "mdate");
       
  1249   if (p)
       
  1250     note->mdate = from_iso8601(p, 1);
       
  1251   note->text = g_strdup(xmlnode_get_data(notenode));
       
  1252   note->jid = g_strdup(xmlnode_get_attrib(notenode, "jid"));
       
  1253   return note;
       
  1254 }
       
  1255 
       
  1256 //  jb_get_all_storage_rosternotes()
       
  1257 // Return a GSList with all storage annotations.
       
  1258 // The caller should g_free the list and its contents.
       
  1259 GSList *jb_get_all_storage_rosternotes(void)
       
  1260 {
       
  1261   xmlnode x;
       
  1262   GSList *sl_notes = NULL;
       
  1263 
       
  1264   // If we have no rosternotes, probably the server doesn't support them.
       
  1265   if (!rosternotes)
       
  1266     return NULL;
       
  1267 
       
  1268   // Walk through the storage rosternotes tags
       
  1269   x = xmlnode_get_firstchild(rosternotes);
       
  1270   for ( ; x; x = xmlnode_get_nextsibling(x)) {
       
  1271     const char *p;
       
  1272     struct annotation *note;
       
  1273     p = xmlnode_get_name(x);
       
  1274 
       
  1275     // We want a note item
       
  1276     if (!p || strcmp(p, "note"))
       
  1277       continue;
       
  1278     // Just in case, check the jid...
       
  1279     if (!xmlnode_get_attrib(x, "jid"))
       
  1280       continue;
       
  1281     // Ok, let's add the note to our list
       
  1282     note = parse_storage_rosternote(x);
       
  1283     sl_notes = g_slist_append(sl_notes, note);
       
  1284   }
       
  1285   return sl_notes;
       
  1286 }
       
  1287 
  1241 //  jb_get_storage_rosternotes(barejid)
  1288 //  jb_get_storage_rosternotes(barejid)
  1242 // Return the annotation associated with this jid.
  1289 // Return the annotation associated with this jid.
  1243 // The caller should g_free the string and structure after use.
  1290 // The caller should g_free the string and structure after use.
  1244 struct annotation *jb_get_storage_rosternotes(const char *barejid)
  1291 struct annotation *jb_get_storage_rosternotes(const char *barejid)
  1245 {
  1292 {
  1253     scr_LogPrint(LPRINT_LOGNORM,
  1300     scr_LogPrint(LPRINT_LOGNORM,
  1254                  "Sorry, your server doesn't seem to support private storage.");
  1301                  "Sorry, your server doesn't seem to support private storage.");
  1255     return NULL;
  1302     return NULL;
  1256   }
  1303   }
  1257 
  1304 
  1258   // Walk through the storage tags
  1305   // Walk through the storage rosternotes tags
  1259   x = xmlnode_get_firstchild(rosternotes);
  1306   x = xmlnode_get_firstchild(rosternotes);
  1260   for ( ; x; x = xmlnode_get_nextsibling(x)) {
  1307   for ( ; x; x = xmlnode_get_nextsibling(x)) {
  1261     const char *jid;
  1308     const char *jid;
  1262     const char *p;
  1309     const char *p;
  1263     p = xmlnode_get_name(x);
  1310     p = xmlnode_get_name(x);
  1264     // If the current node is a conference item, see if we have to replace it.
  1311     // We want a note item
  1265     if (p && !strcmp(p, "note")) {
  1312     if (!p || strcmp(p, "note"))
  1266       jid = xmlnode_get_attrib(x, "jid");
  1313       continue;
  1267       if (!jid)
  1314     // Just in case, check the jid...
  1268         continue;
  1315     jid = xmlnode_get_attrib(x, "jid");
  1269       if (!strcmp(jid, barejid)) {
  1316     if (jid && !strcmp(jid, barejid))  // We've found a note for this contact.
  1270         // We've found a note for this contact.
  1317       return parse_storage_rosternote(x);
  1271         struct annotation *note = g_new0(struct annotation, 1);
       
  1272         p = xmlnode_get_attrib(x, "cdate");
       
  1273         if (p)
       
  1274           note->cdate = from_iso8601(p, 1);
       
  1275         p = xmlnode_get_attrib(x, "mdate");
       
  1276         if (p)
       
  1277           note->mdate = from_iso8601(p, 1);
       
  1278         note->text = g_strdup(xmlnode_get_data(x));
       
  1279         return note;
       
  1280       }
       
  1281     }
       
  1282   }
  1318   }
  1283   return NULL;  // No note found
  1319   return NULL;  // No note found
  1284 }
  1320 }
  1285 
  1321 
  1286 //  jb_set_storage_rosternotes(barejid, note)
  1322 //  jb_set_storage_rosternotes(barejid, note)