~ubuntu-branches/ubuntu/precise/evolution-data-server/precise-proposed

« back to all changes in this revision

Viewing changes to camel/providers/imapx/camel-imapx-server.c

  • Committer: Bazaar Package Importer
  • Author(s): Mathieu Trudel-Lapierre
  • Date: 2011-07-27 11:45:30 UTC
  • mfrom: (1.1.90 upstream)
  • Revision ID: james.westby@ubuntu.com-20110727114530-v4ntbu728os68b0b
Tags: 3.1.4-0ubuntu1
* New upstream version.
* debian/patches/999git_EDS_3_1_3_1_to_f94a069.patch: drop, included in
  the upstream 3.1.4 tarball.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2233
2233
                        "Unable to issue DONE");
2234
2234
                c(is->tagprefix, "Failed to issue DONE to terminate IDLE\n");
2235
2235
                is->state = IMAPX_SHUTDOWN;
 
2236
                is->parser_quit = TRUE;
2236
2237
                if (is->cancellable)
2237
2238
                        camel_operation_cancel (CAMEL_OPERATION (is->cancellable));
2238
 
                is->parser_quit = TRUE;
2239
2239
                return FALSE;
2240
2240
        }
2241
2241
 
2860
2860
                         GCancellable *cancellable,
2861
2861
                         GError **error)
2862
2862
{
 
2863
        CamelNetworkService *network_service;
 
2864
        CamelNetworkSecurityMethod method;
2863
2865
        CamelStream * tcp_stream = NULL;
2864
 
        gchar *socks_host;
2865
 
        gint socks_port;
2866
2866
        CamelSockOptData sockopt;
2867
 
        gint ret, ssl_mode = 0;
2868
 
 
2869
 
#ifdef CAMEL_HAVE_SSL
2870
 
        const gchar *mode;
2871
 
#endif
2872
2867
        guint len;
2873
2868
        guchar *token;
2874
2869
        gint tok;
2875
 
        const gchar *serv;
2876
 
        gint fallback_port;
2877
2870
        CamelIMAPXCommand *ic;
2878
2871
        GError *local_error = NULL;
2879
2872
 
2888
2881
                        goto connected;
2889
2882
        }
2890
2883
#endif
2891
 
        if (is->url->port) {
2892
 
                serv = g_alloca (16);
2893
 
                sprintf((gchar *) serv, "%d", is->url->port);
2894
 
                fallback_port = 0;
2895
 
        } else {
2896
 
                serv = "imap";
2897
 
                fallback_port = 143;
2898
 
        }
2899
 
#ifdef CAMEL_HAVE_SSL
2900
 
        mode = camel_url_get_param(is->url, "use_ssl");
2901
 
        if (mode && strcmp(mode, "never") != 0) {
2902
 
                if (!strcmp(mode, "when-possible")) {
2903
 
                        tcp_stream = camel_tcp_stream_ssl_new_raw (is->session, is->url->host, STARTTLS_FLAGS);
2904
 
                        ssl_mode = 2;
2905
 
                } else {
2906
 
                        if (is->url->port == 0) {
2907
 
                                serv = "imaps";
2908
 
                                fallback_port = 993;
2909
 
                        }
2910
 
                        tcp_stream = camel_tcp_stream_ssl_new (is->session, is->url->host, SSL_PORT_FLAGS);
2911
 
                }
2912
 
        } else {
2913
 
                tcp_stream = camel_tcp_stream_raw_new ();
2914
 
        }
2915
 
#else
2916
 
        tcp_stream = camel_tcp_stream_raw_new ();
2917
 
#endif /* CAMEL_HAVE_SSL */
2918
 
 
2919
 
        camel_session_get_socks_proxy (is->session, &socks_host, &socks_port);
2920
 
 
2921
 
        if (socks_host) {
2922
 
                camel_tcp_stream_set_socks_proxy ((CamelTcpStream *) tcp_stream, socks_host, socks_port);
2923
 
                g_free (socks_host);
2924
 
        }
2925
 
 
2926
 
        ret = camel_tcp_stream_connect (
2927
 
                CAMEL_TCP_STREAM (tcp_stream), is->url->host, serv,
2928
 
                fallback_port, cancellable, error);
2929
 
        if (ret == -1) {
2930
 
                g_prefix_error (
2931
 
                        error, _("Could not connect to %s (port %s): "),
2932
 
                        is->url->host, serv);
2933
 
                g_object_unref (tcp_stream);
 
2884
 
 
2885
        network_service = CAMEL_NETWORK_SERVICE (is->store);
 
2886
        method = camel_network_service_get_security_method (network_service);
 
2887
 
 
2888
        tcp_stream = camel_network_service_connect_sync (
 
2889
                CAMEL_NETWORK_SERVICE (is->store), cancellable, error);
 
2890
 
 
2891
        if (tcp_stream == NULL)
2934
2892
                return FALSE;
2935
 
        }
2936
2893
 
2937
2894
        is->stream = (CamelIMAPXStream *) camel_imapx_stream_new (tcp_stream);
2938
2895
        g_object_unref (tcp_stream);
2998
2955
        }
2999
2956
 
3000
2957
#ifdef CAMEL_HAVE_SSL
3001
 
        if (ssl_mode == 2)
