libpurple/protocols/silc/silc.c

changeset 41467
5e0e6387ad84
parent 41396
2ef3d6eeffb3
child 41679
ddd97cdcbefc
equal deleted inserted replaced
41466:557aad2bc415 41467:5e0e6387ad84
939 SILC_ATTRIBUTE_TIMEZONE, 939 SILC_ATTRIBUTE_TIMEZONE,
940 (void *)val, strlen(val)); 940 (void *)val, strlen(val));
941 } 941 }
942 942
943 static void 943 static void
944 silcpurple_attrs(PurpleProtocolAction *action) 944 silcpurple_attrs(G_GNUC_UNUSED GSimpleAction *action,
945 { 945 GVariant *parameter,
946 PurpleConnection *gc = action->connection; 946 G_GNUC_UNUSED gpointer data)
947 SilcPurple sg = purple_connection_get_protocol_data(gc); 947 {
948 SilcClient client = sg->client; 948 const gchar *account_id = NULL;
949 SilcClientConnection conn = sg->conn; 949 PurpleAccountManager *manager = NULL;
950 PurpleAccount *account = NULL;
951 PurpleConnection *gc = NULL;
952 SilcPurple sg = NULL;
953 SilcClient client = NULL;
954 SilcClientConnection conn = NULL;
950 PurpleRequestFields *fields; 955 PurpleRequestFields *fields;
951 PurpleRequestFieldGroup *g; 956 PurpleRequestFieldGroup *g;
952 PurpleRequestField *f; 957 PurpleRequestField *f;
953 SilcHashTable attrs; 958 SilcHashTable attrs;
954 SilcAttributePayload attr; 959 SilcAttributePayload attr;
961 #ifdef HAVE_SYS_UTSNAME_H 966 #ifdef HAVE_SYS_UTSNAME_H
962 gboolean device = TRUE; 967 gboolean device = TRUE;
963 #endif 968 #endif
964 char status[1024], tz[16]; 969 char status[1024], tz[16];
965 970
971 if(!g_variant_is_of_type(parameter, G_VARIANT_TYPE_STRING)) {
972 g_critical("SILC attrs action parameter is of incorrect type %s",
973 g_variant_get_type_string(parameter));
974 }
975
976 account_id = g_variant_get_string(parameter, NULL);
977 manager = purple_account_manager_get_default();
978 account = purple_account_manager_find_by_id(manager, account_id);
979 gc = purple_account_get_connection(account);
980
966 sg = purple_connection_get_protocol_data(gc); 981 sg = purple_connection_get_protocol_data(gc);
967 if (!sg) 982 if (!sg)
968 return; 983 return;
984
985 client = sg->client;
986 conn = sg->conn;
969 987
970 memset(status, 0, sizeof(status)); 988 memset(status, 0, sizeof(status));
971 989
972 attrs = silc_client_attributes_get(client, conn); 990 attrs = silc_client_attributes_get(client, conn);
973 if (attrs) { 991 if (attrs) {
1098 _("Cancel"), G_CALLBACK(silcpurple_attrs_cancel), 1116 _("Cancel"), G_CALLBACK(silcpurple_attrs_cancel),
1099 purple_request_cpar_from_connection(gc), gc); 1117 purple_request_cpar_from_connection(gc), gc);
1100 } 1118 }
1101 1119
1102 static void 1120 static void
1103 silcpurple_detach(PurpleProtocolAction *action) 1121 silcpurple_detach(G_GNUC_UNUSED GSimpleAction *action,
1104 { 1122 GVariant *parameter,
1105 PurpleConnection *gc = action->connection; 1123 G_GNUC_UNUSED gpointer data)
1106 SilcPurple sg; 1124 {
1107 1125 const gchar *account_id = NULL;
1108 if (!gc) 1126 PurpleAccountManager *manager = NULL;
1127 PurpleAccount *account = NULL;
1128 PurpleConnection *connection = NULL;
1129 SilcPurple sg = NULL;
1130
1131 if(!g_variant_is_of_type(parameter, G_VARIANT_TYPE_STRING)) {
1132 g_critical("SILC detach action parameter is of incorrect type %s",
1133 g_variant_get_type_string(parameter));
1134 }
1135
1136 account_id = g_variant_get_string(parameter, NULL);
1137 manager = purple_account_manager_get_default();
1138 account = purple_account_manager_find_by_id(manager, account_id);
1139 connection = purple_account_get_connection(account);
1140 if (!connection) {
1109 return; 1141 return;
1110 sg = purple_connection_get_protocol_data(gc); 1142 }
1111 if (!sg) 1143
1144 sg = purple_connection_get_protocol_data(connection);
1145 if (!sg) {
1112 return; 1146 return;
1147 }
1113 1148
1114 /* Call DETACH */ 1149 /* Call DETACH */
1115 silc_client_command_call(sg->client, sg->conn, "DETACH"); 1150 silc_client_command_call(sg->client, sg->conn, "DETACH");
1116 sg->detaching = TRUE; 1151 sg->detaching = TRUE;
1117 } 1152 }
1118 1153
1119 static void 1154 static void
1120 silcpurple_view_motd(PurpleProtocolAction *action) 1155 silcpurple_view_motd(G_GNUC_UNUSED GSimpleAction *action,
1121 { 1156 GVariant *parameter,
1122 PurpleConnection *gc = action->connection; 1157 G_GNUC_UNUSED gpointer data)
1123 SilcPurple sg; 1158 {
1159 const gchar *account_id = NULL;
1160 PurpleAccountManager *manager = NULL;
1161 PurpleAccount *account = NULL;
1162 PurpleConnection *connection = NULL;
1163 SilcPurple sg = NULL;
1124 char *tmp; 1164 char *tmp;
1125 1165
1126 if (!gc) 1166 if(!g_variant_is_of_type(parameter, G_VARIANT_TYPE_STRING)) {
1167 g_critical("SILC view MOTD action parameter is of incorrect type %s",
1168 g_variant_get_type_string(parameter));
1169 }
1170
1171 account_id = g_variant_get_string(parameter, NULL);
1172 manager = purple_account_manager_get_default();
1173 account = purple_account_manager_find_by_id(manager, account_id);
1174 connection = purple_account_get_connection(account);
1175 if (!connection) {
1127 return; 1176 return;
1128 sg = purple_connection_get_protocol_data(gc); 1177 }
1129 if (!sg) 1178
1179 sg = purple_connection_get_protocol_data(connection);
1180 if (!sg) {
1130 return; 1181 return;
1182 }
1131 1183
1132 if (!sg->motd) { 1184 if (!sg->motd) {
1133 purple_notify_error(gc, _("Message of the Day"), _("No Message " 1185 purple_notify_error(connection, _("Message of the Day"), _("No Message "
1134 "of the Day available"), _("There is no Message of the " 1186 "of the Day available"), _("There is no Message of the "
1135 "Day associated with this connection"), 1187 "Day associated with this connection"),
1136 purple_request_cpar_from_connection(gc)); 1188 purple_request_cpar_from_connection(connection));
1137 return; 1189 return;
1138 } 1190 }
1139 1191
1140 tmp = g_markup_escape_text(sg->motd, -1); 1192 tmp = g_markup_escape_text(sg->motd, -1);
1141 purple_notify_formatted(gc, NULL, _("Message of the Day"), NULL, 1193 purple_notify_formatted(connection, NULL, _("Message of the Day"), NULL,
1142 tmp, NULL, NULL); 1194 tmp, NULL, NULL);
1143 g_free(tmp); 1195 g_free(tmp);
1144 } 1196 }
1145 1197
1146 static void 1198 static void
1241 silc_pkcs_public_key_free(public_key); 1293 silc_pkcs_public_key_free(public_key);
1242 silc_free(identifier); 1294 silc_free(identifier);
1243 } 1295 }
1244 1296
1245 static void 1297 static void
1246 silcpurple_create_keypair(PurpleProtocolAction *action) 1298 silcpurple_create_keypair(G_GNUC_UNUSED GSimpleAction *action,
1247 { 1299 GVariant *parameter,
1248 PurpleConnection *gc = action->connection; 1300 G_GNUC_UNUSED gpointer data)
1249 SilcPurple sg = purple_connection_get_protocol_data(gc); 1301 {
1302 const gchar *account_id = NULL;
1303 PurpleAccountManager *manager = NULL;
1304 PurpleAccount *account = NULL;
1305 PurpleConnection *connection = NULL;
1250 PurpleRequestFields *fields; 1306 PurpleRequestFields *fields;
1251 PurpleRequestFieldGroup *g; 1307 PurpleRequestFieldGroup *g;
1252 PurpleRequestField *f; 1308 PurpleRequestField *f;
1253 const char *username, *realname; 1309 const char *username, *realname;
1254 char *hostname, **u; 1310 char *hostname, **u;
1255 char tmp[256], pkd[256], pkd2[256], prd[256], prd2[256]; 1311 char tmp[256], pkd[256], pkd2[256], prd[256], prd2[256];
1256 1312
1257 username = purple_account_get_username(sg->account); 1313 if(!g_variant_is_of_type(parameter, G_VARIANT_TYPE_STRING)) {
1314 g_critical("SILC create keypair action parameter is of incorrect type %s",
1315 g_variant_get_type_string(parameter));
1316 }
1317
1318 account_id = g_variant_get_string(parameter, NULL);
1319 manager = purple_account_manager_get_default();
1320 account = purple_account_manager_find_by_id(manager, account_id);
1321 connection = purple_account_get_connection(account);
1322
1323 username = purple_account_get_username(account);
1258 u = g_strsplit(username, "@", 2); 1324 u = g_strsplit(username, "@", 2);
1259 username = u[0]; 1325 username = u[0];
1260 realname = purple_account_get_user_info(sg->account); 1326 realname = purple_account_get_user_info(account);
1261 hostname = silc_net_localhost(); 1327 hostname = silc_net_localhost();
1262 g_snprintf(tmp, sizeof(tmp), "%s@%s", username, hostname); 1328 g_snprintf(tmp, sizeof(tmp), "%s@%s", username, hostname);
1263 1329
1264 g_snprintf(pkd2, sizeof(pkd2), "%s" G_DIR_SEPARATOR_S"public_key.pub", silcpurple_silcdir()); 1330 g_snprintf(pkd2, sizeof(pkd2), "%s" G_DIR_SEPARATOR_S"public_key.pub", silcpurple_silcdir());
1265 g_snprintf(prd2, sizeof(prd2), "%s" G_DIR_SEPARATOR_S"private_key.prv", silcpurple_silcdir()); 1331 g_snprintf(prd2, sizeof(prd2), "%s" G_DIR_SEPARATOR_S"private_key.prv", silcpurple_silcdir());
1266 g_snprintf(pkd, sizeof(pkd) - 1, "%s", 1332 g_snprintf(pkd, sizeof(pkd) - 1, "%s",
1267 purple_account_get_string(purple_connection_get_account(gc), "public-key", pkd2)); 1333 purple_account_get_string(account, "public-key", pkd2));
1268 g_snprintf(prd, sizeof(prd) - 1, "%s", 1334 g_snprintf(prd, sizeof(prd) - 1, "%s",
1269 purple_account_get_string(purple_connection_get_account(gc), "private-key", prd2)); 1335 purple_account_get_string(account, "private-key", prd2));
1270 1336
1271 fields = purple_request_fields_new(); 1337 fields = purple_request_fields_new();
1272 1338
1273 g = purple_request_field_group_new(NULL); 1339 g = purple_request_field_group_new(NULL);
1274 f = purple_request_field_string_new("key", _("Key length"), "2048", FALSE); 1340 f = purple_request_field_string_new("key", _("Key length"), "2048", FALSE);
1301 f = purple_request_field_string_new("pass2", _("Passphrase (retype)"), "", FALSE); 1367 f = purple_request_field_string_new("pass2", _("Passphrase (retype)"), "", FALSE);
1302 purple_request_field_string_set_masked(f, TRUE); 1368 purple_request_field_string_set_masked(f, TRUE);
1303 purple_request_field_group_add_field(g, f); 1369 purple_request_field_group_add_field(g, f);
1304 purple_request_fields_add_group(fields, g); 1370 purple_request_fields_add_group(fields, g);
1305 1371
1306 purple_request_fields(gc, _("Create New SILC Key Pair"), 1372 purple_request_fields(connection, _("Create New SILC Key Pair"),
1307 _("Create New SILC Key Pair"), NULL, fields, 1373 _("Create New SILC Key Pair"), NULL, fields,
1308 _("Generate Key Pair"), G_CALLBACK(silcpurple_create_keypair_cb), 1374 _("Generate Key Pair"), G_CALLBACK(silcpurple_create_keypair_cb),
1309 _("Cancel"), G_CALLBACK(silcpurple_create_keypair_cancel), 1375 _("Cancel"), G_CALLBACK(silcpurple_create_keypair_cancel),
1310 purple_request_cpar_from_connection(gc), gc); 1376 purple_request_cpar_from_connection(connection), connection);
1311 1377
1312 g_strfreev(u); 1378 g_strfreev(u);
1313 silc_free(hostname); 1379 silc_free(hostname);
1314 } 1380 }
1315 1381
1316 static void 1382 static void
1317 silcpurple_change_pass(PurpleProtocolAction *action) 1383 silcpurple_change_pass(G_GNUC_UNUSED GSimpleAction *action,
1318 { 1384 GVariant *parameter,
1319 PurpleConnection *gc = action->connection; 1385 G_GNUC_UNUSED gpointer data)
1320 purple_account_request_change_password(purple_connection_get_account(gc)); 1386 {
1387 const gchar *account_id = NULL;
1388 PurpleAccountManager *manager = NULL;
1389 PurpleAccount *account = NULL;
1390
1391 if(!g_variant_is_of_type(parameter, G_VARIANT_TYPE_STRING)) {
1392 g_critical("SILC change password action parameter is of incorrect type %s",
1393 g_variant_get_type_string(parameter));
1394 }
1395
1396 account_id = g_variant_get_string(parameter, NULL);
1397 manager = purple_account_manager_get_default();
1398 account = purple_account_manager_find_by_id(manager, account_id);
1399
1400 purple_account_request_change_password(account);
1321 } 1401 }
1322 1402
1323 static void 1403 static void
1324 silcpurple_change_passwd(PurpleProtocolServer *protocol_server, PurpleConnection *gc, const char *old, const char *new) 1404 silcpurple_change_passwd(PurpleProtocolServer *protocol_server, PurpleConnection *gc, const char *old, const char *new)
1325 { 1405 {
1329 "private-key", 1409 "private-key",
1330 prd), old ? old : "", new ? new : ""); 1410 prd), old ? old : "", new ? new : "");
1331 } 1411 }
1332 1412
1333 static void 1413 static void
1334 silcpurple_show_set_info(PurpleProtocolAction *action) 1414 silcpurple_show_set_info(G_GNUC_UNUSED GSimpleAction *action,
1335 { 1415 GVariant *parameter,
1336 PurpleConnection *gc = action->connection; 1416 G_GNUC_UNUSED gpointer data)
1337 purple_account_request_change_user_info(purple_connection_get_account(gc)); 1417 {
1418 const gchar *account_id = NULL;
1419 PurpleAccountManager *manager = NULL;
1420 PurpleAccount *account = NULL;
1421
1422 if(!g_variant_is_of_type(parameter, G_VARIANT_TYPE_STRING)) {
1423 g_critical("SILC change password action parameter is of incorrect type %s",
1424 g_variant_get_type_string(parameter));
1425 }
1426
1427 account_id = g_variant_get_string(parameter, NULL);
1428 manager = purple_account_manager_get_default();
1429 account = purple_account_manager_find_by_id(manager, account_id);
1430
1431 purple_account_request_change_user_info(account);
1338 } 1432 }
1339 1433
1340 static void 1434 static void
1341 silcpurple_set_info(PurpleProtocolServer *protocol_server, PurpleConnection *gc, const char *text) 1435 silcpurple_set_info(PurpleProtocolServer *protocol_server, PurpleConnection *gc, const char *text)
1342 { 1436 {
1343 } 1437 }
1344 1438
1345 static GList * 1439 static const gchar *
1346 silcpurple_get_actions(PurpleProtocolClient *client, PurpleConnection *gc) 1440 silcpurple_protocol_actions_get_prefix(PurpleProtocolActions *actions) {
1347 { 1441 return "prpl-silc";
1348 GList *list = NULL; 1442 }
1349 PurpleProtocolAction *act; 1443
1350 1444 static GActionGroup *
1351 act = purple_protocol_action_new(_("Online Status"), 1445 silcpurple_protocol_actions_get_action_group(PurpleProtocolActions *actions,
1352 silcpurple_attrs); 1446 PurpleConnection *connection)
1353 list = g_list_append(list, act); 1447 {
1354 1448 GSimpleActionGroup *group = NULL;
1355 act = purple_protocol_action_new(_("Detach From Server"), 1449 GActionEntry entries[] = {
1356 silcpurple_detach); 1450 {
1357 list = g_list_append(list, act); 1451 .name = "attrs",
1358 1452 .activate = silcpurple_attrs,
1359 act = purple_protocol_action_new(_("View Message of the Day"), 1453 .parameter_type = "s",
1360 silcpurple_view_motd); 1454 },
1361 list = g_list_append(list, act); 1455 {
1362 1456 .name = "detach",
1363 act = purple_protocol_action_new(_("Create SILC Key Pair..."), 1457 .activate = silcpurple_detach,
1364 silcpurple_create_keypair); 1458 .parameter_type = "s",
1365 list = g_list_append(list, act); 1459 },
1366 1460 {
1367 act = purple_protocol_action_new(_("Change Password..."), 1461 .name = "view-motd",
1368 silcpurple_change_pass); 1462 .activate = silcpurple_view_motd,
1369 list = g_list_append(list, act); 1463 .parameter_type = "s",
1370 1464 },
1371 act = purple_protocol_action_new(_("Set User Info..."), 1465 {
1372 silcpurple_show_set_info); 1466 .name = "create-keypair",
1373 list = g_list_append(list, act); 1467 .activate = silcpurple_create_keypair,
1374 1468 .parameter_type = "s",
1375 return list; 1469 },
1470 {
1471 .name = "change-password",
1472 .activate = silcpurple_change_pass,
1473 .parameter_type = "s",
1474 },
1475 {
1476 .name = "set-user-info",
1477 .activate = silcpurple_show_set_info,
1478 .parameter_type = "s",
1479 },
1480 };
1481 gsize nentries = G_N_ELEMENTS(entries);
1482
1483 group = g_simple_action_group_new();
1484 g_action_map_add_action_entries(G_ACTION_MAP(group), entries, nentries,
1485 connection);
1486
1487 return G_ACTION_GROUP(group);
1488 }
1489
1490 static GMenu *
1491 silcpurple_protocol_actions_get_menu(PurpleProtocolActions *actions)
1492 {
1493 GMenu *menu = NULL;
1494 GMenuItem *item = NULL;
1495
1496 menu = g_menu_new();
1497
1498 item = g_menu_item_new(_("Online Status"), "prpl-silc.attrs");
1499 g_menu_item_set_attribute(item, PURPLE_MENU_ATTRIBUTE_DYNAMIC_TARGET, "s",
1500 "account");
1501 g_menu_append_item(menu, item);
1502 g_object_unref(item);
1503
1504 item = g_menu_item_new(_("Detach From Server"), "prpl-silc.detach");
1505 g_menu_item_set_attribute(item, PURPLE_MENU_ATTRIBUTE_DYNAMIC_TARGET, "s",
1506 "account");
1507 g_menu_append_item(menu, item);
1508 g_object_unref(item);
1509
1510 item = g_menu_item_new(_("View Message of the Day"), "prpl-silc.view-motd");
1511 g_menu_item_set_attribute(item, PURPLE_MENU_ATTRIBUTE_DYNAMIC_TARGET, "s",
1512 "account");
1513 g_menu_append_item(menu, item);
1514 g_object_unref(item);
1515
1516 item = g_menu_item_new(_("Create SILC Key Pair..."),
1517 "prpl-silc.create-keypair");
1518 g_menu_item_set_attribute(item, PURPLE_MENU_ATTRIBUTE_DYNAMIC_TARGET, "s",
1519 "account");
1520 g_menu_append_item(menu, item);
1521 g_object_unref(item);
1522
1523 item = g_menu_item_new(_("Change Password..."),
1524 "prpl-silc.change-password");
1525 g_menu_item_set_attribute(item, PURPLE_MENU_ATTRIBUTE_DYNAMIC_TARGET, "s",
1526 "account");
1527 g_menu_append_item(menu, item);
1528 g_object_unref(item);
1529
1530 item = g_menu_item_new(_("Set User Info..."), "prpl-silc.set-user-info");
1531 g_menu_item_set_attribute(item, PURPLE_MENU_ATTRIBUTE_DYNAMIC_TARGET, "s",
1532 "account");
1533 g_menu_append_item(menu, item);
1534 g_object_unref(item);
1535
1536 return menu;
1376 } 1537 }
1377 1538
1378 1539
1379 /******************************* IM Routines *********************************/ 1540 /******************************* IM Routines *********************************/
1380 1541
2262 silcpurple_protocol_class_finalize(G_GNUC_UNUSED SilcProtocolClass *klass) 2423 silcpurple_protocol_class_finalize(G_GNUC_UNUSED SilcProtocolClass *klass)
2263 { 2424 {
2264 } 2425 }
2265 2426
2266 static void 2427 static void
2428 silcpurple_protocol_actions_iface_init(PurpleProtocolActionsInterface *iface)
2429 {
2430 iface->get_prefix = silcpurple_protocol_actions_get_prefix;
2431 iface->get_action_group = silcpurple_protocol_actions_get_action_group;
2432 iface->get_menu = silcpurple_protocol_actions_get_menu;
2433 }
2434
2435 static void
2267 silcpurple_protocol_client_iface_init(PurpleProtocolClientInterface *client_iface) 2436 silcpurple_protocol_client_iface_init(PurpleProtocolClientInterface *client_iface)
2268 { 2437 {
2269 client_iface->get_actions = silcpurple_get_actions;
2270 client_iface->status_text = silcpurple_status_text; 2438 client_iface->status_text = silcpurple_status_text;
2271 client_iface->tooltip_text = silcpurple_tooltip_text; 2439 client_iface->tooltip_text = silcpurple_tooltip_text;
2272 client_iface->blist_node_menu = silcpurple_blist_node_menu; 2440 client_iface->blist_node_menu = silcpurple_blist_node_menu;
2273 } 2441 }
2274 2442
2319 xfer_iface->new_xfer = silcpurple_ftp_new_xfer; 2487 xfer_iface->new_xfer = silcpurple_ftp_new_xfer;
2320 } 2488 }
2321 2489
2322 G_DEFINE_DYNAMIC_TYPE_EXTENDED( 2490 G_DEFINE_DYNAMIC_TYPE_EXTENDED(
2323 SilcProtocol, silcpurple_protocol, PURPLE_TYPE_PROTOCOL, 0, 2491 SilcProtocol, silcpurple_protocol, PURPLE_TYPE_PROTOCOL, 0,
2492
2493 G_IMPLEMENT_INTERFACE_DYNAMIC(PURPLE_TYPE_PROTOCOL_ACTIONS,
2494 silcpurple_protocol_actions_iface_init)
2324 2495
2325 G_IMPLEMENT_INTERFACE_DYNAMIC(PURPLE_TYPE_PROTOCOL_CLIENT, 2496 G_IMPLEMENT_INTERFACE_DYNAMIC(PURPLE_TYPE_PROTOCOL_CLIENT,
2326 silcpurple_protocol_client_iface_init) 2497 silcpurple_protocol_client_iface_init)
2327 2498
2328 G_IMPLEMENT_INTERFACE_DYNAMIC(PURPLE_TYPE_PROTOCOL_SERVER, 2499 G_IMPLEMENT_INTERFACE_DYNAMIC(PURPLE_TYPE_PROTOCOL_SERVER,

mercurial