Mercurial > hg > nnchat
comparison 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 |
comparison
equal
deleted
inserted
replaced
353:83ae825bb8c1 | 354:c01e42fc9adb |
---|---|
567 } | 567 } |
568 | 568 |
569 void messageFunc(struct _nn_conn_t *conn, const char *fmt, va_list ap) | 569 void messageFunc(struct _nn_conn_t *conn, const char *fmt, va_list ap) |
570 { | 570 { |
571 (void) conn; | 571 (void) conn; |
572 printMsgV(chatWindows[0], LOG_STAMP | LOG_WINDOW | LOG_FILE, fmt, ap); | 572 printMsgV(NULL, LOG_STAMP | LOG_WINDOW | LOG_FILE, fmt, ap); |
573 } | 573 } |
574 | 574 |
575 | 575 |
576 BOOL checkIgnoreList(const char *name) | 576 BOOL checkIgnoreList(const char *name) |
577 { | 577 { |
1270 } | 1270 } |
1271 | 1271 |
1272 int main(int argc, char *argv[]) | 1272 int main(int argc, char *argv[]) |
1273 { | 1273 { |
1274 nn_conn_t *conn = NULL; | 1274 nn_conn_t *conn = NULL; |
1275 struct hostent *tmpHost = NULL, *proxyHost = NULL; | |
1276 int curVis = ERR, updateCount = 0; | 1275 int curVis = ERR, updateCount = 0; |
1277 BOOL argsOK, isError = FALSE, | 1276 BOOL argsOK, isError = FALSE, |
1278 exitProg = FALSE, | 1277 exitProg = FALSE, |
1279 colorSet = FALSE, | 1278 colorSet = FALSE, |
1280 cursesInit = FALSE, | 1279 cursesInit = FALSE, |
1459 if (optUserName == NULL || optPassword == NULL) { | 1458 if (optUserName == NULL || optPassword == NULL) { |
1460 errorMsg("Username and/or password not specified.\n"); | 1459 errorMsg("Username and/or password not specified.\n"); |
1461 goto err_exit; | 1460 goto err_exit; |
1462 } | 1461 } |
1463 | 1462 |
1463 /* Create a connection */ | |
1464 conn = nn_conn_new(errorFunc, messageFunc); | |
1465 if (conn == NULL) { | |
1466 errorMsg("Could not create connection structure.\n"); | |
1467 goto err_exit; | |
1468 } | |
1469 | |
1464 /* Are we using a proxy? */ | 1470 /* Are we using a proxy? */ |
1465 if (optProxyType != NN_PROXY_NONE && optProxyServer != NULL) { | 1471 if (optProxyType != NN_PROXY_NONE && optProxyServer != NULL) { |
1466 printMsg(currWin, "Trying to resolve proxy host '%s' ...\n", optProxyServer); | 1472 if (nn_conn_set_proxy(conn, optProxyType, optProxyPort, optProxyServer) != 0) { |
1467 tmpHost = gethostbyname(optProxyServer); | 1473 errorMsg("Error setting proxy information.\n"); |
1468 if (tmpHost == NULL) { | |
1469 errorMsg("Could not resolve hostname: %s.\n", strerror(h_errno)); | |
1470 goto err_exit; | 1474 goto err_exit; |
1471 } | 1475 } |
1472 printMsg(currWin, "True hostname: %s\n", tmpHost->h_name); | |
1473 } | 1476 } |
1474 | 1477 |
1475 /* Okay ... */ | 1478 /* Okay ... */ |
1476 printMsg(currWin, "Trying to resolve host '%s' ...\n", optServer); | 1479 printMsg(currWin, "Trying to resolve host '%s' ...\n", optServer); |
1477 tmpHost = gethostbyname(optServer); | 1480 conn->host = th_strdup(optServer); |
1478 if (tmpHost == NULL) { | 1481 conn->hst = nn_resolve_host(conn, optServer); |
1482 if (conn->hst == NULL) { | |
1479 errorMsg("Could not resolve hostname: %s.\n", strerror(h_errno)); | 1483 errorMsg("Could not resolve hostname: %s.\n", strerror(h_errno)); |
1480 goto err_exit; | 1484 goto err_exit; |
1481 } | 1485 } |
1482 printMsg(currWin, "True hostname: %s\n", tmpHost->h_name); | |
1483 | 1486 |
1484 #ifdef FINAL_BUILD | 1487 #ifdef FINAL_BUILD |
1485 /* To emulate the official client, we first make a request for | 1488 /* To emulate the official client, we first make a request for |
1486 * policy file, even though we don't use it for anything... | 1489 * policy file, even though we don't use it for anything... |
1487 */ | 1490 */ |
1488 conn = nn_conn_open(errorFunc, messageFunc, | 1491 if (nn_conn_open(conn, 843, NULL) != 0) { |
1489 optProxyType, optProxyPort, proxyHost != NULL ? (struct in_addr *) proxyHost->h_addr : NULL, | |
1490 (struct in_addr *) tmpHost->h_addr, 843, optServer); | |
1491 | |
1492 if (!nn_conn_check(conn)) { | |
1493 errorMsg("Policy file request connection setup failed!\n"); | 1492 errorMsg("Policy file request connection setup failed!\n"); |
1494 goto err_exit; | 1493 goto err_exit; |
1495 } | 1494 } |
1496 | 1495 |
1497 tmpStr = "<policy-file-request/>"; | 1496 tmpStr = "<policy-file-request/>"; |
1508 } | 1507 } |
1509 nn_conn_close(conn); | 1508 nn_conn_close(conn); |
1510 #endif | 1509 #endif |
1511 | 1510 |
1512 /* Okay, now do the proper connection ... */ | 1511 /* Okay, now do the proper connection ... */ |
1513 conn = nn_conn_open(errorFunc, messageFunc, | 1512 if (nn_conn_open(conn, optPort, NULL) != 0) { |
1514 optProxyType, optProxyPort, proxyHost != NULL ? (struct in_addr *) proxyHost->h_addr : NULL, | |
1515 (struct in_addr *) tmpHost->h_addr, optPort, optServer); | |
1516 | |
1517 if (!nn_conn_check(conn)) { | |
1518 errorMsg("Main connection setup failed!\n"); | 1513 errorMsg("Main connection setup failed!\n"); |
1519 goto err_exit; | 1514 goto err_exit; |
1520 } | 1515 } |
1521 | 1516 |
1522 /* Send login command */ | 1517 /* Send login command */ |