Mercurial > hg > nnchat
diff nnchat.c @ 354:c01e42fc9adb
More work on SOCKS proxy support, should work now.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 23 Jun 2011 08:26:48 +0300 |
parents | 83ae825bb8c1 |
children | 8f3c102db611 |
line wrap: on
line diff
--- a/nnchat.c Thu Jun 23 06:31:34 2011 +0300 +++ b/nnchat.c Thu Jun 23 08:26:48 2011 +0300 @@ -569,7 +569,7 @@ void messageFunc(struct _nn_conn_t *conn, const char *fmt, va_list ap) { (void) conn; - printMsgV(chatWindows[0], LOG_STAMP | LOG_WINDOW | LOG_FILE, fmt, ap); + printMsgV(NULL, LOG_STAMP | LOG_WINDOW | LOG_FILE, fmt, ap); } @@ -1272,7 +1272,6 @@ int main(int argc, char *argv[]) { nn_conn_t *conn = NULL; - struct hostent *tmpHost = NULL, *proxyHost = NULL; int curVis = ERR, updateCount = 0; BOOL argsOK, isError = FALSE, exitProg = FALSE, @@ -1461,35 +1460,35 @@ goto err_exit; } + /* Create a connection */ + conn = nn_conn_new(errorFunc, messageFunc); + if (conn == NULL) { + errorMsg("Could not create connection structure.\n"); + goto err_exit; + } + /* Are we using a proxy? */ if (optProxyType != NN_PROXY_NONE && optProxyServer != NULL) { - printMsg(currWin, "Trying to resolve proxy host '%s' ...\n", optProxyServer); - tmpHost = gethostbyname(optProxyServer); - if (tmpHost == NULL) { - errorMsg("Could not resolve hostname: %s.\n", strerror(h_errno)); + if (nn_conn_set_proxy(conn, optProxyType, optProxyPort, optProxyServer) != 0) { + errorMsg("Error setting proxy information.\n"); goto err_exit; } - printMsg(currWin, "True hostname: %s\n", tmpHost->h_name); } /* Okay ... */ printMsg(currWin, "Trying to resolve host '%s' ...\n", optServer); - tmpHost = gethostbyname(optServer); - if (tmpHost == NULL) { + conn->host = th_strdup(optServer); + conn->hst = nn_resolve_host(conn, optServer); + if (conn->hst == NULL) { errorMsg("Could not resolve hostname: %s.\n", strerror(h_errno)); goto err_exit; } - printMsg(currWin, "True hostname: %s\n", tmpHost->h_name); #ifdef FINAL_BUILD /* To emulate the official client, we first make a request for * policy file, even though we don't use it for anything... */ - conn = nn_conn_open(errorFunc, messageFunc, - optProxyType, optProxyPort, proxyHost != NULL ? (struct in_addr *) proxyHost->h_addr : NULL, - (struct in_addr *) tmpHost->h_addr, 843, optServer); - - if (!nn_conn_check(conn)) { + if (nn_conn_open(conn, 843, NULL) != 0) { errorMsg("Policy file request connection setup failed!\n"); goto err_exit; } @@ -1510,11 +1509,7 @@ #endif /* Okay, now do the proper connection ... */ - conn = nn_conn_open(errorFunc, messageFunc, - optProxyType, optProxyPort, proxyHost != NULL ? (struct in_addr *) proxyHost->h_addr : NULL, - (struct in_addr *) tmpHost->h_addr, optPort, optServer); - - if (!nn_conn_check(conn)) { + if (nn_conn_open(conn, optPort, NULL) != 0) { errorMsg("Main connection setup failed!\n"); goto err_exit; }