comparison mcabber/src/jabglue.c @ 749:6c633adaae10

Use events system for subscription requests
author Mikael Berthe <mikael@lilotux.net>
date Mon, 13 Mar 2006 19:20:03 +0100
parents 413e95f3051a
children 4a7271e69694
comparison
equal deleted inserted replaced
748:53a000411587 749:6c633adaae10
1419 gotmessage(type, from, body, enc, timestamp); 1419 gotmessage(type, from, body, enc, timestamp);
1420 if (tmp) 1420 if (tmp)
1421 g_free(tmp); 1421 g_free(tmp);
1422 } 1422 }
1423 1423
1424 static void evscallback_subcription(eviqs *evp, guint evcontext)
1425 {
1426 char *barejid;
1427 char *buf;
1428
1429 if (evcontext == EVS_CONTEXT_TIMEOUT) {
1430 scr_LogPrint(LPRINT_LOGNORM, "Event %s timed out, cancelled.",
1431 evp->id);
1432 return;
1433 }
1434 if (evcontext == EVS_CONTEXT_CANCEL) {
1435 scr_LogPrint(LPRINT_LOGNORM, "Event %s cancelled.", evp->id);
1436 return;
1437 }
1438 if (!(evcontext & EVS_CONTEXT_USER))
1439 return;
1440
1441 // Sanity check
1442 if (!evp->data) {
1443 // Shouldn't happen, data should be set to the barejid.
1444 scr_LogPrint(LPRINT_LOGNORM, "Error in evs callback.");
1445 return;
1446 }
1447
1448 // Ok, let's work now.
1449 // evcontext: 0, 1 == reject, accept
1450
1451 barejid = evp->data;
1452
1453 if (evcontext & ~EVS_CONTEXT_USER) {
1454 // Accept subscription request
1455 jb_subscr_send_auth(barejid);
1456 buf = g_strdup_printf("<%s> is allowed to receive your presence updates",
1457 barejid);
1458 } else {
1459 // Reject subscription request
1460 jb_subscr_cancel_auth(barejid);
1461 buf = g_strdup_printf("<%s> won't receive your presence updates", barejid);
1462 }
1463 scr_WriteIncomingMessage(barejid, buf, 0, HBB_PREFIX_INFO);
1464 scr_LogPrint(LPRINT_LOGNORM, "%s", buf);
1465 g_free(buf);
1466 }
1467
1424 static void handle_packet_s10n(jconn conn, char *type, char *from, 1468 static void handle_packet_s10n(jconn conn, char *type, char *from,
1425 xmlnode xmldata) 1469 xmlnode xmldata)
1426 { 1470 {
1427 char *r; 1471 char *r;
1428 char *buf; 1472 char *buf;
1431 1475
1432 if (!strcmp(type, "subscribe")) { 1476 if (!strcmp(type, "subscribe")) {
1433 /* The sender wishes to subscribe to our presence */ 1477 /* The sender wishes to subscribe to our presence */
1434 char *msg; 1478 char *msg;
1435 int isagent; 1479 int isagent;
1480 eviqs *evn;
1436 1481
1437 isagent = (roster_gettype(r) & ROSTER_TYPE_AGENT) != 0; 1482 isagent = (roster_gettype(r) & ROSTER_TYPE_AGENT) != 0;
1438 msg = xmlnode_get_tag_data(xmldata, "status"); 1483 msg = xmlnode_get_tag_data(xmldata, "status");
1439 1484
1440 buf = g_strdup_printf("<%s> wants to subscribe to your presence updates", 1485 buf = g_strdup_printf("<%s> wants to subscribe to your presence updates",
1453 g_free(buf); 1498 g_free(buf);
1454 g_free(msg_noutf8); 1499 g_free(msg_noutf8);
1455 } 1500 }
1456 } 1501 }
1457 1502
1458 // FIXME We accept everybody... 1503 // Create a new event item
1459 jb_subscr_send_auth(from); 1504 evn = evs_new(EVS_TYPE_SUBSCRIPTION, EVS_MAX_TIMEOUT);
1460 buf = g_strdup_printf("<%s> is allowed to receive your presence updates", 1505 evn->callback = &evscallback_subcription;
1461 from); 1506 evn->data = g_strdup(r);
1507
1508 buf = g_strdup_printf("Please use /event %s accept|reject", evn->id);
1462 scr_WriteIncomingMessage(r, buf, 0, HBB_PREFIX_INFO); 1509 scr_WriteIncomingMessage(r, buf, 0, HBB_PREFIX_INFO);
1463 scr_LogPrint(LPRINT_LOGNORM, "%s", buf); 1510 scr_LogPrint(LPRINT_LOGNORM, "%s", buf);
1464 g_free(buf); 1511 g_free(buf);
1465 } else if (!strcmp(type, "unsubscribe")) { 1512 } else if (!strcmp(type, "unsubscribe")) {
1466 /* The sender is unsubscribing from our presence */ 1513 /* The sender is unsubscribing from our presence */