# HG changeset patch # User Matti Hamalainen # Date 1400549663 -10800 # Node ID 2cc5434a8ce0c8871fb1c86fcfce97d0ebfb4479 # Parent ad00f2bbb615e290d9b9b75777436602378f9ffb Change proxy authentication handling. diff -r ad00f2bbb615 -r 2cc5434a8ce0 main.c --- a/main.c Tue May 20 02:11:05 2014 +0300 +++ b/main.c Tue May 20 04:34:23 2014 +0300 @@ -59,7 +59,8 @@ */ int optPort = 8005, optProxyPort = 1080, - optProxyType = NN_PROXY_NONE; + optProxyType = NN_PROXY_NONE, + optProxyAuthType = NN_PROXY_AUTH_NONE; int optUserColor = 0x000000; char *optServer = "chat.newbienudes.com", *optProxyServer = NULL, @@ -2089,8 +2090,8 @@ if (optProxyUserID == NULL) optProxyUserID = "James Bond"; - if (nn_conn_set_proxy(conn, optProxyType, optProxyPort, optProxyServer, - optProxyUserID, optProxyPassword) != 0) + if (nn_conn_set_proxy(conn, optProxyType, optProxyPort, optProxyServer, optProxyAuthType) != 0 || + nn_conn_set_proxy_auth_user(conn, optProxyUserID, optProxyPassword) != 0) { errorMsg("Error setting proxy information.\n"); goto err_exit; diff -r ad00f2bbb615 -r 2cc5434a8ce0 network.c --- a/network.c Tue May 20 02:11:05 2014 +0300 +++ b/network.c Tue May 20 04:34:23 2014 +0300 @@ -133,7 +133,7 @@ void (*errfunc)(nn_conn_t *conn, const char *msg), void (*msgfunc)(nn_conn_t *conn, const char *msg)) { - nn_conn_t *conn = th_calloc(1, sizeof(nn_conn_t)); + nn_conn_t *conn = th_malloc0(sizeof(nn_conn_t)); if (conn == NULL) return NULL; @@ -160,16 +160,17 @@ } -int nn_conn_set_proxy(nn_conn_t *conn, int type, int port, const char *host, const char *userid, const char *passwd) +int nn_conn_set_proxy(nn_conn_t *conn, int type, int port, const char *host, int auth_type) { if (conn == NULL) return -1; conn->proxy.type = type; conn->proxy.port = port; + conn->proxy.auth_type = auth_type; + + th_free(conn->proxy.host); conn->proxy.host = th_strdup(host); - conn->proxy.userid = th_strdup(userid); - conn->proxy.passwd = th_strdup(passwd); if (host != NULL) { @@ -183,6 +184,20 @@ } +int nn_conn_set_proxy_auth_user(nn_conn_t *conn, const char *userid, const char *passwd) +{ + if (conn == NULL) + return -1; + + th_free(conn->proxy.userid); + conn->proxy.userid = th_strdup(userid); + th_free(conn->proxy.passwd); + conn->proxy.passwd = th_strdup(passwd); + + return 0; +} + + int nn_conn_open(nn_conn_t *conn, const int port, const char *host) { struct sockaddr_in dest; diff -r ad00f2bbb615 -r 2cc5434a8ce0 network.h --- a/network.h Tue May 20 02:11:05 2014 +0300 +++ b/network.h Tue May 20 04:34:23 2014 +0300 @@ -71,7 +71,7 @@ { char *host; struct hostent *hst; - int type; + int type, auth_type; int port; struct in_addr addr; char *userid, *passwd; @@ -106,12 +106,14 @@ void (*errfunc)(nn_conn_t *conn, const char *msg), void (*msgfunc)(nn_conn_t *conn, const char *msg)); -int nn_conn_set_proxy(nn_conn_t *conn, int type, int port, const char *host, const char *userid, const char *passwd); +int nn_conn_set_proxy(nn_conn_t *conn, int type, int port, const char *host, int auth_type); +int nn_conn_set_proxy_auth_user(nn_conn_t *conn, const char *userid, const char *passwd); int nn_conn_open(nn_conn_t *conn, const int port, const char *host); void nn_conn_close(nn_conn_t *); void nn_conn_reset(nn_conn_t *); int nn_conn_pull(nn_conn_t *); BOOL nn_conn_send_buf(nn_conn_t *, const char *buf, const size_t len); + BOOL nn_conn_send_msg(nn_conn_t *, const char *user, const char *str); BOOL nn_conn_send_msg_v(nn_conn_t *, const char *user, const char *fmt, ...); BOOL nn_conn_check(nn_conn_t *);