Mercurial > ~mikael > mcabber > hg
comparison mcabber/src/commands.c @ 1074:b2fc694a8228
Fix a few memory leaks after calls to parse_assigment()
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Sun, 03 Dec 2006 19:29:54 +0100 |
parents | 253e8988eb5c |
children | 5e2e647e781b |
comparison
equal
deleted
inserted
replaced
1073:253e8988eb5c | 1074:b2fc694a8228 |
---|---|
1542 } | 1542 } |
1543 | 1543 |
1544 static void do_set(char *arg) | 1544 static void do_set(char *arg) |
1545 { | 1545 { |
1546 guint assign; | 1546 guint assign; |
1547 const gchar *option, *value; | 1547 gchar *option, *value; |
1548 gchar *option_utf8; | 1548 gchar *option_utf8; |
1549 | 1549 |
1550 assign = parse_assigment(arg, &option, &value); | 1550 assign = parse_assigment(arg, &option, &value); |
1551 if (!option) { | 1551 if (!option) { |
1552 scr_LogPrint(LPRINT_NORMAL, "Set what option?"); | 1552 scr_LogPrint(LPRINT_NORMAL, "Set what option?"); |
1553 return; | 1553 return; |
1554 } | 1554 } |
1555 option_utf8 = to_utf8(option); | 1555 option_utf8 = to_utf8(option); |
1556 if (!assign) { | 1556 g_free(option); |
1557 // This is a query | 1557 if (!assign) { // This is a query |
1558 value = settings_opt_get(option_utf8); | 1558 const char *val = settings_opt_get(option_utf8); |
1559 if (value) { | 1559 if (val) |
1560 scr_LogPrint(LPRINT_NORMAL, "%s = [%s]", option_utf8, value); | 1560 scr_LogPrint(LPRINT_NORMAL, "%s = [%s]", option_utf8, val); |
1561 } else | 1561 else |
1562 scr_LogPrint(LPRINT_NORMAL, "Option %s is not set", option_utf8); | 1562 scr_LogPrint(LPRINT_NORMAL, "Option %s is not set", option_utf8); |
1563 g_free(option_utf8); | 1563 g_free(option_utf8); |
1564 return; | 1564 return; |
1565 } | 1565 } |
1566 // Update the option | 1566 // Update the option |
1567 // XXX Maybe some options should be protected when user is connected | 1567 // Maybe some options should be protected when user is connected (server, |
1568 // (server, username, etc.). And we should catch some options here, too | 1568 // username, etc.). And we should catch some options here, too |
1569 // (hide_offline_buddies for ex.) | 1569 // (hide_offline_buddies for ex.) |
1570 if (!value) { | 1570 if (!value) { |
1571 settings_del(SETTINGS_TYPE_OPTION, option_utf8); | 1571 settings_del(SETTINGS_TYPE_OPTION, option_utf8); |
1572 } else { | 1572 } else { |
1573 gchar *value_utf8 = to_utf8(value); | 1573 gchar *value_utf8 = to_utf8(value); |
1574 settings_set(SETTINGS_TYPE_OPTION, option_utf8, value_utf8); | 1574 settings_set(SETTINGS_TYPE_OPTION, option_utf8, value_utf8); |
1575 g_free(value_utf8); | 1575 g_free(value_utf8); |
1576 g_free(value); | |
1576 } | 1577 } |
1577 g_free(option_utf8); | 1578 g_free(option_utf8); |
1578 } | 1579 } |
1579 | 1580 |
1580 static void dump_alias(char *k, char *v, void *param) | 1581 static void dump_alias(char *k, char *v, void *param) |
1583 } | 1584 } |
1584 | 1585 |
1585 static void do_alias(char *arg) | 1586 static void do_alias(char *arg) |
1586 { | 1587 { |
1587 guint assign; | 1588 guint assign; |
1588 const gchar *alias, *value; | 1589 gchar *alias, *value; |
1589 | 1590 |
1590 assign = parse_assigment(arg, &alias, &value); | 1591 assign = parse_assigment(arg, &alias, &value); |
1591 if (!alias) { | 1592 if (!alias) { |
1592 settings_foreach(SETTINGS_TYPE_ALIAS, &dump_alias, NULL); | 1593 settings_foreach(SETTINGS_TYPE_ALIAS, &dump_alias, NULL); |
1593 return; | 1594 return; |
1594 } | 1595 } |
1595 if (!assign) { | 1596 if (!assign) { // This is a query |
1596 // This is a query | 1597 const char *val = settings_get(SETTINGS_TYPE_ALIAS, alias); |
1597 value = settings_get(SETTINGS_TYPE_ALIAS, alias); | 1598 // NOTE: LPRINT_NOTUTF8 here, see below why it isn't encoded... |
1598 if (value) { | 1599 if (val) |
1599 // XXX LPRINT_NOTUTF8 here, see below why it isn't encoded... | 1600 scr_LogPrint(LPRINT_NORMAL|LPRINT_NOTUTF8, "%s = %s", alias, val); |
1600 scr_LogPrint(LPRINT_NORMAL|LPRINT_NOTUTF8, "%s = %s", alias, value); | 1601 else |
1601 } else | |
1602 scr_LogPrint(LPRINT_NORMAL|LPRINT_NOTUTF8, | 1602 scr_LogPrint(LPRINT_NORMAL|LPRINT_NOTUTF8, |
1603 "Alias '%s' does not exist", alias); | 1603 "Alias '%s' does not exist", alias); |
1604 return; | 1604 goto do_alias_return; |
1605 } | 1605 } |
1606 // Check the alias does not conflict with a registered command | 1606 // Check the alias does not conflict with a registered command |
1607 if (cmd_get(alias)) { | 1607 if (cmd_get(alias)) { |
1608 scr_LogPrint(LPRINT_NORMAL|LPRINT_NOTUTF8, | 1608 scr_LogPrint(LPRINT_NORMAL|LPRINT_NOTUTF8, |
1609 "'%s' is a reserved word!", alias); | 1609 "'%s' is a reserved word!", alias); |
1610 return; | 1610 goto do_alias_return; |
1611 } | 1611 } |
1612 // Update the alias | 1612 // Update the alias |
1613 if (!value) { | 1613 if (!value) { |
1614 if (settings_get(SETTINGS_TYPE_ALIAS, alias)) { | 1614 if (settings_get(SETTINGS_TYPE_ALIAS, alias)) { |
1615 settings_del(SETTINGS_TYPE_ALIAS, alias); | 1615 settings_del(SETTINGS_TYPE_ALIAS, alias); |
1616 // Remove alias from the completion list | 1616 // Remove alias from the completion list |
1617 compl_del_category_word(COMPL_CMD, alias); | 1617 compl_del_category_word(COMPL_CMD, alias); |
1618 } | 1618 } |
1619 } else { | 1619 } else { |
1620 /* Add alias to the completion list, if not already in. | 1620 /* Add alias to the completion list, if not already in. |
1621 XXX We're not UTF8-encoding "alias" and "value" here because UTF-8 is | 1621 NOTE: We're not UTF8-encoding "alias" and "value" here because UTF-8 is |
1622 not yet supported in the UI... (and we use the values in the completion | 1622 not yet supported in the UI... (and we use the values in the completion |
1623 system) | 1623 system) |
1624 */ | 1624 */ |
1625 if (!settings_get(SETTINGS_TYPE_ALIAS, alias)) | 1625 if (!settings_get(SETTINGS_TYPE_ALIAS, alias)) |
1626 compl_add_category_word(COMPL_CMD, alias); | 1626 compl_add_category_word(COMPL_CMD, alias); |
1627 settings_set(SETTINGS_TYPE_ALIAS, alias, value); | 1627 settings_set(SETTINGS_TYPE_ALIAS, alias, value); |
1628 } | 1628 g_free(value); |
1629 } | |
1630 do_alias_return: | |
1631 g_free(alias); | |
1629 } | 1632 } |
1630 | 1633 |
1631 static void dump_bind(char *k, char *v, void *param) | 1634 static void dump_bind(char *k, char *v, void *param) |
1632 { | 1635 { |
1633 scr_LogPrint(LPRINT_NORMAL, "Key %4s is bound to: %s", k, v); | 1636 scr_LogPrint(LPRINT_NORMAL, "Key %4s is bound to: %s", k, v); |
1634 } | 1637 } |
1635 | 1638 |
1636 static void do_bind(char *arg) | 1639 static void do_bind(char *arg) |
1637 { | 1640 { |
1638 guint assign; | 1641 guint assign; |
1639 const gchar *k_code, *value; | 1642 gchar *k_code, *value; |
1640 | 1643 |
1641 assign = parse_assigment(arg, &k_code, &value); | 1644 assign = parse_assigment(arg, &k_code, &value); |
1642 if (!k_code) { | 1645 if (!k_code) { |
1643 settings_foreach(SETTINGS_TYPE_BINDING, &dump_bind, NULL); | 1646 settings_foreach(SETTINGS_TYPE_BINDING, &dump_bind, NULL); |
1644 return; | 1647 return; |
1645 } | 1648 } |
1646 if (!assign) { | 1649 if (!assign) { // This is a query |
1647 // This is a query | 1650 const char *val = settings_get(SETTINGS_TYPE_BINDING, k_code); |
1648 value = settings_get(SETTINGS_TYPE_BINDING, k_code); | 1651 if (val) |
1649 if (value) { | 1652 scr_LogPrint(LPRINT_NORMAL, "Key %s is bound to: %s", k_code, val); |
1650 scr_LogPrint(LPRINT_NORMAL, "Key %s is bound to: %s", k_code, value); | 1653 else |
1651 } else | |
1652 scr_LogPrint(LPRINT_NORMAL, "Key %s is not bound.", k_code); | 1654 scr_LogPrint(LPRINT_NORMAL, "Key %s is not bound.", k_code); |
1655 g_free(k_code); | |
1653 return; | 1656 return; |
1654 } | 1657 } |
1655 // Update the key binding | 1658 // Update the key binding |
1656 if (!value) { | 1659 if (!value) { |
1657 settings_del(SETTINGS_TYPE_BINDING, k_code); | 1660 settings_del(SETTINGS_TYPE_BINDING, k_code); |
1658 } else { | 1661 } else { |
1659 gchar *value_utf8 = to_utf8(value); | 1662 gchar *value_utf8 = to_utf8(value); |
1660 settings_set(SETTINGS_TYPE_BINDING, k_code, value_utf8); | 1663 settings_set(SETTINGS_TYPE_BINDING, k_code, value_utf8); |
1661 g_free(value_utf8); | 1664 g_free(value_utf8); |
1662 } | 1665 g_free(value); |
1666 } | |
1667 g_free(k_code); | |
1663 } | 1668 } |
1664 | 1669 |
1665 static void do_rawxml(char *arg) | 1670 static void do_rawxml(char *arg) |
1666 { | 1671 { |
1667 char **paramlst; | 1672 char **paramlst; |