From: Sebastian B. <sb...@us...> - 2014-02-21 06:39:11
|
Update of /cvsroot/simplemail/simplemail In directory sfp-cvs-1.v30.ch3.sourceforge.com:/tmp/cvs-serv25834 Modified Files: imap.c pop3.c tcp.c tcp.h Log Message: Introduced connection_options structure to simplyfy the development of further extensions. Index: imap.c =================================================================== RCS file: /cvsroot/simplemail/simplemail/imap.c,v retrieving revision 1.92 retrieving revision 1.93 diff -u -d -r1.92 -r1.93 --- imap.c 24 Dec 2013 10:34:00 -0000 1.92 +++ imap.c 21 Feb 2014 06:39:08 -0000 1.93 @@ -1104,6 +1104,7 @@ for( ;server; server = (struct imap_server*)node_next(&server->node)) { struct connection *conn; + struct connect_options conn_opts = {}; char head_buf[100]; SM_DEBUGF(10,("Synchronizing with server \"%s\"\n",server->name)); @@ -1140,8 +1141,10 @@ free(login); } + conn_opts.use_ssl = server->ssl; + SM_DEBUGF(10,("Connecting\n")); - if ((conn = tcp_connect(server->name, server->port, server->ssl))) + if ((conn = tcp_connect(server->name, server->port, &conn_opts))) { thread_call_parent_function_async(status_set_status,1,_("Waiting for login...")); SM_DEBUGF(10,("Waiting for login\n")); @@ -1218,6 +1221,7 @@ if (open_socket_lib()) { struct connection *conn; + struct connect_options conn_opts = {}; char head_buf[100]; sprintf(head_buf,_("Reading folders of %s"),server->name); @@ -1228,7 +1232,9 @@ thread_call_parent_function_async_string(status_set_title, 1, server->name); thread_call_parent_function_async_string(status_set_connect_to_server, 1, server->name); - if ((conn = tcp_connect(server->name, server->port, server->ssl))) + conn_opts.use_ssl = server->ssl; + + if ((conn = tcp_connect(server->name, server->port, &conn_opts))) { thread_call_parent_function_async(status_set_status,1,N_("Waiting for login...")); if (imap_wait_login(conn,server)) @@ -1296,9 +1302,10 @@ if (open_socket_lib()) { struct connection *conn; + struct connect_options conn_opts = {}; char head_buf[100]; - sprintf(head_buf,_("Submitting subscribed folders to %s"),server->name); + sm_snprintf(head_buf,sizeof(head_buf),_("Submitting subscribed folders to %s"),server->name); thread_call_parent_function_async_string(status_set_head, 1, head_buf); if (server->title) thread_call_parent_function_async_string(status_set_title_utf8, 1, server->title); @@ -1306,7 +1313,9 @@ thread_call_parent_function_async_string(status_set_title, 1, server->name); thread_call_parent_function_async_string(status_set_connect_to_server, 1, server->name); - if ((conn = tcp_connect(server->name, server->port, server->ssl))) + conn_opts.use_ssl = server->ssl; + + if ((conn = tcp_connect(server->name, server->port, &conn_opts))) { thread_call_parent_function_async(status_set_status,1,_("Waiting for login...")); if (imap_wait_login(conn,server)) @@ -1855,6 +1864,7 @@ if (imap_server) { char status_buf[160]; + struct connect_options conn_opts = {}; if (!imap_socket_lib_open) imap_socket_lib_open = open_socket_lib(); @@ -1896,7 +1906,9 @@ sm_snprintf(status_buf,sizeof(status_buf),"%s: %s",imap_server->name, _("Connecting...")); thread_call_parent_function_async_string(status_set_status,1,status_buf); - if ((imap_connection = tcp_connect(imap_server->name, imap_server->port, imap_server->ssl))) + conn_opts.use_ssl = imap_server->ssl; + + if ((imap_connection = tcp_connect(imap_server->name, imap_server->port, &conn_opts))) { SM_DEBUGF(20,("Connected to %s\n",imap_server->name)); Index: pop3.c =================================================================== RCS file: /cvsroot/simplemail/simplemail/pop3.c,v retrieving revision 1.106 retrieving revision 1.107 diff -u -d -r1.106 -r1.107 --- pop3.c 14 Dec 2012 20:38:43 -0000 1.106 +++ pop3.c 21 Feb 2014 06:39:08 -0000 1.107 @@ -941,6 +941,7 @@ for (;server; server = (struct pop3_server*)node_next(&server->node)) { struct connection *conn; + struct connect_options connect_options = {}; char head_buf[100]; rc = 0; @@ -977,7 +978,9 @@ free(login); } - if ((conn = tcp_connect(server->name, server->port, server->ssl && (!server->stls)))) + connect_options.use_ssl = server->ssl && !server->stls; + + if ((conn = tcp_connect(server->name, server->port, &connect_options))) { char *timestamp; thread_call_parent_function_async(status_set_status,1,_("Waiting for login...")); @@ -997,7 +1000,7 @@ pop3_quit(conn,server); tcp_disconnect(conn); SM_DEBUGF(15,("Trying to connect again to the server\n")); - if ((conn = tcp_connect(server->name, server->port, server->ssl && (!server->stls)))) + if ((conn = tcp_connect(server->name, server->port, &connect_options))) { if (pop3_wait_login(conn,server,NULL)) { @@ -1170,8 +1173,11 @@ if (open_socket_lib()) { struct connection *conn; + struct connect_options conn_opts = {}; - if ((conn = tcp_connect(server->name, server->port,server->ssl && (!server->stls)))) + conn_opts.use_ssl = server->ssl && (!server->stls); + + if ((conn = tcp_connect(server->name, server->port, &conn_opts))) { char *timestamp; @@ -1188,7 +1194,7 @@ In such cases a reconnect should help. */ pop3_quit(conn,server); tcp_disconnect(conn); - if ((conn = tcp_connect(server->name, server->port, server->ssl && (!server->stls)))) + if ((conn = tcp_connect(server->name, server->port, &conn_opts))) { if (pop3_wait_login(conn,server,NULL)) { Index: tcp.c =================================================================== RCS file: /cvsroot/simplemail/simplemail/tcp.c,v retrieving revision 1.52 retrieving revision 1.53 diff -u -d -r1.52 -r1.53 --- tcp.c 21 Feb 2014 06:38:32 -0000 1.52 +++ tcp.c 21 Feb 2014 06:39:08 -0000 1.53 @@ -107,17 +107,18 @@ * @param server defines the name of the server to which the connection * should be created. * @param port defines to which server port the connection should be established. - * @param use_ssl defines whether connection should be made secure. + * @param options defines additional connection should be made secure. * @return the connection or NULL on failure. Use tcp_error_code() for more information. * * @note TODO: Rework the error code handling. */ -struct connection *tcp_connect(char *server, unsigned int port, int use_ssl) +struct connection *tcp_connect(char *server, unsigned int port, struct connect_options *options) { int i,sd; struct sockaddr_in sockaddr; struct hostent *hostent; struct connection *conn = NULL; + int use_ssl = options?options->use_ssl:0; SM_ENTER; Index: tcp.h =================================================================== RCS file: /cvsroot/simplemail/simplemail/tcp.h,v retrieving revision 1.17 retrieving revision 1.18 diff -u -d -r1.17 -r1.18 --- tcp.h 3 Nov 2004 01:26:37 -0000 1.17 +++ tcp.h 21 Feb 2014 06:39:08 -0000 1.18 @@ -40,6 +40,11 @@ #endif +struct connect_options +{ + int use_ssl; +}; + struct connection { long socket; @@ -60,7 +65,7 @@ int tcp_error_code(void); const char *tcp_strerror(int code); -struct connection *tcp_connect(char *server, unsigned int port, int use_ssl); +struct connection *tcp_connect(char *server, unsigned int port, struct connect_options *options); void tcp_disconnect(struct connection *conn); int tcp_make_secure(struct connection *conn); int tcp_secure(struct connection *conn); |