Changeset 1521

Show
Ignore:
Timestamp:
01/30/07 20:19:03
Author:
pvanhoof
Message:

Code cleanup

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/ChangeLog

    r1517 r1521  
    22 
    33        * Little bugfix. Max line size of an E-mail is now MAX_LINE_SIZE 
     4        * Cleaning up old code, fixing bug in the tny-session-camel.c 
    45 
    562007-01-29 Dirk-Jan C. Binnema <dirk-jan.binnema@nokia.com> 
  • trunk/libtinymail-camel/camel-lite/camel/camel-service.c

    r1025 r1521  
    9292{ 
    9393        CamelService *service = o; 
    94          
     94 
     95        service->data = NULL; 
    9596        service->priv = g_malloc0(sizeof(*service->priv)); 
    9697        g_static_rec_mutex_init(&service->priv->connect_lock); 
     
    119120        if (service->session) 
    120121                camel_object_unref (service->session); 
    121          
     122        service->data = NULL; 
     123 
    122124        g_static_rec_mutex_free (&service->priv->connect_lock); 
    123125        g_static_mutex_free (&service->priv->connect_op_lock); 
  • trunk/libtinymail-camel/camel-lite/camel/camel-service.h

    r1014 r1521  
    7373        CamelOperation *connect_op; 
    7474        CamelURL *url; 
     75        gpointer data; 
    7576}; 
    7677 
  • trunk/libtinymail-camel/tny-camel-account.c

    r1500 r1521  
    473473        g_static_rec_mutex_lock (priv->service_lock); 
    474474 
    475         tny_session_camel_set_pass_func (priv->session, self, get_pass_func); 
    476475        priv->get_pass_func = get_pass_func; 
    477476        priv->pass_func_set = TRUE; 
     
    497496        g_static_rec_mutex_lock (priv->service_lock); 
    498497 
    499         tny_session_camel_set_forget_pass_func (priv->session, self, get_forget_pass_func); 
    500498        priv->forget_pass_func = get_forget_pass_func; 
    501499        priv->forget_pass_func_set = TRUE; 
     
    671669        TnyCamelAccountPriv *priv = TNY_CAMEL_ACCOUNT_GET_PRIVATE (self); 
    672670 
     671        priv->get_pass_func = NULL; 
     672        priv->forget_pass_func = NULL; 
    673673        priv->port = -1; 
    674674        priv->cache_location = NULL; 
  • trunk/libtinymail-camel/tny-camel-store-account.c

    r1511 r1521  
    118118        if (apriv->session) 
    119119        { 
     120                CamelService *oservice = apriv->service; 
     121 
    120122                if (camel_exception_is_set (apriv->ex)) 
    121123                        camel_exception_clear (apriv->ex); 
    122  
    123                 if (apriv->service)  
    124                 { 
    125                         camel_object_unref (CAMEL_OBJECT (apriv->service)); 
    126                         apriv->service = NULL; 
    127                 } 
    128124 
    129125                apriv->service = camel_session_get_service 
    130126                        ((CamelSession*) apriv->session, apriv->url_string,  
    131127                        apriv->type, apriv->ex); 
     128 
     129                if (apriv->service) 
     130                        apriv->service->data = self; 
    132131 
    133132        } else { 
  • trunk/libtinymail-camel/tny-camel-transport-account.c

    r1490 r1521  
    122122        if (apriv->session) 
    123123        { 
     124                CamelService *oservice = apriv->service; 
     125 
    124126                if (camel_exception_is_set (apriv->ex)) 
    125127                        camel_exception_clear (apriv->ex); 
    126  
    127                 if (apriv->service)  
    128                 { 
    129                         camel_object_unref (CAMEL_OBJECT (apriv->service)); 
    130                         apriv->service = NULL; 
    131                 } 
    132128 
    133129                apriv->service = camel_session_get_service 
    134130                        ((CamelSession*) apriv->session, apriv->url_string,  
    135131                        apriv->type, apriv->ex); 
     132 
     133                if (apriv->service) 
     134                        apriv->service->data = self; 
    136135 
    137136        } else { 
  • trunk/libtinymail-camel/tny-session-camel-priv.h

    r1511 r1521  
    1111        gchar *camel_dir; 
    1212        gboolean in_auth_function, is_connecting; 
     13        gboolean async_connect; 
    1314        TnyLockable *ui_lock; 
    1415        GMutex *conlock; 
     
    1617}; 
    1718 
     19void _tny_session_camel_fixup (TnySessionCamel *self, CamelService *oservice, TnyAccount *account); 
    1820void _tny_session_camel_add_account (TnySessionCamel *self, TnyCamelAccount *account); 
    1921void _tny_session_camel_forget_account (TnySessionCamel *self, TnyCamelAccount *account); 
  • trunk/libtinymail-camel/tny-session-camel.c

    r1511 r1521  
    5555 
    5656static CamelSessionClass *ms_parent_class; 
    57 static GList *password_funcs = NULL; 
    58 static GList *forget_password_funcs = NULL; 
    59  
    60 typedef struct 
    61 { 
    62         CamelService *service; 
    63         TnyGetPassFunc func; 
    64         TnyAccount *account; 
    65  
    66 } PrivPassFunc; 
    67  
    68 typedef struct 
    69 { 
    70         CamelService *service; 
    71         TnyForgetPassFunc func; 
    72         TnyAccount *account; 
    73  
    74 } PrivForgetPassFunc; 
    75  
    76 static void 
    77 tny_session_camel_forget_password (CamelSession *session, CamelService *service, const char *domain, const char *item, CamelException *ex); 
    78  
    79 /** 
    80  * tny_session_camel_set_forget_pass_func: 
    81  * @self: a #TnySessionCamel object 
    82  * @account: the #TnyAccount account instance 
    83  * @get_forget_pass_func: The function that will forget the password for the account 
    84  * 
    85  * For each account you can set a password handler. This makes it possible to 
    86  * use your own password-store implementation for storing passwords. You set 
    87  * the handler that tells that store to forget the password, using this method. 
    88  * 
    89  * It's recommended to also memset (buffer, 0, len) the memory where the 
    90  * password was stored. You can do it in the forget_pass_func handler. 
    91  * 
    92  **/ 
    93 void 
    94 tny_session_camel_set_forget_pass_func (TnySessionCamel *self, TnyAccount *account, TnyForgetPassFunc get_forget_pass_func) 
    95 { 
    96         GList *copy = forget_password_funcs, *mark_del = NULL; 
    97         PrivForgetPassFunc *pf; 
    98         gboolean found = FALSE; 
    99         CamelService *service = (CamelService*)_tny_camel_account_get_service (TNY_CAMEL_ACCOUNT (account)); 
    100  
    101         while (G_LIKELY (copy)) 
    102         { 
    103                 pf = copy->data; 
    104  
    105                 if (G_UNLIKELY (pf->service == NULL) || G_UNLIKELY (pf->account == NULL)) 
    106                 { 
    107                         mark_del = g_list_prepend (mark_del, copy); 
    108                         copy = g_list_next (copy); 
    109                         continue; 
    110                 } 
    111  
    112                 if (G_UNLIKELY (pf->service == service)) 
    113                 { 
    114                         found = TRUE; 
    115                         break; 
    116                 } 
    117  
    118                 copy = g_list_next (copy); 
    119         } 
    120  
    121         if (G_UNLIKELY (!found)) 
    122                 pf = g_new0 (PrivForgetPassFunc, 1); 
    123  
    124         pf->account = account; 
    125         pf->func = get_forget_pass_func; 
    126         pf->service = service; 
    127  
    128         if (G_UNLIKELY (!found)) 
    129                 forget_password_funcs = g_list_prepend (forget_password_funcs, pf); 
    130  
    131         if (G_UNLIKELY (mark_del))  
    132         { 
    133                 while (G_LIKELY (mark_del)) 
    134                 { 
    135                         forget_password_funcs = g_list_remove (forget_password_funcs, mark_del->data); 
    136                         mark_del = g_list_next (mark_del); 
    137                 } 
    138  
    139                 g_list_free (mark_del); 
    140         } 
    141  
    142         return; 
    143 } 
    144  
    145 /** 
    146  * tny_session_camel_set_pass_func: 
    147  * @self: a #TnySessionCamel object 
    148  * @account: the #TnyAccount account instance 
    149  * @get_pass_func: The function that will return the password for the account 
    150  * 
    151  * For each account you can set a password handler. This makes it possible to 
    152  * use your own password-store implementation for storing passwords. You set 
    153  * that password handler method using this method. 
    154  * 
    155  **/ 
    156 void 
    157 tny_session_camel_set_pass_func (TnySessionCamel *self, TnyAccount *account, TnyGetPassFunc get_pass_func) 
    158 { 
    159         GList *copy = password_funcs, *mark_del = NULL; 
    160         PrivPassFunc *pf; 
    161         gboolean found = FALSE; 
    162         CamelService *service = (CamelService*)_tny_camel_account_get_service (TNY_CAMEL_ACCOUNT (account)); 
    163  
    164         while (G_LIKELY (copy)) 
    165         { 
    166                 pf = copy->data; 
    167  
    168                 if (G_UNLIKELY (pf->service == NULL) || G_UNLIKELY (pf->account == NULL) || 
    169                         !CAMEL_IS_SERVICE (pf->service) || !TNY_IS_ACCOUNT (pf->account)) 
    170                 { 
    171                         mark_del = g_list_prepend (mark_del, copy); 
    172                         copy = g_list_next (copy); 
    173                         continue; 
    174                 } 
    175  
    176                 if (G_UNLIKELY (pf->service == service)) 
    177                 { 
    178                         found = TRUE; 
    179                         break; 
    180                 } 
    181  
    182                 copy = g_list_next (copy); 
    183         } 
    184  
    185         if (G_UNLIKELY (!found)) 
    186                 pf = g_new0 (PrivPassFunc, 1); 
    187  
    188         pf->account = account; 
    189         pf->func = get_pass_func; 
    190         pf->service = service; 
    191  
    192         if (G_UNLIKELY (!found)) 
    193                 password_funcs = g_list_prepend (password_funcs, pf); 
    194  
    195         if (G_UNLIKELY (mark_del)) 
    196         { 
    197                 while (G_LIKELY (mark_del)) 
    198                 { 
    199                         password_funcs = g_list_remove (password_funcs, mark_del->data); 
    200                         mark_del = g_list_next (mark_del); 
    201                 } 
    202                 g_list_free (mark_del); 
    203         } 
    204  
    205         return; 
    206 } 
    20757 
    20858static char * 
     
    21363        TnySessionCamelPriv *priv = self->priv; 
    21464 
    215         GList *copy = password_funcs; 
    21665        TnyGetPassFunc func; 
    21766        TnyAccount *account; 
    218         gboolean found = FALSE, freeprmpt = FALSE, cancel = FALSE; 
     67        gboolean freeprmpt = FALSE, cancel = FALSE; 
    21968        gchar *retval = NULL, *prmpt = (gchar*)prompt; 
    220         GThread *thread; 
    221  
    222         while (G_LIKELY (copy)) 
    223         { 
    224                 PrivPassFunc *pf = copy->data; 
    225  
    226                 if (G_UNLIKELY (pf->service == service) && pf->account) 
    227                 { 
    228                         found = TRUE; 
    229                         func = pf->func; 
    230                         account = pf->account; 
    231                         break; 
    232                 } 
    233  
    234                 copy = g_list_next (copy); 
    235         } 
    236  
    237         if (G_LIKELY (found)) 
    238         { 
     69 
     70        account = service->data; 
     71        if (account) 
     72        { 
     73 
     74                func = tny_account_get_pass_func (account); 
     75 
     76                if (!func) 
     77                        return g_strdup (""); 
     78 
    23979                if (prmpt == NULL) 
    24080                { 
     
    266106        } 
    267107 
     108emptypass: 
     109 
    268110        return retval; 
    269111} 
     
    298140        TnySessionCamelPriv *priv = self->priv; 
    299141 
    300         GList *copy = forget_password_funcs; 
    301142        TnyForgetPassFunc func; 
    302143        TnyAccount *account; 
    303         gboolean found = FALSE; 
    304         GThread *thread; 
    305  
    306         while (G_LIKELY (copy)) 
    307         { 
    308                 PrivForgetPassFunc *pf = copy->data; 
    309  
    310                 if (G_UNLIKELY (pf->service == service) && pf->account) 
    311                 { 
    312                         found = TRUE; 
    313                         func = pf->func; 
    314                         account = pf->account; 
    315                         break; 
    316                 } 
    317                 copy = g_list_next (copy); 
    318         } 
    319  
    320         if (G_LIKELY (found)) 
    321         { 
     144 
     145        account = service->data; 
     146 
     147        if (account) 
     148        { 
     149                func = tny_account_get_forget_pass_func (account); 
     150 
     151                if (!func) 
     152                        return; 
     153 
    322154                tny_lockable_lock (self->priv->ui_lock); 
    323155                func (account); 
     
    490322} 
    491323 
     324/** 
     325 * tny_session_camel_set_async_connecting: 
     326 * @self: a #TnySessionCamel object 
     327 * @enable: Whether or not to asynchronously connect 
     328 * 
     329 * Set connection strategy 
     330 **/ 
     331void  
     332tny_session_camel_set_async_connecting (TnySessionCamel *self, gboolean enable) 
     333{ 
     334        g_mutex_lock (self->priv->conlock); 
     335        self->priv->async_connect = enable; 
     336        g_mutex_unlock (self->priv->conlock); 
     337} 
     338 
    492339 
    493340static void 
     
    507354        priv->in_auth_function = FALSE; 
    508355        priv->is_connecting = FALSE; 
     356        priv->async_connect = TRUE; 
     357 
    509358        return; 
    510359} 
     
    650499        camel_session_set_online ((CamelSession *) self, online);  
    651500 
    652         priv->conthread = g_thread_create (background_connect_thread, info, TRUE, NULL); 
    653  
    654         /* background_connect_thread (info); */ 
     501        if (priv->async_connect) 
     502                priv->conthread = g_thread_create (background_connect_thread, info, TRUE, NULL); 
     503        else 
     504                background_connect_thread (info); 
    655505 
    656506        return; 
  • trunk/libtinymail-camel/tny-session-camel.h

    r1501 r1521  
    4949CamelType tny_session_camel_get_type (void); 
    5050 
    51 void tny_session_camel_set_pass_func (TnySessionCamel *self, TnyAccount *account, TnyGetPassFunc get_pass_func); 
    52 void tny_session_camel_set_forget_pass_func (TnySessionCamel *self, TnyAccount *account, TnyForgetPassFunc get_forget_pass_func); 
    5351void tny_session_camel_set_account_store (TnySessionCamel *self, TnyAccountStore *account_store); 
    5452void tny_session_camel_set_device (TnySessionCamel *self, TnyDevice *device); 
    5553void tny_session_camel_set_ui_locker (TnySessionCamel *self, TnyLockable *ui_lock); 
    5654void tny_session_camel_join_connecting (TnySessionCamel *self); 
     55void tny_session_camel_set_async_connecting (TnySessionCamel *self, gboolean enable); 
    5756 
    5857G_END_DECLS 
  • trunk/tests/shared/account-store.c

    r1502 r1521  
    9090                                me->cache_dir = str; 
    9191                        att++; 
    92                 } while (dir != NULL);           
     92                } while (dir != NULL); 
    9393        } 
    9494     
     
    146146        } 
    147147 
     148        if (me->force_online) 
     149                tny_device_force_online (me->device); 
     150        else 
     151                tny_device_force_offline (me->device); 
     152 
    148153        return; 
    149154} 
     
    164169 
    165170        self->session = tny_session_camel_new (TNY_ACCOUNT_STORE (self)); 
     171        tny_session_camel_set_async_connecting (self->session, FALSE); 
     172 
    166173        self->force_online = force_online; 
    167174 
    168         if (self->force_online) 
    169                 tny_device_force_online (self->device); 
    170         else 
    171                 tny_device_force_offline (self->device); 
    172175 
    173176        return TNY_ACCOUNT_STORE (self);