comparison mcabber/mcabber/xmpp.c @ 1810:8c2651fc217a

Improve initial display when there is an error message Chat mode is enabled automatically and the screen is refreshed.
author Mikael Berthe <mikael@lilotux.net>
date Mon, 22 Mar 2010 21:18:29 +0100
parents d2747442918a
children e6d355e50d7a
comparison
equal deleted inserted replaced
1809:eef8c9fff727 1810:8c2651fc217a
1632 g_free(msg); 1632 g_free(msg);
1633 } 1633 }
1634 } 1634 }
1635 1635
1636 1636
1637 void xmpp_connect(void) 1637 // xmpp_connect()
1638 // Return a non-zero value if there's an obvious problem
1639 // (no JID, no password, etc.)
1640 gint xmpp_connect(void)
1638 { 1641 {
1639 const char *userjid, *password, *resource, *servername, *ssl_fpr; 1642 const char *userjid, *password, *resource, *servername, *ssl_fpr;
1640 char *dynresource = NULL; 1643 char *dynresource = NULL;
1641 char fpr[16]; 1644 char fpr[16];
1642 const char *proxy_host; 1645 const char *proxy_host;
1658 proxy_host = settings_opt_get("proxy_host"); 1661 proxy_host = settings_opt_get("proxy_host");
1659 ssl_fpr = settings_opt_get("ssl_fingerprint"); 1662 ssl_fpr = settings_opt_get("ssl_fingerprint");
1660 1663
1661 if (!userjid) { 1664 if (!userjid) {
1662 scr_LogPrint(LPRINT_LOGNORM, "Your JID has not been specified!"); 1665 scr_LogPrint(LPRINT_LOGNORM, "Your JID has not been specified!");
1663 return; 1666 return -1;
1664 } 1667 }
1665 if (!password) { 1668 if (!password) {
1666 scr_LogPrint(LPRINT_LOGNORM, "Your password has not been specified!"); 1669 scr_LogPrint(LPRINT_LOGNORM, "Your password has not been specified!");
1667 return; 1670 return -1;
1668 } 1671 }
1669 1672
1670 lconnection = lm_connection_new_with_context(NULL, main_context); 1673 lconnection = lm_connection_new_with_context(NULL, main_context);
1671 1674
1672 g_log_set_handler("LM", LM_LOG_LEVEL_ALL, lm_debug_handler, NULL); 1675 g_log_set_handler("LM", LM_LOG_LEVEL_ALL, lm_debug_handler, NULL);
1768 1771
1769 if (!lm_ssl_is_supported()) { 1772 if (!lm_ssl_is_supported()) {
1770 if (ssl || tls) { 1773 if (ssl || tls) {
1771 scr_LogPrint(LPRINT_LOGNORM, "** Error: SSL is NOT available, " 1774 scr_LogPrint(LPRINT_LOGNORM, "** Error: SSL is NOT available, "
1772 "please recompile loudmouth with SSL enabled."); 1775 "please recompile loudmouth with SSL enabled.");
1773 return; 1776 return -1;
1774 } 1777 }
1775 } 1778 }
1776 1779
1777 if (ssl && tls) { 1780 if (ssl && tls) {
1778 scr_LogPrint(LPRINT_LOGNORM, "You can only set ssl or tls, not both."); 1781 scr_LogPrint(LPRINT_LOGNORM, "You can only set ssl or tls, not both.");
1779 return; 1782 return -1;
1780 } 1783 }
1781 1784
1782 if (!port) 1785 if (!port)
1783 port = (ssl ? LM_CONNECTION_DEFAULT_PORT_SSL : LM_CONNECTION_DEFAULT_PORT); 1786 port = (ssl ? LM_CONNECTION_DEFAULT_PORT_SSL : LM_CONNECTION_DEFAULT_PORT);
1784 lm_connection_set_port(lconnection, port); 1787 lm_connection_set_port(lconnection, port);
1785 1788
1786 if (ssl_fpr && (!hex_to_fingerprint(ssl_fpr, fpr))) { 1789 if (ssl_fpr && (!hex_to_fingerprint(ssl_fpr, fpr))) {
1787 scr_LogPrint(LPRINT_LOGNORM, "** Plese set the fingerprint in the format " 1790 scr_LogPrint(LPRINT_LOGNORM, "** Please set the fingerprint in the format "
1788 "97:5C:00:3F:1D:77:45:25:E2:C5:70:EC:83:C8:87:EE"); 1791 "97:5C:00:3F:1D:77:45:25:E2:C5:70:EC:83:C8:87:EE");
1789 return; 1792 return -1;
1790 } 1793 }
1791 1794
1792 lssl = lm_ssl_new((ssl_fpr ? fpr : NULL), ssl_cb, NULL, NULL); 1795 lssl = lm_ssl_new((ssl_fpr ? fpr : NULL), ssl_cb, NULL, NULL);
1793 if (lssl) { 1796 if (lssl) {
1794 lm_ssl_use_starttls(lssl, !ssl, tls); 1797 lm_ssl_use_starttls(lssl, !ssl, tls);
1795 lm_connection_set_ssl(lconnection, lssl); 1798 lm_connection_set_ssl(lconnection, lssl);
1796 lm_ssl_unref(lssl); 1799 lm_ssl_unref(lssl);
1797 } else if (ssl || tls) { 1800 } else if (ssl || tls) {
1798 scr_LogPrint(LPRINT_LOGNORM, "** Error: Couldn't create SSL struct."); 1801 scr_LogPrint(LPRINT_LOGNORM, "** Error: Couldn't create SSL struct.");
1799 return; 1802 return -1;
1800 } 1803 }
1801 1804
1802 if (!lm_connection_open(lconnection, connection_open_cb, 1805 if (!lm_connection_open(lconnection, connection_open_cb,
1803 NULL, FALSE, &error)) { 1806 NULL, FALSE, &error)) {
1804 _try_to_reconnect(); 1807 _try_to_reconnect();
1805 scr_LogPrint(LPRINT_LOGNORM, "Failed to open: %s", error->message); 1808 scr_LogPrint(LPRINT_LOGNORM, "Failed to open: %s", error->message);
1806 g_error_free (error); 1809 g_error_free(error);
1807 } 1810 }
1811 return 0;
1808 } 1812 }
1809 1813
1810 // insert_entity_capabilities(presence_stanza) 1814 // insert_entity_capabilities(presence_stanza)
1811 // Entity Capabilities (XEP-0115) 1815 // Entity Capabilities (XEP-0115)
1812 static void insert_entity_capabilities(LmMessageNode *x, enum imstatus status) 1816 static void insert_entity_capabilities(LmMessageNode *x, enum imstatus status)