comparison src/account.c @ 10424:108151be77a3

[gaim-migrate @ 11676] Those 2 helper functions in xmlnode made things less readable... Lesson #456: Helper functions, while possible saving time, can hurt you in the long run when they steal your wallet. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Sun, 26 Dec 2004 18:58:36 +0000
parents 3232e1a33899
children 9903182f2aac
comparison
equal deleted inserted replaced
10423:3232e1a33899 10424:108151be77a3
1363 1363
1364 name = (const char *)key; 1364 name = (const char *)key;
1365 setting = (GaimAccountSetting *)value; 1365 setting = (GaimAccountSetting *)value;
1366 node = (xmlnode *)user_data; 1366 node = (xmlnode *)user_data;
1367 1367
1368 child = xmlnode_new("setting"); 1368 child = xmlnode_new_child(node, "setting");
1369 xmlnode_set_attrib(child, "name", name); 1369 xmlnode_set_attrib(child, "name", name);
1370 1370
1371 if (setting->type == GAIM_PREF_INT) { 1371 if (setting->type == GAIM_PREF_INT) {
1372 xmlnode_set_attrib(child, "type", "int"); 1372 xmlnode_set_attrib(child, "type", "int");
1373 snprintf(buf, sizeof(buf), "%d", setting->value.integer); 1373 snprintf(buf, sizeof(buf), "%d", setting->value.integer);
1380 else if (setting->type == GAIM_PREF_BOOLEAN) { 1380 else if (setting->type == GAIM_PREF_BOOLEAN) {
1381 xmlnode_set_attrib(child, "type", "bool"); 1381 xmlnode_set_attrib(child, "type", "bool");
1382 snprintf(buf, sizeof(buf), "%d", setting->value.bool); 1382 snprintf(buf, sizeof(buf), "%d", setting->value.bool);
1383 xmlnode_insert_data(child, buf, -1); 1383 xmlnode_insert_data(child, buf, -1);
1384 } 1384 }
1385
1386 xmlnode_insert_child(node, child);
1387 } 1385 }
1388 1386
1389 static void 1387 static void
1390 ui_setting_to_xmlnode(gpointer key, gpointer value, gpointer user_data) 1388 ui_setting_to_xmlnode(gpointer key, gpointer value, gpointer user_data)
1391 { 1389 {
1395 1393
1396 ui = (const char *)key; 1394 ui = (const char *)key;
1397 table = (GHashTable *)value; 1395 table = (GHashTable *)value;
1398 node = (xmlnode *)user_data; 1396 node = (xmlnode *)user_data;
1399 1397
1400 child = xmlnode_new("settings"); 1398 child = xmlnode_new_child(node, "settings");
1401 xmlnode_set_attrib(child, "ui", ui); 1399 xmlnode_set_attrib(child, "ui", ui);
1402 g_hash_table_foreach(table, setting_to_xmlnode, child); 1400 g_hash_table_foreach(table, setting_to_xmlnode, child);
1403
1404 xmlnode_insert_child(node, child);
1405 } 1401 }
1406 1402
1407 static xmlnode * 1403 static xmlnode *
1408 proxy_settings_to_xmlnode(GaimProxyInfo *proxy_info) 1404 proxy_settings_to_xmlnode(GaimProxyInfo *proxy_info)
1409 { 1405 {
1415 1411
1416 proxy_type = gaim_proxy_info_get_type(proxy_info); 1412 proxy_type = gaim_proxy_info_get_type(proxy_info);
1417 1413
1418 node = xmlnode_new("proxy"); 1414 node = xmlnode_new("proxy");
1419 1415
1420 child = xmlnode_new_child_with_data(node, "type", 1416 child = xmlnode_new_child(node, "type");
1417 xmlnode_insert_data(child,
1421 (proxy_type == GAIM_PROXY_USE_GLOBAL ? "global" : 1418 (proxy_type == GAIM_PROXY_USE_GLOBAL ? "global" :
1422 proxy_type == GAIM_PROXY_NONE ? "none" : 1419 proxy_type == GAIM_PROXY_NONE ? "none" :
1423 proxy_type == GAIM_PROXY_HTTP ? "http" : 1420 proxy_type == GAIM_PROXY_HTTP ? "http" :
1424 proxy_type == GAIM_PROXY_SOCKS4 ? "socks4" : 1421 proxy_type == GAIM_PROXY_SOCKS4 ? "socks4" :
1425 proxy_type == GAIM_PROXY_SOCKS5 ? "socks5" : 1422 proxy_type == GAIM_PROXY_SOCKS5 ? "socks5" :
1428 if (proxy_type != GAIM_PROXY_USE_GLOBAL && 1425 if (proxy_type != GAIM_PROXY_USE_GLOBAL &&
1429 proxy_type != GAIM_PROXY_NONE && 1426 proxy_type != GAIM_PROXY_NONE &&
1430 proxy_type != GAIM_PROXY_USE_ENVVAR) 1427 proxy_type != GAIM_PROXY_USE_ENVVAR)
1431 { 1428 {
1432 if ((value = gaim_proxy_info_get_host(proxy_info)) != NULL) 1429 if ((value = gaim_proxy_info_get_host(proxy_info)) != NULL)
1433 child = xmlnode_new_child_with_data(node, "host", value, -1); 1430 {
1431 child = xmlnode_new_child(node, "host");
1432 xmlnode_insert_data(child, value, -1);
1433 }
1434 1434
1435 if ((int_value = gaim_proxy_info_get_port(proxy_info)) != 0) 1435 if ((int_value = gaim_proxy_info_get_port(proxy_info)) != 0)
1436 { 1436 {
1437 snprintf(buf, sizeof(buf), "%d", int_value); 1437 snprintf(buf, sizeof(buf), "%d", int_value);
1438 child = xmlnode_new_child_with_data(node, "port", buf, -1); 1438 child = xmlnode_new_child(node, "port");
1439 xmlnode_insert_data(child, buf, -1);
1439 } 1440 }
1440 1441
1441 if ((value = gaim_proxy_info_get_username(proxy_info)) != NULL) 1442 if ((value = gaim_proxy_info_get_username(proxy_info)) != NULL)
1442 child = xmlnode_new_child_with_data(node, "username", value, -1); 1443 {
1444 child = xmlnode_new_child(node, "username");
1445 xmlnode_insert_data(child, value, -1);
1446 }
1443 1447
1444 if ((value = gaim_proxy_info_get_password(proxy_info)) != NULL) 1448 if ((value = gaim_proxy_info_get_password(proxy_info)) != NULL)
1445 child = xmlnode_new_child_with_data(node, "password", value, -1); 1449 {
1450 child = xmlnode_new_child(node, "password");
1451 xmlnode_insert_data(child, value, -1);
1452 }
1446 } 1453 }
1447 1454
1448 return node; 1455 return node;
1449 } 1456 }
1450 1457
1455 const char *tmp; 1462 const char *tmp;
1456 GaimProxyInfo *proxy_info; 1463 GaimProxyInfo *proxy_info;
1457 1464
1458 node = xmlnode_new("account"); 1465 node = xmlnode_new("account");
1459 1466
1460 child = xmlnode_new("protocol"); 1467 child = xmlnode_new_child(node, "protocol");
1461 xmlnode_insert_data(child, gaim_account_get_protocol_id(account), -1); 1468 xmlnode_insert_data(child, gaim_account_get_protocol_id(account), -1);
1462 xmlnode_insert_child(node, child); 1469
1463 1470 child = xmlnode_new_child(node, "name");
1464 child = xmlnode_new("name");
1465 xmlnode_insert_data(child, gaim_account_get_username(account), -1); 1471 xmlnode_insert_data(child, gaim_account_get_username(account), -1);
1466 xmlnode_insert_child(node, child);
1467 1472
1468 if (gaim_account_get_remember_password(account) && 1473 if (gaim_account_get_remember_password(account) &&
1469 ((tmp = gaim_account_get_password(account)) != NULL)) 1474 ((tmp = gaim_account_get_password(account)) != NULL))
1470 { 1475 {
1471 child = xmlnode_new("password"); 1476 child = xmlnode_new_child(node, "password");
1472 xmlnode_insert_data(child, tmp, -1); 1477 xmlnode_insert_data(child, tmp, -1);
1473 xmlnode_insert_child(node, child);
1474 } 1478 }
1475 1479
1476 if ((tmp = gaim_account_get_alias(account)) != NULL) 1480 if ((tmp = gaim_account_get_alias(account)) != NULL)
1477 { 1481 {
1478 child = xmlnode_new("alias"); 1482 child = xmlnode_new_child(node, "alias");
1479 xmlnode_insert_data(child, tmp, -1); 1483 xmlnode_insert_data(child, tmp, -1);
1480 xmlnode_insert_child(node, child);
1481 } 1484 }
1482 1485
1483 if ((tmp = gaim_account_get_user_info(account)) != NULL) 1486 if ((tmp = gaim_account_get_user_info(account)) != NULL)
1484 { 1487 {
1485 /* TODO: Do we need to call gaim_str_strip_cr(tmp) here? */ 1488 /* TODO: Do we need to call gaim_str_strip_cr(tmp) here? */
1486 child = xmlnode_new("userinfo"); 1489 child = xmlnode_new_child(node, "userinfo");
1487 xmlnode_insert_data(child, tmp, -1); 1490 xmlnode_insert_data(child, tmp, -1);
1488 xmlnode_insert_child(node, child);
1489 } 1491 }
1490 1492
1491 if ((tmp = gaim_account_get_buddy_icon(account)) != NULL) 1493 if ((tmp = gaim_account_get_buddy_icon(account)) != NULL)
1492 { 1494 {
1493 child = xmlnode_new("buddyicon"); 1495 child = xmlnode_new_child(node, "buddyicon");
1494 xmlnode_insert_data(child, tmp, -1); 1496 xmlnode_insert_data(child, tmp, -1);
1495 xmlnode_insert_child(node, child); 1497 }
1496 } 1498
1497 1499 child = xmlnode_new_child(node, "settings");
1498 child = xmlnode_new("settings");
1499 g_hash_table_foreach(account->settings, setting_to_xmlnode, child); 1500 g_hash_table_foreach(account->settings, setting_to_xmlnode, child);
1500 xmlnode_insert_child(node, child);
1501 1501
1502 g_hash_table_foreach(account->ui_settings, ui_setting_to_xmlnode, node); 1502 g_hash_table_foreach(account->ui_settings, ui_setting_to_xmlnode, node);
1503 1503
1504 if ((proxy_info = gaim_account_get_proxy_info(account)) != NULL) 1504 if ((proxy_info = gaim_account_get_proxy_info(account)) != NULL)
1505 { 1505 {