comparison mcabber/src/jabglue.c @ 625:028c01940490

Show presence timestamps in "/info" and "/room whois"
author Mikael Berthe <mikael@lilotux.net>
date Sat, 17 Dec 2005 18:39:04 +0100
parents 4e882a19077d
children 454399f026fa
comparison
equal deleted inserted replaced
624:4e882a19077d 625:028c01940490
900 break; 900 break;
901 } 901 }
902 previous_state = state; 902 previous_state = state;
903 } 903 }
904 904
905 static time_t xml_get_timestamp(xmlnode xmldata)
906 {
907 xmlnode x;
908 char *p;
909
910 x = xmlnode_get_firstchild(xmldata);
911 for ( ; x; x = xmlnode_get_nextsibling(x)) {
912 if ((p = xmlnode_get_name(x)) && !strcmp(p, "x"))
913 if ((p = xmlnode_get_attrib(x, "xmlns")) && !strcmp(p, NS_DELAY)) {
914 break;
915 }
916 }
917 if ((p = xmlnode_get_attrib(x, "stamp")) != NULL)
918 return from_iso8601(p, 1);
919 return 0;
920 }
921
905 static void handle_presence_muc(const char *from, xmlnode xmldata, 922 static void handle_presence_muc(const char *from, xmlnode xmldata,
906 const char *roomjid, const char *rname, 923 const char *roomjid, const char *rname,
907 enum imstatus ust, char *ustmsg, char bpprio) 924 enum imstatus ust, char *ustmsg,
925 time_t usttime, char bpprio)
908 { 926 {
909 xmlnode y; 927 xmlnode y;
910 char *p; 928 char *p;
911 const char *m; 929 const char *m;
912 enum imrole mbrole = role_none; 930 enum imrole mbrole = role_none;
1100 } 1118 }
1101 1119
1102 // Update room member status 1120 // Update room member status
1103 if (rname) { 1121 if (rname) {
1104 gchar *mbrjid_noutf8 = from_utf8(mbjid); 1122 gchar *mbrjid_noutf8 = from_utf8(mbjid);
1105 roster_setstatus(roomjid, rname, bpprio, ust, ustmsg, 1123 roster_setstatus(roomjid, rname, bpprio, ust, ustmsg, usttime,
1106 mbrole, mbaffil, mbrjid_noutf8); 1124 mbrole, mbaffil, mbrjid_noutf8);
1107 if (mbrjid_noutf8) 1125 if (mbrjid_noutf8)
1108 g_free(mbrjid_noutf8); 1126 g_free(mbrjid_noutf8);
1109 } else 1127 } else
1110 scr_LogPrint(LPRINT_LOGNORM, "MUC DBG: no rname!"); /* DBG */ 1128 scr_LogPrint(LPRINT_LOGNORM, "MUC DBG: no rname!"); /* DBG */
1120 char *ustmsg; 1138 char *ustmsg;
1121 xmlnode x; 1139 xmlnode x;
1122 const char *rname; 1140 const char *rname;
1123 enum imstatus ust; 1141 enum imstatus ust;
1124 char bpprio; 1142 char bpprio;
1143 time_t timestamp = 0;
1125 1144
1126 r = jidtodisp(from); 1145 r = jidtodisp(from);
1127 if (type && !strcmp(type, TMSG_ERROR)) { 1146 if (type && !strcmp(type, TMSG_ERROR)) {
1128 scr_LogPrint(LPRINT_LOGNORM, "Error presence packet from <%s>", r); 1147 scr_LogPrint(LPRINT_LOGNORM, "Error presence packet from <%s>", r);
1129 if ((x = xmlnode_get_tag(xmldata, TMSG_ERROR)) != NULL) 1148 if ((x = xmlnode_get_tag(xmldata, TMSG_ERROR)) != NULL)
1159 } 1178 }
1160 1179
1161 rname = strchr(from, '/'); 1180 rname = strchr(from, '/');
1162 if (rname) rname++; 1181 if (rname) rname++;
1163 1182
1183 // Timestamp?
1184 timestamp = xml_get_timestamp(xmldata);
1185
1164 // Check for MUC presence packet 1186 // Check for MUC presence packet
1165 // There can be multiple <x> tags!! 1187 // There can be multiple <x> tags!!
1166 x = xmlnode_get_firstchild(xmldata); 1188 x = xmlnode_get_firstchild(xmldata);
1167 for ( ; x; x = xmlnode_get_nextsibling(x)) { 1189 for ( ; x; x = xmlnode_get_nextsibling(x)) {
1168 if ((p = xmlnode_get_name(x)) && !strcmp(p, "x")) 1190 if ((p = xmlnode_get_name(x)) && !strcmp(p, "x"))
1169 if ((p = xmlnode_get_attrib(x, "xmlns")) && 1191 if ((p = xmlnode_get_attrib(x, "xmlns")) &&
1170 !strcasecmp(p, "http://jabber.org/protocol/muc#user")) 1192 !strcmp(p, "http://jabber.org/protocol/muc#user"))
1171 break; 1193 break;
1172 } 1194 }
1173 if (x) { 1195 if (x) {
1174 // This is a MUC presence message 1196 // This is a MUC presence message
1175 handle_presence_muc(from, x, r, rname, ust, ustmsg, bpprio); 1197 handle_presence_muc(from, x, r, rname, ust, ustmsg, timestamp, bpprio);
1176 } else { 1198 } else {
1177 // Not a MUC message, so this is a regular buddy... 1199 // Not a MUC message, so this is a regular buddy...
1178 // Call hk_statuschange() if status has changed or if the 1200 // Call hk_statuschange() if status has changed or if the
1179 // status message is different 1201 // status message is different
1180 const char *m = roster_getstatusmsg(r, rname); 1202 const char *m = roster_getstatusmsg(r, rname);
1181 if ((ust != roster_getstatus(r, rname)) || 1203 if ((ust != roster_getstatus(r, rname)) ||
1182 (!ustmsg && m && m[0]) || (ustmsg && (!m || strcmp(ustmsg, m)))) 1204 (!ustmsg && m && m[0]) || (ustmsg && (!m || strcmp(ustmsg, m))))
1183 hk_statuschange(r, rname, bpprio, 0, ust, ustmsg); 1205 hk_statuschange(r, rname, bpprio, timestamp, ust, ustmsg);
1184 } 1206 }
1185 1207
1186 g_free(r); 1208 g_free(r);
1187 if (ustmsg) g_free(ustmsg); 1209 if (ustmsg) g_free(ustmsg);
1188 } 1210 }
1247 xmlns = jabber:x:encrypted */ 1269 xmlns = jabber:x:encrypted */
1248 1270
1249 x = xmlnode_get_firstchild(xmldata); 1271 x = xmlnode_get_firstchild(xmldata);
1250 for ( ; x; x = xmlnode_get_nextsibling(x)) { 1272 for ( ; x; x = xmlnode_get_nextsibling(x)) {
1251 if ((p = xmlnode_get_name(x)) && !strcmp(p, "x")) 1273 if ((p = xmlnode_get_name(x)) && !strcmp(p, "x"))
1252 if ((p = xmlnode_get_attrib(x, "xmlns")) && 1274 if ((p = xmlnode_get_attrib(x, "xmlns")) && !strcmp(p, NS_ENCRYPTED))
1253 !strcasecmp(p, "jabber:x:encrypted"))
1254 if ((p = xmlnode_get_data(x)) != NULL) { 1275 if ((p = xmlnode_get_data(x)) != NULL) {
1255 enc = p; 1276 enc = p;
1256 break; 1277 break;
1257 } 1278 }
1258 } 1279 }
1259 1280
1260 // Timestamp? 1281 // Timestamp?
1261 if ((x = xmlnode_get_tag(xmldata, "x")) != NULL) { 1282 timestamp = xml_get_timestamp(xmldata);
1262 if ((p = xmlnode_get_attrib(x, "stamp")) != NULL)
1263 timestamp = from_iso8601(p, 1);
1264 }
1265 1283
1266 if (type && !strcmp(type, TMSG_ERROR)) { 1284 if (type && !strcmp(type, TMSG_ERROR)) {
1267 if ((x = xmlnode_get_tag(xmldata, TMSG_ERROR)) != NULL) 1285 if ((x = xmlnode_get_tag(xmldata, TMSG_ERROR)) != NULL)
1268 display_server_error(x); 1286 display_server_error(x);
1269 } 1287 }