comparison mcabber/src/jabglue.c @ 617:d3a8b43bf9e7

Add "/authorization" command
author Mikael Berthe <mikael@lilotux.net>
date Fri, 16 Dec 2005 13:34:13 +0100
parents a61a257ec38b
children 4e882a19077d
comparison
equal deleted inserted replaced
616:a61a257ec38b 617:d3a8b43bf9e7
408 if (utf8_jid) g_free(utf8_jid); 408 if (utf8_jid) g_free(utf8_jid);
409 409
410 jb_reset_keepalive(); 410 jb_reset_keepalive();
411 } 411 }
412 412
413 // jb_subscr_send_auth(jid)
414 // Allow jid to receive our presence updates
415 void jb_subscr_send_auth(const char *jid)
416 {
417 xmlnode x;
418 char *utf8_jid = to_utf8(jid);
419
420 x = jutil_presnew(JPACKET__SUBSCRIBED, utf8_jid, NULL);
421 jab_send(jc, x);
422 xmlnode_free(x);
423 g_free(utf8_jid);
424 }
425
426 // jb_subscr_cancel_auth(jid)
427 // Cancel jid's subscription to our presence updates
428 void jb_subscr_cancel_auth(const char *jid)
429 {
430 xmlnode x;
431 char *utf8_jid = to_utf8(jid);
432
433 x = jutil_presnew(JPACKET__UNSUBSCRIBED, utf8_jid, NULL);
434 jab_send(jc, x);
435 xmlnode_free(x);
436 g_free(utf8_jid);
437 }
438
439 // jb_subscr_request_auth(jid)
440 // Request a subscription to jid's presence updates
441 void jb_subscr_request_auth(const char *jid)
442 {
443 xmlnode x;
444 char *utf8_jid = to_utf8(jid);
445
446 x = jutil_presnew(JPACKET__SUBSCRIBE, utf8_jid, NULL);
447 jab_send(jc, x);
448 xmlnode_free(x);
449 g_free(utf8_jid);
450 }
451
413 // Note: the caller should check the jid is correct 452 // Note: the caller should check the jid is correct
414 void jb_addbuddy(const char *jid, const char *name, const char *group) 453 void jb_addbuddy(const char *jid, const char *name, const char *group)
415 { 454 {
416 xmlnode x, y, z; 455 xmlnode x, y, z;
417 char *cleanjid; 456 char *cleanjid;
443 } 482 }
444 483
445 jab_send(jc, x); 484 jab_send(jc, x);
446 xmlnode_free(x); 485 xmlnode_free(x);
447 486
448 x = jutil_presnew(JPACKET__SUBSCRIBE, cleanjid, NULL); 487 jb_subscr_request_auth(cleanjid);
449 jab_send(jc, x);
450 xmlnode_free(x);
451 488
452 roster_add_user(cleanjid, name, group, ROSTER_TYPE_USER, sub_pending); 489 roster_add_user(cleanjid, name, group, ROSTER_TYPE_USER, sub_pending);
453 g_free(cleanjid); 490 g_free(cleanjid);
454 buddylist_build(); 491 buddylist_build();
455 492
1238 } 1275 }
1239 1276
1240 static void handle_packet_s10n(jconn conn, char *type, char *from, 1277 static void handle_packet_s10n(jconn conn, char *type, char *from,
1241 xmlnode xmldata) 1278 xmlnode xmldata)
1242 { 1279 {
1243 xmlnode x;
1244 char *r; 1280 char *r;
1245 char *buf; 1281 char *buf;
1246 1282
1247 r = jidtodisp(from); 1283 r = jidtodisp(from);
1248 1284
1250 /* The sender wishes to subscribe to our presence */ 1286 /* The sender wishes to subscribe to our presence */
1251 char *msg; 1287 char *msg;
1252 int isagent; 1288 int isagent;
1253 1289
1254 isagent = (roster_gettype(r) & ROSTER_TYPE_AGENT) != 0; 1290 isagent = (roster_gettype(r) & ROSTER_TYPE_AGENT) != 0;
1255
1256 msg = xmlnode_get_tag_data(xmldata, "status"); 1291 msg = xmlnode_get_tag_data(xmldata, "status");
1257 scr_LogPrint(LPRINT_LOGNORM, "<%s> wants to subscribe " 1292
1258 "to your network presence updates", from); 1293 buf = g_strdup_printf("<%s> wants to subscribe to your presence updates",
1294 from);
1295 scr_WriteIncomingMessage(r, buf, 0, HBB_PREFIX_INFO);
1296 scr_LogPrint(LPRINT_LOGNORM, "%s", buf);
1297 g_free(buf);
1298
1259 if (msg) { 1299 if (msg) {
1260 char *msg_noutf8 = from_utf8(msg); 1300 char *msg_noutf8 = from_utf8(msg);
1261 if (msg_noutf8) { 1301 if (msg_noutf8) {
1262 buf = g_strdup_printf("<%s> said: %s", from, msg_noutf8); 1302 buf = g_strdup_printf("<%s> said: %s", from, msg_noutf8);
1263 scr_WriteIncomingMessage(r, buf, 0, HBB_PREFIX_INFO); 1303 scr_WriteIncomingMessage(r, buf, 0, HBB_PREFIX_INFO);
1268 g_free(msg_noutf8); 1308 g_free(msg_noutf8);
1269 } 1309 }
1270 } 1310 }
1271 1311
1272 // FIXME We accept everybody... 1312 // FIXME We accept everybody...
1273 x = jutil_presnew(JPACKET__SUBSCRIBED, from, 0); 1313 jb_subscr_send_auth(from);
1274 jab_send(jc, x); 1314 buf = g_strdup_printf("<%s> is allowed to receive your presence updates",
1275 xmlnode_free(x); 1315 from);
1276 buf = g_strdup_printf("<%s> has subscribed to your presence updates", from);
1277 scr_WriteIncomingMessage(r, buf, 0, HBB_PREFIX_INFO); 1316 scr_WriteIncomingMessage(r, buf, 0, HBB_PREFIX_INFO);
1317 scr_LogPrint(LPRINT_LOGNORM, "%s", buf);
1278 g_free(buf); 1318 g_free(buf);
1279 } else if (!strcmp(type, "unsubscribe")) { 1319 } else if (!strcmp(type, "unsubscribe")) {
1280 /* The sender is unsubscribing from our presence */ 1320 /* The sender is unsubscribing from our presence */
1281 x = jutil_presnew(JPACKET__UNSUBSCRIBED, from, 0); 1321 jb_subscr_cancel_auth(from);
1282 jab_send(jc, x);
1283 xmlnode_free(x);
1284 buf = g_strdup_printf("<%s> is unsubscribing from your " 1322 buf = g_strdup_printf("<%s> is unsubscribing from your "
1285 "presence updates", from); 1323 "presence updates", from);
1286 scr_WriteIncomingMessage(r, buf, 0, HBB_PREFIX_INFO); 1324 scr_WriteIncomingMessage(r, buf, 0, HBB_PREFIX_INFO);
1287 scr_LogPrint(LPRINT_LOGNORM, "%s", buf); 1325 scr_LogPrint(LPRINT_LOGNORM, "%s", buf);
1288 g_free(buf); 1326 g_free(buf);