Changeset 2142

Show
Ignore:
Timestamp:
06/13/07 09:17:12
Author:
pvanhoof
Message:

Added some locks

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/ChangeLog

    r2140 r2142  
     12007-06-13  Philip Van Hoof  <pvanhoof@gnome.org> 
     2 
     3        * Added some extra locking into the camel-lite's POP3 code 
     4 
    152007-06-13  Philip Van Hoof  <pvanhoof@gnome.org> 
    26 
  • trunk/libtinymail-camel/camel-lite/camel/camel-mime-parser.c

    r1943 r2142  
    13051305{ 
    13061306        int atleast = s->atleast, newatleast; 
    1307         register char *inptr
     1307        register char *inptr=NULL
    13081308        char *inend; 
    13091309        char *start; 
  • trunk/libtinymail-camel/camel-lite/camel/providers/pop3/camel-pop3-engine.c

    r2139 r2142  
    6161camel_pop3_engine_init(CamelPOP3Engine *pe, CamelPOP3EngineClass *peclass) 
    6262{ 
     63        pe->lock = g_new0 (GStaticRecMutex, 1); 
     64        g_static_rec_mutex_init (pe->lock); 
     65 
    6366        e_dlist_init(&pe->active); 
    6467        e_dlist_init(&pe->queue); 
     
    7174{ 
    7275        /* FIXME: Also flush/free any outstanding requests, etc */ 
     76 
     77        g_static_rec_mutex_lock (pe->lock); 
    7378 
    7479        if (pe->stream) 
     
    7883        if (pe->apop) 
    7984                g_free(pe->apop); 
     85 
     86        g_static_rec_mutex_unlock (pe->lock); 
     87 
     88        g_static_rec_mutex_free (pe->lock); 
     89        pe->lock = NULL; 
    8090} 
    8191 
     
    106116        unsigned char *line, *apop, *apopend; 
    107117        unsigned int len; 
    108          
     118 
     119 
     120        g_static_rec_mutex_lock (pe->lock); 
     121 
    109122        /* first, read the greeting */ 
    110123        if (camel_pop3_stream_line (pe->stream, &line, &len) == -1 
    111             || strncmp ((char *) line, "+OK", 3) != 0) 
     124            || strncmp ((char *) line, "+OK", 3) != 0) { 
     125                g_static_rec_mutex_unlock (pe->lock); 
    112126                return -1; 
    113          
     127        } 
     128 
    114129        if ((apop = (unsigned char *) strchr ((char *) line + 3, '<')) 
    115130            && (apopend = (unsigned char *) strchr ((char *) apop, '>'))) { 
     
    121136         
    122137        pe->auth = g_list_prepend (pe->auth, &camel_pop3_password_authtype); 
    123          
     138 
     139        g_static_rec_mutex_unlock (pe->lock); 
     140 
    124141        return 0; 
    125142} 
     
    141158 
    142159        pe = (CamelPOP3Engine *)camel_object_new(camel_pop3_engine_get_type ()); 
     160 
     161        g_static_rec_mutex_lock (pe->lock); 
    143162 
    144163        pe->stream = (CamelPOP3Stream *)camel_pop3_stream_new(source); 
     
    147166         
    148167        if (read_greeting (pe) == -1) { 
     168                g_static_rec_mutex_unlock (pe->lock); 
    149169                camel_object_unref (pe); 
    150170                return NULL; 
    151171        } 
    152          
     172 
    153173        get_capabilities (pe); 
    154          
     174        g_static_rec_mutex_unlock (pe->lock); 
     175 
    155176        return pe; 
    156177} 
     
    167188{ 
    168189        g_return_if_fail (CAMEL_IS_POP3_ENGINE (engine)); 
    169          
     190 
     191        g_static_rec_mutex_lock (engine->lock); 
    170192        get_capabilities (engine); 
     193        g_static_rec_mutex_unlock (engine->lock); 
    171194} 
    172195 
     
    193216        int i; 
    194217        CamelServiceAuthType *auth; 
     218 
     219        g_static_rec_mutex_lock (pe->lock); 
    195220 
    196221        dd(printf("cmd_capa\n")); 
     
    223248                } 
    224249        } while (ret>0); 
     250 
     251        g_static_rec_mutex_unlock (pe->lock); 
    225252} 
    226253 
     
    229256{ 
    230257        CamelPOP3Command *pc; 
    231          
     258 
     259        g_static_rec_mutex_lock (pe->lock); 
     260 
    232261        if (!(pe->flags & CAMEL_POP3_ENGINE_DISABLE_EXTENSIONS)) { 
    233262                pc = camel_pop3_engine_command_new(pe, CAMEL_POP3_COMMAND_MULTI, cmd_capa, NULL, "CAPA\r\n"); 
     
    248277                } 
    249278        } 
     279 
     280        g_static_rec_mutex_unlock (pe->lock); 
     281 
    250282} 
    251283 
     
    255287{ 
    256288 
    257 #warning FIXME 
    258         if (!pe) { 
    259                 g_warning ("FIXME: pe == NULL in %s", __FUNCTION__); 
    260                 return FALSE; 
    261         } 
     289        g_static_rec_mutex_lock (pe->lock); 
    262290 
    263291        if (((pe->capa & CAMEL_POP3_CAP_PIPE) == 0 || (pe->sentlen + strlen(pc->data)) > CAMEL_POP3_SEND_LIMIT) 
    264292            && pe->current != NULL) { 
    265293                e_dlist_addtail(&pe->queue, (EDListNode *)pc); 
     294                g_static_rec_mutex_unlock (pe->lock); 
    266295                return FALSE; 
    267         } else { 
    268                 /* ??? */ 
    269  
    270                 /* TNY TODO: Check online status here, else it will crash  
    271                         Correction, it will not crash but will emit a SIGPIPE */ 
    272  
    273                 if (camel_stream_write((CamelStream *)pe->stream, pc->data, strlen(pc->data)) == -1) { 
    274                         e_dlist_addtail(&pe->queue, (EDListNode *)pc); 
    275                         return FALSE; 
    276                 } 
    277  
    278                 pe->sentlen += strlen(pc->data); 
    279  
    280                 pc->state = CAMEL_POP3_COMMAND_DISPATCHED; 
    281  
    282                 if (pe->current == NULL) 
    283                         pe->current = pc; 
    284                 else 
    285                         e_dlist_addtail(&pe->active, (EDListNode *)pc); 
    286  
    287                 return TRUE; 
    288         } 
     296        } 
     297 
     298        /* TNY TODO: Check online status here, else it will crash  
     299                Correction, it will not crash but will emit a SIGPIPE */ 
     300 
     301        if (camel_stream_write((CamelStream *)pe->stream, pc->data, strlen(pc->data)) == -1) { 
     302                e_dlist_addtail(&pe->queue, (EDListNode *)pc); 
     303                g_static_rec_mutex_unlock (pe->lock); 
     304                return FALSE; 
     305        } 
     306 
     307        pe->sentlen += strlen(pc->data); 
     308 
     309        pc->state = CAMEL_POP3_COMMAND_DISPATCHED; 
     310 
     311        if (pe->current == NULL) 
     312                pe->current = pc; 
     313        else 
     314                e_dlist_addtail(&pe->active, (EDListNode *)pc); 
     315 
     316        g_static_rec_mutex_unlock (pe->lock); 
     317 
     318        return TRUE; 
    289319} 
    290320 
     
    297327        CamelPOP3Command *pc, *pw, *pn; 
    298328 
    299 #warning FIXME 
    300         if (!pe) { 
    301                 g_warning ("FIXME: pe == NULL in %s", __FUNCTION__); 
     329        g_static_rec_mutex_lock (pe->lock); 
     330 
     331        if (pcwait && pcwait->state >= CAMEL_POP3_COMMAND_OK) { 
     332                g_static_rec_mutex_unlock (pe->lock); 
    302333                return 0; 
    303334        } 
    304          
    305         if (pcwait && pcwait->state >= CAMEL_POP3_COMMAND_OK) 
     335 
     336        pc = pe->current; 
     337        if (pc == NULL) { 
     338                g_static_rec_mutex_unlock (pe->lock); 
    306339                return 0; 
    307  
    308         pc = pe->current; 
    309         if (pc == NULL) 
    310                 return 0; 
    311  
    312         /* LOCK */ 
     340        } 
    313341 
    314342        if (camel_pop3_stream_line(pe->stream, &pe->line, &pe->linelen) == -1) 
     
    349377        } 
    350378 
    351         e_dlist_addtail(&pe->done, (EDListNode *)pc); 
     379        if (pc) 
     380                e_dlist_addtail(&pe->done, (EDListNode *)pc); 
     381        else 
     382                g_warning ("Unexpected, pc == NULL"); 
    352383 
    353384        if (pc && pc->data) 
     
    362393        pw = (CamelPOP3Command *)pe->queue.head; 
    363394        pn = pw->next; 
    364         while (pn) { 
     395 
     396        while (pn)  
     397        { 
    365398                if (((pe->capa & CAMEL_POP3_CAP_PIPE) == 0 || (pe->sentlen + strlen(pw->data)) > CAMEL_POP3_SEND_LIMIT) 
    366399                    && pe->current != NULL) 
     
    384417        } 
    385418 
    386         /* UNLOCK */ 
    387  
    388         if (pcwait && pcwait->state >= CAMEL_POP3_COMMAND_OK) 
     419        if (pcwait && pcwait->state >= CAMEL_POP3_COMMAND_OK) { 
     420                g_static_rec_mutex_unlock (pe->lock); 
    389421                return 0; 
    390  
     422        } 
     423 
     424        g_static_rec_mutex_unlock (pe->lock); 
    391425        return pe->current==NULL?0:1; 
     426 
    392427ioerror: 
    393428        /* we assume all outstanding commands are gunna fail now */ 
     
    408443        } 
    409444 
     445        g_static_rec_mutex_unlock (pe->lock); 
    410446        return -1; 
    411447} 
     
    435471camel_pop3_engine_command_free(CamelPOP3Engine *pe, CamelPOP3Command *pc) 
    436472{ 
    437         #warning FIXME 
    438         if (!pe) { 
    439                 g_warning ("FIXME: pe == NULL in %s", __FUNCTION__); 
    440                 return; 
    441         } 
    442          
     473        g_static_rec_mutex_lock (pe->lock); 
    443474        if (pe->current != pc) 
    444475                e_dlist_remove((EDListNode *)pc); 
    445         g_free(pc->data); 
     476        g_free(pc->data); pc->data = NULL; 
    446477        g_free(pc); 
    447 
     478        g_static_rec_mutex_unlock (pe->lock); 
     479
  • trunk/libtinymail-camel/camel-lite/camel/providers/pop3/camel-pop3-engine.h

    r1943 r2142  
    118118        void *store; gboolean partial_happening; 
    119119        gint type; gint param; 
     120 
     121        GStaticRecMutex *lock; 
    120122}; 
    121123