1223 |
1226 |
1224 static void handle_packet_s10n(jconn conn, char *type, char *from, |
1227 static void handle_packet_s10n(jconn conn, char *type, char *from, |
1225 xmlnode xmldata) |
1228 xmlnode xmldata) |
1226 { |
1229 { |
1227 xmlnode x; |
1230 xmlnode x; |
|
1231 char *r; |
|
1232 char *buf; |
|
1233 |
|
1234 r = jidtodisp(from); |
1228 |
1235 |
1229 if (!strcmp(type, "subscribe")) { |
1236 if (!strcmp(type, "subscribe")) { |
1230 char *r; |
1237 /* The sender wishes to subscribe to our presence */ |
|
1238 char *msg; |
1231 int isagent; |
1239 int isagent; |
1232 r = jidtodisp(from); |
1240 |
1233 isagent = (roster_gettype(r) & ROSTER_TYPE_AGENT) != 0; |
1241 isagent = (roster_gettype(r) & ROSTER_TYPE_AGENT) != 0; |
1234 g_free(r); |
1242 |
|
1243 msg = xmlnode_get_tag_data(xmldata, "status"); |
1235 scr_LogPrint(LPRINT_LOGNORM, "<%s> wants to subscribe " |
1244 scr_LogPrint(LPRINT_LOGNORM, "<%s> wants to subscribe " |
1236 "to your network presence updates", from); |
1245 "to your network presence updates", from); |
1237 if (!isagent) { |
1246 if (msg) { |
1238 // FIXME we accept everybody... |
1247 char *msg_noutf8 = from_utf8(msg); |
1239 x = jutil_presnew(JPACKET__SUBSCRIBED, from, 0); |
1248 if (msg_noutf8) { |
1240 jab_send(jc, x); |
1249 buf = g_strdup_printf("<%s> said: %s", from, msg_noutf8); |
1241 xmlnode_free(x); |
1250 scr_WriteIncomingMessage(r, buf, 0, HBB_PREFIX_INFO); |
1242 } else { |
1251 msg = strchr(buf, '\n'); |
1243 x = jutil_presnew(JPACKET__SUBSCRIBED, from, 0); |
1252 if (msg) *msg = 0; |
1244 jab_send(jc, x); |
1253 scr_LogPrint(LPRINT_LOGNORM, buf); |
1245 xmlnode_free(x); |
1254 g_free(buf); |
|
1255 g_free(msg_noutf8); |
|
1256 } |
1246 } |
1257 } |
|
1258 |
|
1259 // FIXME We accept everybody... |
|
1260 x = jutil_presnew(JPACKET__SUBSCRIBED, from, 0); |
|
1261 jab_send(jc, x); |
|
1262 xmlnode_free(x); |
|
1263 buf = g_strdup_printf("<%s> has subscribed to your presence updates", from); |
|
1264 scr_WriteIncomingMessage(r, buf, 0, HBB_PREFIX_INFO); |
|
1265 g_free(buf); |
1247 } else if (!strcmp(type, "unsubscribe")) { |
1266 } else if (!strcmp(type, "unsubscribe")) { |
|
1267 /* The sender is unsubscribing from our presence */ |
1248 x = jutil_presnew(JPACKET__UNSUBSCRIBED, from, 0); |
1268 x = jutil_presnew(JPACKET__UNSUBSCRIBED, from, 0); |
1249 jab_send(jc, x); |
1269 jab_send(jc, x); |
1250 xmlnode_free(x); |
1270 xmlnode_free(x); |
1251 scr_LogPrint(LPRINT_LOGNORM, "<%s> wants to unsubscribe from " |
1271 buf = g_strdup_printf("<%s> is unsubscribing from your " |
1252 "your presence updates", from); |
1272 "presence updates", from); |
|
1273 scr_WriteIncomingMessage(r, buf, 0, HBB_PREFIX_INFO); |
|
1274 scr_LogPrint(LPRINT_LOGNORM, "%s", buf); |
|
1275 g_free(buf); |
1253 } else if (!strcmp(type, "subscribed")) { |
1276 } else if (!strcmp(type, "subscribed")) { |
1254 scr_LogPrint(LPRINT_LOGNORM, "<%s> has subscribed to your presence " |
1277 /* The sender has allowed us to receive their presence */ |
1255 "updates", from); |
1278 buf = g_strdup_printf("<%s> has allowed you to receive their " |
|
1279 "presence updates", from); |
|
1280 scr_WriteIncomingMessage(r, buf, 0, HBB_PREFIX_INFO); |
|
1281 scr_LogPrint(LPRINT_LOGNORM, "%s", buf); |
|
1282 g_free(buf); |
1256 } else if (!strcmp(type, "unsubscribed")) { |
1283 } else if (!strcmp(type, "unsubscribed")) { |
1257 scr_LogPrint(LPRINT_LOGNORM, "<%s> has unsubscribed from your presence " |
1284 /* The subscription request has been denied or a previously-granted |
1258 "updates", from); |
1285 subscription has been cancelled */ |
1259 roster_unsubscribed(from); |
1286 roster_unsubscribed(from); |
|
1287 buf = g_strdup_printf("<%s> has cancelled your subscription to " |
|
1288 "their presence updates", from); |
|
1289 scr_WriteIncomingMessage(r, buf, 0, HBB_PREFIX_INFO); |
|
1290 scr_LogPrint(LPRINT_LOGNORM, "%s", buf); |
|
1291 g_free(buf); |
1260 } else { |
1292 } else { |
1261 scr_LogPrint(LPRINT_LOGNORM, "Received (un)subscription packet from <%s>" |
1293 scr_LogPrint(LPRINT_LOGNORM, "Received unrecognized packet from <%s>, " |
1262 " (type=%s)", from, (type ? type : "")); |
1294 "type=%s", from, (type ? type : "")); |
1263 |
1295 |
1264 } |
1296 } |
|
1297 g_free(r); |
1265 } |
1298 } |
1266 |
1299 |
1267 static void packethandler(jconn conn, jpacket packet) |
1300 static void packethandler(jconn conn, jpacket packet) |
1268 { |
1301 { |
1269 char *p, *r, *s; |
1302 char *p, *r, *s; |