diff options
author | Not Zed <NotZed@HelixCode.com> | 2000-12-24 08:46:20 +0800 |
---|---|---|
committer | Michael Zucci <zucchi@src.gnome.org> | 2000-12-24 08:46:20 +0800 |
commit | 6de256c2a2b23f30d35e4a2213ad5839bf141d06 (patch) | |
tree | a34d8be64c0718070c4e1ea9548282912f37b387 /camel/providers/nntp | |
parent | 6183d89039ba67a7f3869f460c13aff09a548471 (diff) | |
download | gsoc2013-evolution-6de256c2a2b23f30d35e4a2213ad5839bf141d06.tar gsoc2013-evolution-6de256c2a2b23f30d35e4a2213ad5839bf141d06.tar.gz gsoc2013-evolution-6de256c2a2b23f30d35e4a2213ad5839bf141d06.tar.bz2 gsoc2013-evolution-6de256c2a2b23f30d35e4a2213ad5839bf141d06.tar.lz gsoc2013-evolution-6de256c2a2b23f30d35e4a2213ad5839bf141d06.tar.xz gsoc2013-evolution-6de256c2a2b23f30d35e4a2213ad5839bf141d06.tar.zst gsoc2013-evolution-6de256c2a2b23f30d35e4a2213ad5839bf141d06.zip |
Lock the command channel while searching. (imap_body_contains): If
2000-12-24 Not Zed <NotZed@HelixCode.com>
* providers/imap/camel-imap-search.c (imap_body_contains): Lock
the command channel while searching.
(imap_body_contains): If performing a whole uid search, then add
references to our own summary items, dont look it up in the
folder. This way they can't vanish unexpectedly.
* providers/imap/camel-imap-folder.h (CamelImapFolder): Added a
private field.
* providers/imap/camel-imap-private.h: Added lock for imap
searches.
* Merge from camel-mt-branch.
* providers/imap/camel-imap-folder.c (imap_update_summary): Merge
fix, use the folder->summary.
(imap_get_message_flags, imap_set_message_flags,
imap_get_message_user_flag, imap_set_message_user_flag): Removed
again.
(camel_imap_folder_init): Setup private data/lock.
(imap_finalize): Free private data/search lock.
(imap_search_free): Lock the search_lock.
(imap_search_by_expression): Lock the search lock when using the
search object. Also copy/ref hte summary, rather than getting it
directly.
(imap_refresh_info): Free any info lookups. Use folder->summary
not imap_folder->summary. And lock around commands.
svn path=/trunk/; revision=7150
Diffstat (limited to 'camel/providers/nntp')
-rw-r--r-- | camel/providers/nntp/camel-nntp-folder.c | 87 | ||||
-rw-r--r-- | camel/providers/nntp/camel-nntp-newsrc.c | 96 |
2 files changed, 93 insertions, 90 deletions
diff --git a/camel/providers/nntp/camel-nntp-folder.c b/camel/providers/nntp/camel-nntp-folder.c index f918317502..7edc4a98fd 100644 --- a/camel/providers/nntp/camel-nntp-folder.c +++ b/camel/providers/nntp/camel-nntp-folder.c @@ -63,7 +63,7 @@ nntp_folder_sync (CamelFolder *folder, gboolean expunge, { CamelNNTPStore *store; - camel_folder_summary_save (CAMEL_NNTP_FOLDER(folder)->summary); + camel_folder_summary_save (folder->summary); store = CAMEL_NNTP_STORE (camel_folder_get_parent_store (folder)); @@ -71,39 +71,12 @@ nntp_folder_sync (CamelFolder *folder, gboolean expunge, camel_nntp_newsrc_write (store->newsrc); } -static gint -nntp_folder_get_message_count (CamelFolder *folder) -{ - CamelNNTPFolder *nntp_folder = CAMEL_NNTP_FOLDER(folder); - - g_assert (folder); - g_assert (nntp_folder->summary); - - return camel_folder_summary_count(nntp_folder->summary); -} - -static guint32 -nntp_folder_get_message_flags (CamelFolder *folder, const char *uid) -{ - CamelNNTPFolder *nntp_folder = CAMEL_NNTP_FOLDER (folder); - CamelMessageInfo *info = camel_folder_summary_uid (nntp_folder->summary, uid); - - return info->flags; -} - static void nntp_folder_set_message_flags (CamelFolder *folder, const char *uid, guint32 flags, guint32 set) { - CamelNNTPFolder *nntp_folder = CAMEL_NNTP_FOLDER (folder); - CamelMessageInfo *info = camel_folder_summary_uid (nntp_folder->summary, uid); - guint32 new; - - new = (info->flags & ~flags) | (set & flags); - if (new == info->flags) - return; + ((CamelFolderClass *)parent_class)->set_message_flags(folder, uid, flags, set); - info->flags = new; if (flags & set & CAMEL_MESSAGE_SEEN) { int article_num; CamelNNTPStore *nntp_store = CAMEL_NNTP_STORE (camel_folder_get_parent_store (folder)); @@ -114,8 +87,6 @@ nntp_folder_set_message_flags (CamelFolder *folder, const char *uid, folder->name, article_num); } - - camel_folder_summary_touch (nntp_folder->summary); } static CamelMimeMessage * @@ -151,6 +122,9 @@ nntp_folder_get_message (CamelFolder *folder, const gchar *uid, CamelException * return NULL; } + /* this could probably done fairly easily with an nntp stream that + returns eof after '.' */ + /* XXX ick ick ick. read the entire message into a buffer and then create a stream_mem for it. */ buf_alloc = 2048; @@ -206,34 +180,6 @@ nntp_folder_get_message (CamelFolder *folder, const gchar *uid, CamelException * return message; } -static GPtrArray * -nntp_folder_get_uids (CamelFolder *folder) -{ - CamelNNTPFolder *nntp_folder = CAMEL_NNTP_FOLDER (folder); - GPtrArray *out; - CamelMessageInfo *message_info; - int i; - int count = camel_folder_summary_count (nntp_folder->summary); - - out = g_ptr_array_new (); - g_ptr_array_set_size (out, count); - - for (i = 0; i < count; i++) { - message_info = camel_folder_summary_index (nntp_folder->summary, i); - out->pdata[i] = g_strdup (camel_message_info_uid(message_info)); - } - - return out; -} - -static GPtrArray * -nntp_folder_get_summary (CamelFolder *folder) -{ - CamelNNTPFolder *nntp_folder = CAMEL_NNTP_FOLDER (folder); - - return nntp_folder->summary->messages; -} - static GPtrArray* nntp_folder_search_by_expression (CamelFolder *folder, const char *expression, CamelException *ex) { @@ -241,14 +187,6 @@ nntp_folder_search_by_expression (CamelFolder *folder, const char *expression, C return NULL; } -static const CamelMessageInfo* -nntp_folder_get_message_info (CamelFolder *folder, const char *uid) -{ - CamelNNTPFolder *nntp_folder = CAMEL_NNTP_FOLDER (folder); - - return camel_folder_summary_uid (nntp_folder->summary, uid); -} - static void nntp_folder_finalize (CamelObject *object) { @@ -268,16 +206,9 @@ camel_nntp_folder_class_init (CamelNNTPFolderClass *camel_nntp_folder_class) /* virtual method overload */ camel_folder_class->sync = nntp_folder_sync; - camel_folder_class->get_message_count = nntp_folder_get_message_count; camel_folder_class->set_message_flags = nntp_folder_set_message_flags; - camel_folder_class->get_message_flags = nntp_folder_get_message_flags; camel_folder_class->get_message = nntp_folder_get_message; - camel_folder_class->get_uids = nntp_folder_get_uids; - camel_folder_class->free_uids = camel_folder_free_deep; - camel_folder_class->get_summary = nntp_folder_get_summary; - camel_folder_class->free_summary = camel_folder_free_nop; camel_folder_class->search_by_expression = nntp_folder_search_by_expression; - camel_folder_class->get_message_info = nntp_folder_get_message_info; } CamelType @@ -313,11 +244,11 @@ camel_nntp_folder_new (CamelStore *parent, const char *folder_name, CamelExcepti root_dir_path, folder->name); - nntp_folder->summary = camel_folder_summary_new (); - camel_folder_summary_set_filename (nntp_folder->summary, + folder->summary = camel_folder_summary_new (); + camel_folder_summary_set_filename (folder->summary, nntp_folder->summary_file_path); - if (-1 == camel_folder_summary_load (nntp_folder->summary)) { + if (-1 == camel_folder_summary_load (folder->summary)) { /* Bad or nonexistant summary file */ camel_nntp_get_headers (CAMEL_FOLDER( folder )->parent_store, nntp_folder, ex); @@ -327,7 +258,7 @@ camel_nntp_folder_new (CamelStore *parent, const char *folder_name, CamelExcepti } /* XXX check return value */ - camel_folder_summary_save (nntp_folder->summary); + camel_folder_summary_save (folder->summary); } return folder; diff --git a/camel/providers/nntp/camel-nntp-newsrc.c b/camel/providers/nntp/camel-nntp-newsrc.c index b474dd3a40..d0b56222cf 100644 --- a/camel/providers/nntp/camel-nntp-newsrc.c +++ b/camel/providers/nntp/camel-nntp-newsrc.c @@ -32,6 +32,16 @@ #include "camel-nntp-newsrc.h" #include <camel/camel-folder-summary.h> +#ifdef ENABLE_THREADS +#include <pthread.h> + +#define NEWSRC_LOCK(f, l) (g_mutex_lock(((CamelNNTPNewsrc *)f)->l)) +#define NEWSRC_UNLOCK(f, l) (g_mutex_unlock(((CamelNNTPNewsrc *)f)->l)) +#else +#define NEWSRC_LOCK(f, l) +#define NEWSRC_UNLOCK(f, l) +#endif + typedef struct { guint low; guint high; @@ -47,8 +57,12 @@ struct CamelNNTPNewsrc { gchar *filename; GHashTable *groups; gboolean dirty; +#ifdef ENABLE_THREADS + GMutex *lock; +#endif } ; + static NewsrcGroup * camel_nntp_newsrc_group_add (CamelNNTPNewsrc *newsrc, const char *group_name, gboolean subscribed) { @@ -180,26 +194,40 @@ int camel_nntp_newsrc_get_highest_article_read (CamelNNTPNewsrc *newsrc, const char *group_name) { NewsrcGroup *group; + int ret; + + NEWSRC_LOCK(newsrc, lock); group = g_hash_table_lookup (newsrc->groups, group_name); + ret = camel_nntp_newsrc_group_get_highest_article_read (newsrc, group); + + NEWSRC_UNLOCK(newsrc, lock); - return camel_nntp_newsrc_group_get_highest_article_read (newsrc, group); + return ret; } int camel_nntp_newsrc_get_num_articles_read (CamelNNTPNewsrc *newsrc, const char *group_name) { NewsrcGroup *group; + int ret; + + NEWSRC_LOCK(newsrc, lock); group = g_hash_table_lookup (newsrc->groups, group_name); + ret = camel_nntp_newsrc_group_get_num_articles_read (newsrc, group); + + NEWSRC_UNLOCK(newsrc, lock); - return camel_nntp_newsrc_group_get_num_articles_read (newsrc, group); + return ret; } void camel_nntp_newsrc_mark_article_read (CamelNNTPNewsrc *newsrc, const char *group_name, int num) { + NEWSRC_LOCK(newsrc, lock); camel_nntp_newsrc_mark_range_read (newsrc, group_name, num, num); + NEWSRC_UNLOCK(newsrc, lock); } void @@ -216,9 +244,11 @@ camel_nntp_newsrc_mark_range_read(CamelNNTPNewsrc *newsrc, const char *group_nam low = tmp; } + NEWSRC_LOCK(newsrc, lock); group = g_hash_table_lookup (newsrc->groups, group_name); camel_nntp_newsrc_group_mark_range_read (newsrc, group, low, high); + NEWSRC_UNLOCK(newsrc, lock); } gboolean @@ -226,36 +256,51 @@ camel_nntp_newsrc_article_is_read (CamelNNTPNewsrc *newsrc, const char *group_na { int i; NewsrcGroup *group; + int ret = FALSE; + NEWSRC_LOCK(newsrc, lock); group = g_hash_table_lookup (newsrc->groups, group_name); for (i = 0; i < group->ranges->len; i++) { if (num >= g_array_index (group->ranges, ArticleRange, i).low && num <= g_array_index (group->ranges, ArticleRange, i).high) { - return TRUE; + ret = TRUE; + break; } } + NEWSRC_UNLOCK(newsrc, lock); + return FALSE; } gboolean camel_nntp_newsrc_group_is_subscribed (CamelNNTPNewsrc *newsrc, const char *group_name) { - NewsrcGroup *group = g_hash_table_lookup (newsrc->groups, group_name); + NewsrcGroup *group; + int ret = FALSE; + + NEWSRC_LOCK(newsrc, lock); + + group = g_hash_table_lookup (newsrc->groups, group_name); if (group) { - return group->subscribed; - } - else { - return FALSE; + ret = group->subscribed; } + + NEWSRC_UNLOCK(newsrc, lock); + + return ret; } void camel_nntp_newsrc_subscribe_group (CamelNNTPNewsrc *newsrc, const char *group_name) { - NewsrcGroup *group = g_hash_table_lookup (newsrc->groups, group_name); + NewsrcGroup *group; + + NEWSRC_LOCK(newsrc, lock); + + group = g_hash_table_lookup (newsrc->groups, group_name); if (group) { if (!group->subscribed) @@ -265,13 +310,18 @@ camel_nntp_newsrc_subscribe_group (CamelNNTPNewsrc *newsrc, const char *group_na else { camel_nntp_newsrc_group_add (newsrc, group_name, TRUE); } + + NEWSRC_UNLOCK(newsrc, lock); } void camel_nntp_newsrc_unsubscribe_group (CamelNNTPNewsrc *newsrc, const char *group_name) { - NewsrcGroup *group = g_hash_table_lookup (newsrc->groups, group_name); + NewsrcGroup *group; + + NEWSRC_LOCK(newsrc, lock); + group = g_hash_table_lookup (newsrc->groups, group_name); if (group) { if (group->subscribed) newsrc->dirty = TRUE; @@ -280,6 +330,8 @@ camel_nntp_newsrc_unsubscribe_group (CamelNNTPNewsrc *newsrc, const char *group_ else { camel_nntp_newsrc_group_add (newsrc, group_name, FALSE); } + + NEWSRC_UNLOCK(newsrc, lock); } struct newsrc_ptr_array { @@ -287,6 +339,7 @@ struct newsrc_ptr_array { gboolean subscribed_only; }; +/* this needs to strdup the grup_name, if the group array is likely to change */ static void get_group_foreach (char *group_name, NewsrcGroup *group, struct newsrc_ptr_array *npa) { @@ -302,12 +355,16 @@ camel_nntp_newsrc_get_subscribed_group_names (CamelNNTPNewsrc *newsrc) g_return_val_if_fail (newsrc, NULL); + NEWSRC_LOCK(newsrc, lock); + npa.ptr_array = g_ptr_array_new(); npa.subscribed_only = TRUE; g_hash_table_foreach (newsrc->groups, (GHFunc)get_group_foreach, &npa); + NEWSRC_UNLOCK(newsrc, lock); + return npa.ptr_array; } @@ -318,12 +375,16 @@ camel_nntp_newsrc_get_all_group_names (CamelNNTPNewsrc *newsrc) g_return_val_if_fail (newsrc, NULL); + NEWSRC_LOCK(newsrc, lock); + npa.ptr_array = g_ptr_array_new(); npa.subscribed_only = FALSE; g_hash_table_foreach (newsrc->groups, (GHFunc)get_group_foreach, &npa); + NEWSRC_UNLOCK(newsrc, lock); + return npa.ptr_array; } @@ -395,9 +456,13 @@ camel_nntp_newsrc_write_to_file(CamelNNTPNewsrc *newsrc, FILE *fp) newsrc_fp.newsrc = newsrc; newsrc_fp.fp = fp; + NEWSRC_LOCK(newsrc, lock); + g_hash_table_foreach (newsrc->groups, (GHFunc)camel_nntp_newsrc_write_group_line, &newsrc_fp); + + NEWSRC_UNLOCK(newsrc, lock); } void @@ -407,17 +472,21 @@ camel_nntp_newsrc_write(CamelNNTPNewsrc *newsrc) g_return_if_fail (newsrc); + NEWSRC_LOCK(newsrc, lock); + if (!newsrc->dirty) return; if ((fp = fopen(newsrc->filename, "w")) == NULL) { g_warning ("Couldn't open newsrc file '%s'.\n", newsrc->filename); + NEWSRC_UNLOCK(newsrc, lock); return; } - camel_nntp_newsrc_write_to_file(newsrc, fp); - newsrc->dirty = FALSE; + NEWSRC_UNLOCK(newsrc, lock); + + camel_nntp_newsrc_write_to_file(newsrc, fp); fclose(fp); } @@ -535,6 +604,9 @@ camel_nntp_newsrc_read_for_server (const char *server) newsrc = g_new0(CamelNNTPNewsrc, 1); newsrc->filename = filename; newsrc->groups = g_hash_table_new (g_str_hash, g_str_equal); +#ifdef ENABLE_THREADS + newsrc->lock = g_mutex_new(); +#endif if ((fd = open(filename, O_RDONLY)) == -1) { g_warning ("~/.newsrc-%s not present.\n", server); |