Changeset 2503

Show
Ignore:
Timestamp:
07/26/07 10:49:35
Author:
pvanhoof
Message:

Several fixes in the POP code

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/ChangeLog

    r2499 r2503  
     12007-07-26  Philip Van Hoof  <pvanhoof@gnome.org> 
     2 
     3        * More granularity in the locking of the POP code 
     4        * Several fixes in the POP code 
     5 
    162007-07-25  Philip Van Hoof  <pvanhoof@gnome.org> 
    27 
  • trunk/libtinymail-camel/camel-lite/camel/providers/pop3/camel-pop3-folder.c

    r2499 r2503  
    9696                for (i=0;i<pop3_folder->uids->len;i++,fi++) { 
    9797                        if (fi[0]->cmd) { 
     98 
     99                                g_static_rec_mutex_lock (pop3_store->eng_lock); 
     100 
     101                                if (pop3_store->engine == NULL) { 
     102                                        g_ptr_array_free(pop3_folder->uids, TRUE); 
     103                                        g_hash_table_destroy(pop3_folder->uids_uid); 
     104                                        g_free(fi[0]->uid); 
     105                                        g_free(fi[0]); 
     106                                        g_static_rec_mutex_unlock (pop3_store->eng_lock); 
     107                                        return; 
     108                                } 
     109 
    98110                                while (camel_pop3_engine_iterate(pop3_store->engine, fi[0]->cmd) > 0) 
    99111                                        ; 
    100112                                camel_pop3_engine_command_free(pop3_store->engine, fi[0]->cmd); 
     113 
     114                                g_static_rec_mutex_unlock (pop3_store->eng_lock); 
    101115                        } 
    102116                         
     
    516530 
    517531        if (!expunge) { 
     532                camel_service_disconnect (CAMEL_SERVICE (pop3_store), TRUE, &dex); 
    518533                g_static_rec_mutex_unlock (pop3_store->eng_lock); 
    519                 camel_service_disconnect (CAMEL_SERVICE (pop3_store), TRUE, &dex); 
    520534                return; 
    521535        } 
     
    957971 
    958972                g_static_rec_mutex_lock (pop3_store->eng_lock); 
     973 
     974                if (pop3_store->engine == NULL) { 
     975                        g_static_rec_mutex_unlock (pop3_store->eng_lock); 
     976                        goto fail; 
     977                } 
     978 
    959979                while ((i = camel_pop3_engine_iterate(pop3_store->engine, fi->cmd)) > 0) 
    960980                        ; 
     981 
    961982                g_static_rec_mutex_unlock (pop3_store->eng_lock); 
    962983 
     
    965986 
    966987                /* getting error code? */ 
    967                 /*g_assert (fi->cmd->state == CAMEL_POP3_COMMAND_DATA);*/ 
     988                /* g_assert (fi->cmd->state == CAMEL_POP3_COMMAND_DATA); */ 
    968989 
    969990                g_static_rec_mutex_lock (pop3_store->eng_lock); 
     
    11001121                        while (camel_pop3_engine_iterate(pop3_store->engine, cmd) > 0); 
    11011122                        camel_pop3_engine_command_free(pop3_store->engine, cmd); 
     1123 
    11021124                        g_static_rec_mutex_unlock (pop3_store->eng_lock); 
    11031125                } 
     
    12591281                        fi->err = errno; 
    12601282                camel_pop3_engine_command_free(pop3_store->engine, pcr); 
     1283 
    12611284                g_static_rec_mutex_unlock (pop3_store->eng_lock); 
    12621285 
     
    14081431                camel_folder_change_info_remove_uid (changes, uids->pdata[i]); 
    14091432                /* We intentionally don't remove it from the cache because 
    1410                  * the cached data may be useful in replaying a COPY later. 
    1411                  */ 
     1433                 * the cached data may be useful in replaying a COPY later. */ 
    14121434        } 
    14131435        camel_folder_summary_save (folder->summary); 
  • trunk/libtinymail-camel/camel-lite/camel/providers/pop3/camel-pop3-store.c

    r2499 r2503  
    331331                store->delete_after =  atoi(delete_days); 
    332332 
    333         g_static_rec_mutex_lock (store->eng_lock); 
     333        g_static_rec_mutex_lock (store->eng_lock); /* ! */ 
     334 
    334335        if (!(store->engine = camel_pop3_engine_new (tcp_stream, flags))) { 
    335336                camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, 
     
    337338                        service->url->host); 
    338339                camel_object_unref (tcp_stream); 
    339                 g_static_rec_mutex_unlock (store->eng_lock); 
     340 
     341                g_static_rec_mutex_unlock (store->eng_lock); /* ! */ 
     342 
    340343                return FALSE; 
    341344        } 
    342345        store->engine->store = store; 
    343346        store->engine->partial_happening = FALSE; 
     347 
     348#ifndef HAVE_SSL /* ! */ 
    344349        g_static_rec_mutex_unlock (store->eng_lock); 
     350#endif 
    345351 
    346352        if (!must_tls && (ssl_mode != MODE_TLS))  
     
    348354                camel_object_unref (tcp_stream); 
    349355                store->connected = TRUE; 
     356 
     357#ifdef HAVE_SSL /* ! */ 
     358                g_static_rec_mutex_unlock (store->eng_lock); 
     359#endif 
     360 
    350361                return TRUE; 
    351362        } 
     
    405416        store->connected = TRUE; 
    406417 
     418        g_static_rec_mutex_unlock (store->eng_lock); /* ! */ 
     419 
    407420        return TRUE; 
    408421 
    409422 stls_exception: 
     423 
     424 
    410425        if (clean_quit)  
    411426        { 
     
    417432        } 
    418433 
    419         g_static_rec_mutex_lock (store->eng_lock); 
    420434        camel_object_unref (CAMEL_OBJECT (store->engine)); 
    421435        camel_object_unref (CAMEL_OBJECT (tcp_stream)); 
    422436        store->engine = NULL; 
    423437        store->connected = FALSE; 
    424         g_static_rec_mutex_unlock (store->eng_lock); 
     438 
     439        g_static_rec_mutex_unlock (store->eng_lock); /* ! */ 
    425440 
    426441        return FALSE; 
     
    500515        GList *types = NULL; 
    501516 
    502         types = CAMEL_SERVICE_CLASS (parent_class)->query_auth_types (service, ex); 
     517       types = CAMEL_SERVICE_CLASS (parent_class)->query_auth_types (service, ex); 
    503518        if (camel_exception_is_set (ex)) 
    504519                return NULL; 
    505520 
    506521        if (connect_to_server_wrapper (service, NULL)) { 
     522 
     523                g_static_rec_mutex_lock (store->eng_lock); 
     524 
     525                if (store->engine == NULL) { 
     526                        g_static_rec_mutex_unlock (store->eng_lock); 
     527                        return NULL; 
     528                } 
     529 
    507530                types = g_list_concat(types, g_list_copy(store->engine->auth)); 
     531                g_static_rec_mutex_unlock (store->eng_lock); 
     532 
    508533                pop3_disconnect (service, TRUE, NULL); 
    509534        } else { 
     
    614639 
    615640        if (!service->url->authmech) { 
     641 
     642                g_static_rec_mutex_lock (store->eng_lock); 
     643 
     644                if (store->engine == NULL) { 
     645                        g_static_rec_mutex_unlock (store->eng_lock); 
     646                        return FALSE; 
     647                } 
     648 
    616649                /* pop engine will take care of pipelining ability */ 
    617650                pcu = camel_pop3_engine_command_new(store->engine, 0, NULL, NULL, "USER %s\r\n", service->url->user); 
    618651                pcp = camel_pop3_engine_command_new(store->engine, 0, NULL, NULL, "PASS %s\r\n", service->url->passwd); 
     652 
     653                g_static_rec_mutex_unlock (store->eng_lock); 
     654 
    619655        } else if (strcmp(service->url->authmech, "+APOP") == 0 && store->engine->apop) { 
    620656                char *secret, md5asc[33], *d; 
     
    635671                        d++; 
    636672                } 
    637                  
     673 
     674                g_static_rec_mutex_lock (store->eng_lock); 
     675 
     676                if (store->engine == NULL) { 
     677                        g_static_rec_mutex_unlock (store->eng_lock); 
     678                        return FALSE; 
     679                } 
     680 
    638681                secret = g_alloca(strlen(store->engine->apop)+strlen(service->url->passwd)+1); 
    639682                sprintf(secret, "%s%s",  store->engine->apop, service->url->passwd); 
     
    642685                for (s = md5sum, d = md5asc; d < md5asc + 32; s++, d += 2) 
    643686                        sprintf (d, "%.2x", *s); 
    644                  
     687 
    645688                pcp = camel_pop3_engine_command_new(store->engine, 0, NULL, NULL, "APOP %s %s\r\n", 
    646689                                                    service->url->user, md5asc); 
     690 
     691                g_static_rec_mutex_unlock (store->eng_lock); 
     692 
    647693        } else { 
    648694                CamelServiceAuthType *auth; 
    649695                GList *l; 
    650696 
     697                g_static_rec_mutex_lock (store->eng_lock); 
     698 
     699                if (store->engine == NULL) { 
     700                        g_static_rec_mutex_unlock (store->eng_lock); 
     701                        return FALSE; 
     702                } 
     703 
    651704                l = store->engine->auth; 
    652705                while (l) { 
    653706                        auth = l->data; 
    654                         if (strcmp(auth->authproto, service->url->authmech) == 0) 
     707                        if (strcmp(auth->authproto, service->url->authmech) == 0) { 
     708                                g_static_rec_mutex_unlock (store->eng_lock); 
    655709                                return try_sasl(store, service->url->authmech, ex) == -1; 
     710                        } 
    656711                        l = l->next; 
    657712                } 
    658                  
     713 
     714                g_static_rec_mutex_unlock (store->eng_lock); 
     715 
    659716                camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_URL_INVALID, 
    660717                                      _("Unable to connect to POP server %s: " 
     
    663720                return FALSE; 
    664721        } 
    665          
     722 
     723        g_static_rec_mutex_lock (store->eng_lock); 
     724 
     725        if (store->engine == NULL) { 
     726                g_static_rec_mutex_unlock (store->eng_lock); 
     727                return FALSE; 
     728        } 
     729 
    666730        while ((status = camel_pop3_engine_iterate(store->engine, pcp)) > 0) 
    667731                ; 
    668          
     732 
     733 
    669734        if (status == -1) { 
    670735                if (errno == EINTR) { 
     
    689754                                      CAMEL_SERVICE (store)->url->host, 
    690755                                      store->engine->line ? (char *)store->engine->line : _("Unknown error")); 
    691          
    692         camel_pop3_engine_command_free(store->engine, pcp); 
     756 
     757        camel_pop3_engine_command_free (store->engine, pcp); 
    693758         
    694759        if (pcu) 
    695760                camel_pop3_engine_command_free(store->engine, pcu); 
    696          
     761 
     762        g_static_rec_mutex_unlock (store->eng_lock); 
     763 
    697764        return status; 
    698765} 
     
    706773        char *errbuf = NULL; 
    707774        int status; 
    708          
     775 
    709776        session = camel_service_get_session (service); 
    710777 
     
    737804         
    738805        /* Now that we are in the TRANSACTION state, try regetting the capabilities */ 
     806 
     807        g_static_rec_mutex_lock (store->eng_lock); 
     808 
     809        if (store->engine == NULL) { 
     810                g_static_rec_mutex_unlock (store->eng_lock); 
     811                return FALSE; 
     812        } 
     813 
    739814        store->engine->state = CAMEL_POP3_ENGINE_TRANSACTION; 
    740815        camel_pop3_engine_reget_capabilities (store->engine); 
    741          
     816 
     817        g_static_rec_mutex_unlock (store->eng_lock); 
     818 
    742819        return TRUE; 
    743820} 
     
    747824{ 
    748825        CamelPOP3Store *store = CAMEL_POP3_STORE (service); 
    749          
     826 
     827        g_static_rec_mutex_lock (store->eng_lock); 
     828        if (store->engine == NULL) { 
     829                g_static_rec_mutex_unlock (store->eng_lock); 
     830                return TRUE; 
     831        } 
     832 
    750833        if (clean) { 
    751834                CamelPOP3Command *pc; 
     
    757840        } 
    758841 
    759         g_static_rec_mutex_lock (store->eng_lock); 
    760842        camel_object_unref((CamelObject *)store->engine); 
    761843        store->engine = NULL;