3002
 
        {
 
2958
        if (method == CAMEL_NETWORK_SECURITY_METHOD_STARTTLS_ON_STANDARD_PORT) {
3003
2959
 
3004
2960
                if (!(is->cinfo->capa & IMAPX_CAPABILITY_STARTTLS)) {
3005
2961
                        g_set_error (
4982
4938
                        fds[0].events = G_IO_IN;
4983
4939
                        fds[1].fd = g_cancellable_get_fd (cancellable);
4984
4940
                        fds[1].events = G_IO_IN;
4985
 
                        res = g_poll (fds, 2, 1000*30);
 
4941
                        res = g_poll (fds, 2, -1);
4986
4942
                        if (res == -1)
4987
4943
                                g_usleep (1) /* ?? */ ;
4988
4944
                        else if (res == 0)
5003
4959
                        pollfds[1].fd = camel_operation_cancel_prfd (CAMEL_OPERATION (cancellable));
5004
4960
                        pollfds[1].in_flags = PR_POLL_READ;
5005
4961
 
5006
 
                        res = PR_Poll (pollfds, 2, PR_MillisecondsToInterval (30 * 1000));
 
4962
                        res = PR_Poll (pollfds, 2, PR_INTERVAL_NO_TIMEOUT);
5007
4963
                        if (res == -1)
5008
4964
                                g_usleep (1) /* ?? */ ;
5009
4965
                        else if (res == 0) {
5066
5022
        return NULL;
5067
5023
}
5068
5024
 
5069
 
static void
5070
 
imapx_server_finalize (GObject *object)
5071
 
{
5072
 
        CamelIMAPXServer *is = CAMEL_IMAPX_SERVER (object);
5073
 
 
5074
 
        camel_url_free (is->url);
5075
 
 
5076
 
        g_static_rec_mutex_free (&is->queue_lock);
5077
 
        g_static_rec_mutex_free (&is->ostream_lock);
5078
 
        g_mutex_free (is->fetch_mutex);
5079
 
        g_cond_free (is->fetch_cond);
5080
 
 
5081
 
        camel_folder_change_info_free (is->changes);
5082
 
 
5083
 
        /* Chain up to parent's finalize() method. */
5084
 
        G_OBJECT_CLASS (camel_imapx_server_parent_class)->finalize (object);
5085
 
}
5086
 
 
5087
 
static void
5088
 
imapx_server_constructed (GObject *object)
5089
 
{
5090
 
        CamelIMAPXServer *server;
5091
 
        CamelIMAPXServerClass *class;
5092
 
 
5093
 
        server = CAMEL_IMAPX_SERVER (object);
5094
 
        class = CAMEL_IMAPX_SERVER_GET_CLASS (server);
5095
 
 
5096
 
        server->tagprefix = class->tagprefix;
5097
 
        class->tagprefix++;
5098
 
        if (class->tagprefix > 'Z')
5099
 
                class->tagprefix = 'A';
5100
 
}
5101
 
 
5102
5025
static gboolean
5103
5026
join_helper (gpointer thread)
5104
5027
{
5136
5059
 
5137
5060
        imapx_disconnect (server);
5138
5061
 
 
5062
        if (server->session != NULL) {
 
5063
                g_object_unref (server->session);
 
5064
                server->session = NULL;
 
5065
        }
 
5066
 
5139
5067
        /* Chain up to parent's dispose() method. */
5140
5068
        G_OBJECT_CLASS (camel_imapx_server_parent_class)->dispose (object);
5141
5069
}
5142
5070
 
5143
5071
static void
 
5072
imapx_server_finalize (GObject *object)
 
5073
{
 
5074
        CamelIMAPXServer *is = CAMEL_IMAPX_SERVER (object);
 
5075
 
 
5076
        camel_url_free (is->url);
 
5077
 
 
5078
        g_static_rec_mutex_free (&is->queue_lock);
 
5079
        g_static_rec_mutex_free (&is->ostream_lock);
 
5080
        g_mutex_free (is->fetch_mutex);
 
5081
        g_cond_free (is->fetch_cond);
 
5082
 
 
5083
        camel_folder_change_info_free (is->changes);
 
5084
 
 
5085
        /* Chain up to parent's finalize() method. */
 
5086
        G_OBJECT_CLASS (camel_imapx_server_parent_class)->finalize (object);
 
5087
}
 
5088
 
 
5089
static void
 
5090
imapx_server_constructed (GObject *object)
 
5091
{
 
5092
        CamelIMAPXServer *server;
 
5093
        CamelIMAPXServerClass *class;
 
5094
 
 
5095
        server = CAMEL_IMAPX_SERVER (object);
 
5096
        class = CAMEL_IMAPX_SERVER_GET_CLASS (server);
 
5097
 
 
5098
        server->tagprefix = class->tagprefix;
 
5099
        class->tagprefix++;
 
5100
        if (class->tagprefix > 'Z')
 
5101
                class->tagprefix = 'A';
 
5102
}
 
5103
 
 
5104
static void
5144
5105
camel_imapx_server_class_init (CamelIMAPXServerClass *class)
5145
5106
{
5146
5107
        GObjectClass *object_class;