comparison main.c @ 623:118276b60667

More work towards using th-libs th_network module.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 21 Jun 2014 02:40:51 +0300
parents bb6b07b44800
children 24d97c710497
comparison
equal deleted inserted replaced
622:bb6b07b44800 623:118276b60667
56 56
57 /* Options 57 /* Options
58 */ 58 */
59 int optPort = 8005, 59 int optPort = 8005,
60 optProxyPort = 1080, 60 optProxyPort = 1080,
61 optProxyType = NN_PROXY_NONE, 61 optProxyType = TH_PROXY_NONE,
62 optProxyAuthType = NN_PROXY_AUTH_NONE; 62 optProxyAuthType = TH_PROXY_AUTH_NONE;
63 int optUserColor = 0x000000; 63 int optUserColor = 0x000000;
64 char *optServer = "chat.newbienudes.com", 64 char *optServer = "chat.newbienudes.com",
65 *optProxyServer = NULL, 65 *optProxyServer = NULL,
66 *optProxyUserID = NULL, 66 *optProxyUserID = NULL,
67 *optProxyPassword = NULL, 67 *optProxyPassword = NULL,
192 goto out; 192 goto out;
193 } 193 }
194 194
195 // Validate proxy type 195 // Validate proxy type
196 if (strcasecmp(proto, "socks4") == 0) 196 if (strcasecmp(proto, "socks4") == 0)
197 optProxyType = NN_PROXY_SOCKS4; 197 optProxyType = TH_PROXY_SOCKS4;
198 else 198 else
199 if (strcasecmp(proto, "socks4a") == 0) 199 if (strcasecmp(proto, "socks4a") == 0)
200 optProxyType = NN_PROXY_SOCKS4A; 200 optProxyType = TH_PROXY_SOCKS4A;
201 else 201 else
202 { 202 {
203 THERR("Invalid proxy type specified: '%s'\n", proto); 203 THERR("Invalid proxy type specified: '%s'\n", proto);
204 goto out; 204 goto out;
205 } 205 }
238 else 238 else
239 optProxyServer = th_strdup(host); 239 optProxyServer = th_strdup(host);
240 240
241 // Check what authentication type to use 241 // Check what authentication type to use
242 /* 242 /*
243 if (optProxyType == NN_PROXY_SOCKS5 && 243 if (optProxyType == TH_PROXY_SOCKS5 &&
244 optProxyUserID != NULL && optProxyPassword != NULL) 244 optProxyUserID != NULL && optProxyPassword != NULL)
245 optProxyAuthType = NN_PROXY_AUTH_USER; 245 optProxyAuthType = TH_PROXY_AUTH_USER;
246 else 246 else
247 */ 247 */
248 optProxyAuthType = NN_PROXY_AUTH_NONE; 248 optProxyAuthType = TH_PROXY_AUTH_NONE;
249 249
250 ret = TRUE; 250 ret = TRUE;
251 251
252 out: 252 out:
253 th_free(proto); 253 th_free(proto);
359 359
360 msg = th_strdup_printf("<USER>%s</USER><MESSAGE>%s</MESSAGE>", user, str); 360 msg = th_strdup_printf("<USER>%s</USER><MESSAGE>%s</MESSAGE>", user, str);
361 361
362 if (msg != NULL) 362 if (msg != NULL)
363 { 363 {
364 BOOL ret = nn_conn_send_buf(conn, msg, strlen(msg) + 1); 364 BOOL ret = th_conn_send_buf(conn, msg, strlen(msg) + 1);
365 th_free(msg); 365 th_free(msg);
366 return ret; 366 return ret;
367 } 367 }
368 else 368 else
369 return FALSE; 369 return FALSE;
564 va_end(ap); 564 va_end(ap);
565 } 565 }
566 } 566 }
567 567
568 568
569 void nn_network_errfunc(struct _th_conn_t *conn, const char *msg) 569 void nn_network_errfunc(struct _th_conn_t *conn, int err, const char *msg)
570 { 570 {
571 (void) conn; 571 (void) conn;
572 (void) err;
572 errorMsg("%s", msg); 573 errorMsg("%s", msg);
573 } 574 }
574 575
575 576
576 void nn_network_msgfunc(struct _th_conn_t *conn, const char *msg) 577 void nn_network_msgfunc(struct _th_conn_t *conn, int loglevel, const char *msg)
577 { 578 {
578 (void) conn; 579 (void) conn;
580 (void) loglevel;
579 printMsgConst(NULL, LOG_STAMP | LOG_WINDOW | LOG_FILE, msg); 581 printMsgConst(NULL, LOG_STAMP | LOG_WINDOW | LOG_FILE, msg);
580 } 582 }
581 583
582 584
583 void nn_ioctx_errfunc(th_ioctx_t *ctx, int err, const char *msg) 585 void nn_ioctx_errfunc(th_ioctx_t *ctx, int err, const char *msg)
1968 1970
1969 1971
1970 int main(int argc, char *argv[]) 1972 int main(int argc, char *argv[])
1971 { 1973 {
1972 char *tmpStr; 1974 char *tmpStr;
1973 int index, updateCount = 0; 1975 int index, updateCount = 0, ret;
1974 BOOL argsOK, colorSet = FALSE; 1976 BOOL argsOK, colorSet = FALSE;
1975 th_conn_t *conn = NULL; 1977 th_conn_t *conn = NULL;
1976 nn_editbuf_t *editBuf = nn_editbuf_new(NN_TMPBUF_SIZE); 1978 nn_editbuf_t *editBuf = nn_editbuf_new(NN_TMPBUF_SIZE);
1977 nn_editstate_t editState; 1979 nn_editstate_t editState;
1978 th_cfgitem_t *tmpcfg; 1980 th_cfgitem_t *tmpcfg;
2158 { 2160 {
2159 th_llist_append(&setIdleMessages, th_strdup(".")); 2161 th_llist_append(&setIdleMessages, th_strdup("."));
2160 } 2162 }
2161 2163
2162 // Initialize network 2164 // Initialize network
2163 if (!nn_network_init()) 2165 if ((ret = th_network_init()) != THERR_OK)
2164 { 2166 {
2165 THERR("Could not initialize network subsystem.\n"); 2167 THERR("Could not initialize network subsystem: %s\n", th_error_str(ret));
2166 goto err_exit; 2168 goto err_exit;
2167 } 2169 }
2168 2170
2169 // Initialize curses windowing 2171 // Initialize curses windowing
2170 if (!optDaemon && !nnwin_init(SET_DELAY)) 2172 if (!optDaemon && !nnwin_init(SET_DELAY))
2214 } 2216 }
2215 2217
2216 editState.conn = conn; 2218 editState.conn = conn;
2217 2219
2218 // Are we using a proxy? 2220 // Are we using a proxy?
2219 if (optProxyType != NN_PROXY_NONE && optProxyServer != NULL) 2221 if (optProxyType != TH_PROXY_NONE && optProxyServer != NULL)
2220 { 2222 {
2221 if (optProxyUserID == NULL) 2223 if (optProxyUserID == NULL)
2222 optProxyUserID = "James Bond"; 2224 optProxyUserID = "James Bond";
2223 2225
2224 if (th_conn_set_proxy(conn, optProxyType, optProxyPort, optProxyServer, optProxyAuthType) != 0 || 2226 if (th_conn_set_proxy(conn, optProxyType, optProxyPort, optProxyServer, optProxyAuthType) != 0 ||
2229 } 2231 }
2230 } 2232 }
2231 2233
2232 // Okay, try to resolve the hostname 2234 // Okay, try to resolve the hostname
2233 conn->host = th_strdup(optServer); 2235 conn->host = th_strdup(optServer);
2234 conn->hst = nn_resolve_host(conn, optServer); 2236 conn->hst = th_resolve_host(conn, optServer);
2235 if (conn->hst == NULL) 2237 if (conn->hst == NULL)
2236 goto err_exit; 2238 goto err_exit;
2237 2239
2238 #ifdef FINAL_BUILD 2240 #ifdef FINAL_BUILD
2239 /* To emulate the official client, we first make a request for 2241 /* To emulate the official client, we first make a request for
2388 THERR("%s", errorMessages); 2390 THERR("%s", errorMessages);
2389 #endif 2391 #endif
2390 2392
2391 th_free(optUserNameEnc); 2393 th_free(optUserNameEnc);
2392 th_conn_free(conn); 2394 th_conn_free(conn);
2393 nn_network_close(); 2395 th_network_close();
2394 2396
2395 THMSG(1, "Connection terminated.\n"); 2397 THMSG(1, "Connection terminated.\n");
2396 2398
2397 return 0; 2399 return 0;
2398 } 2400 }