aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbertrand <Bertrand.Guiheneuf@aful.org>1999-12-18 03:19:59 +0800
committerBertrand Guiheneuf <bertrand@src.gnome.org>1999-12-18 03:19:59 +0800
commit0c6cc80cdf8c85ee86b588c1d49d5cbd4fbe5e82 (patch)
tree81e907bd7f2cedeabfebecb28d12024ff2d6c513
parente69ca1a88ce35fb744a0b4233dc5305eaa145d2f (diff)
downloadgsoc2013-evolution-0c6cc80cdf8c85ee86b588c1d49d5cbd4fbe5e82.tar.gz
gsoc2013-evolution-0c6cc80cdf8c85ee86b588c1d49d5cbd4fbe5e82.tar.zst
gsoc2013-evolution-0c6cc80cdf8c85ee86b588c1d49d5cbd4fbe5e82.zip
use exception mechanism. (camel_folder_set_name): idem.
1999-12-17 bertrand <Bertrand.Guiheneuf@aful.org> * camel/camel-folder.c (_set_name): use exception mechanism. (camel_folder_set_name): idem. (camel_folder_set_full_name): idem. (_get_name): idem. (camel_folder_get_name): idem. (_get_full_name): idem. (camel_folder_get_full_name): idem. (_can_hold_folders): idem. (_can_hold_messages): idem. (_exists): idem. (camel_folder_exists): idem. (_is_open): idem. (_get_subfolder): idem. (camel_folder_get_subfolder): idem. * camel/camel-exception.c (camel_exception_clear): New function. Clear an exception. (camel_exception_get_id): New function. (camel_exception_get_description): New function. * camel/camel-folder.c (_set_name): Use the exception system. When the folder has no parent, don't set its full name field. svn path=/trunk/; revision=1499
-rw-r--r--ChangeLog31
-rw-r--r--camel/camel-exception-list.def2
-rw-r--r--camel/camel-exception.c74
-rw-r--r--camel/camel-exception.h13
-rw-r--r--camel/camel-folder.c192
5 files changed, 294 insertions, 18 deletions
diff --git a/ChangeLog b/ChangeLog
index 1a70104b0f..73bd4656ff 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,34 @@
+1999-12-17 bertrand <Bertrand.Guiheneuf@aful.org>
+
+ * camel/camel-folder.c (_set_name):
+ use exception mechanism.
+ (camel_folder_set_name): idem.
+ (camel_folder_set_full_name): idem.
+ (_get_name): idem.
+ (camel_folder_get_name): idem.
+ (_get_full_name): idem.
+ (camel_folder_get_full_name): idem.
+ (_can_hold_folders): idem.
+ (_can_hold_messages): idem.
+ (_exists): idem.
+ (camel_folder_exists): idem.
+ (_is_open): idem.
+ (_get_subfolder): idem.
+ (camel_folder_get_subfolder): idem.
+
+ * camel/camel-exception.c (camel_exception_clear):
+ New function. Clear an exception.
+ (camel_exception_get_id):
+ New function.
+ (camel_exception_get_description):
+ New function.
+
+ * camel/camel-folder.c (_set_name):
+ Use the exception system. When the folder
+ has no parent, don't set its full name
+ field.
+
+
1999-12-16 bertrand <Bertrand.Guiheneuf@aful.org>
* camel/camel-folder.c (camel_folder_expunge):
diff --git a/camel/camel-exception-list.def b/camel/camel-exception-list.def
index 1444c59f2c..1ed6f67fed 100644
--- a/camel/camel-exception-list.def
+++ b/camel/camel-exception-list.def
@@ -1,4 +1,4 @@
-CAMEL_EXCEPTION_NONE,
+CAMEL_EXCEPTION_NONE = 0,
/* Generic exceptions */
CAMEL_EXCEPTION_INVALID_PARAM,
diff --git a/camel/camel-exception.c b/camel/camel-exception.c
index 254b3046e9..961034cd78 100644
--- a/camel/camel-exception.c
+++ b/camel/camel-exception.c
@@ -46,6 +46,34 @@ camel_exception_new ()
return ex;
}
+
+/**
+ * camel_exception_clear: Clear an exception
+ * @exception: the exception object
+ *
+ * Clear an exception, that is, set the
+ * exception ID to CAMEL_EXCEPTION_NONE and
+ * free the description text.
+ * If the exception is NULL, this funtion just
+ * returns.
+ **/
+void
+camel_exception_clear (CamelException *exception)
+{
+ if (!exception) return;
+
+ /* free the description text */
+ if (exception->desc)
+ g_free (exception->desc);
+ exception->desc = NULL;
+
+ /* set the Exception Id to NULL */
+ exception->id = CAMEL_EXCEPTION_NONE;
+}
+
+
+
+
/**
* camel_exception_free: Free an exception
* @exception: The exception object to free
@@ -122,3 +150,49 @@ camel_exception_xfer (CamelException *ex_dst,
ex_src->desc = NULL;
ex_src->id = CAMEL_EXCEPTION_NONE;
}
+
+
+
+
+
+
+
+/**
+ * camel_exception_get_id: get the exception id
+ * @ex: The exception object
+ *
+ * Return the id of an exception.
+ * If @ex is NULL, return CAMEL_EXCEPTION_NONE;
+ *
+ * Return value: Exception ID.
+ **/
+ExceptionId
+camel_exception_get_id (CamelException *ex)
+{
+ if (ex)
+ return ex->id;
+ else
+ return CAMEL_EXCEPTION_NONE;
+}
+
+
+
+
+/**
+ * camel_exception_get_description: get the description of an exception.
+ * @ex: The exception object
+ *
+ * Return the exception description text.
+ * If @ex is NULL, return NULL;
+ *
+ *
+ * Return value: Exception description text.
+ **/
+const gchar *
+camel_exception_get_description (CamelException *ex)
+{
+ if (ex)
+ return ex->desc;
+ else
+ return NULL;
+}
diff --git a/camel/camel-exception.h b/camel/camel-exception.h
index ead903daa3..384f23a6f8 100644
--- a/camel/camel-exception.h
+++ b/camel/camel-exception.h
@@ -44,21 +44,30 @@ typedef enum {
} ExceptionId;
typedef struct {
-
+ /* do not access the fields directly */
ExceptionId id;
char *desc;
} CamelException;
-void camel_exception_free (CamelException *exception);
CamelException *camel_exception_new ();
+void camel_exception_free (CamelException *exception);
+
+
+void camel_exception_clear (CamelException *exception);
void camel_exception_set (CamelException *ex,
ExceptionId id,
const char *desc);
+
+
void camel_exception_xfer (CamelException *ex_dst,
CamelException *ex_src);
+ExceptionId camel_exception_get_id (CamelException *ex);
+const gchar *camel_exception_get_description (CamelException *ex);
+
+
#ifdef __cplusplus
}
diff --git a/camel/camel-folder.c b/camel/camel-folder.c
index 3f9399c2ad..226bed9d06 100644
--- a/camel/camel-folder.c
+++ b/camel/camel-folder.c
@@ -218,6 +218,7 @@ _finalize (GtkObject *object)
static void
_init_with_store (CamelFolder *folder, CamelStore *parent_store, CamelException *ex)
{
+
if (!folder) {
camel_exception_set (ex,
CAMEL_EXCEPTION_FOLDER_NULL,
@@ -232,7 +233,7 @@ _init_with_store (CamelFolder *folder, CamelStore *parent_store, CamelException
return;
}
- if (!folder->parent_store) {
+ if (folder->parent_store) {
camel_exception_set (ex,
CAMEL_EXCEPTION_INVALID_FOLDER,
"folder already has a parent store");
@@ -396,6 +397,12 @@ _close_async (CamelFolder *folder,
gpointer user_data,
CamelException *ex)
{
+ if (!folder) {
+ camel_exception_set (ex,
+ CAMEL_EXCEPTION_FOLDER_NULL,
+ "folder object is NULL");
+ return;
+ }
CAMEL_LOG_WARNING ("Calling CamelFolder::close_async directly. "
"Should be overloaded\n");
}
@@ -443,22 +450,46 @@ _set_name (CamelFolder *folder,
gchar *full_name;
const gchar *parent_full_name;
- g_assert (folder);
- g_assert (name);
- g_assert (folder->parent_store);
+ if (!folder) {
+ camel_exception_set (ex,
+ CAMEL_EXCEPTION_FOLDER_NULL,
+ "folder object is NULL");
+ return;
+ }
+
+ if (!name) {
+ camel_exception_set (ex,
+ CAMEL_EXCEPTION_INVALID_PARAM,
+ "name parameter is NULL");
+ return;
+ }
+
+ if (!folder->parent_store) {
+ camel_exception_set (ex,
+ CAMEL_EXCEPTION_INVALID_FOLDER,
+ "folder has no parent store");
+ return;
+ }
+
+ /* if the folder already has a name, free it */
g_free (folder->name);
g_free (folder->full_name);
- separator = camel_store_get_separator (folder->parent_store);
+ /* set thos fields to NULL now, so that if an
+ exception occurs, they will be set anyway */
+ folder->name = NULL;
+ folder->full_name = NULL;
+
+ separator = camel_store_get_separator (folder->parent_store);
+ camel_exception_free (ex);
if (folder->parent_folder) {
parent_full_name = camel_folder_get_full_name (folder->parent_folder, ex);
- full_name = g_strdup_printf ("%s%d%s", parent_full_name, separator, name);
+ if (camel_exception_get_id (ex)) return;
- } else {
- full_name = g_strdup (name);
- }
+ full_name = g_strdup_printf ("%s%d%s", parent_full_name, separator, name);
+ }
folder->name = g_strdup (name);
folder->full_name = full_name;
@@ -475,6 +506,12 @@ _set_name (CamelFolder *folder,
void
camel_folder_set_name (CamelFolder *folder, const gchar *name, CamelException *ex)
{
+ if (!folder) {
+ camel_exception_set (ex,
+ CAMEL_EXCEPTION_FOLDER_NULL,
+ "folder object is NULL");
+ }
+
CF_CLASS(folder)->set_name (folder, name, ex);
}
@@ -488,6 +525,12 @@ camel_folder_set_name (CamelFolder *folder, const gchar *name, CamelException *e
static void
_set_full_name (CamelFolder *folder, const gchar *name, CamelException *ex)
{
+ if (!folder) {
+ camel_exception_set (ex,
+ CAMEL_EXCEPTION_FOLDER_NULL,
+ "folder object is NULL");
+ return;
+ }
g_free(folder->full_name);
folder->full_name = g_strdup (name);
}
@@ -504,6 +547,13 @@ _set_full_name (CamelFolder *folder, const gchar *name, CamelException *ex)
void
camel_folder_set_full_name (CamelFolder *folder, const gchar *name, CamelException *ex)
{
+ if (!folder) {
+ camel_exception_set (ex,
+ CAMEL_EXCEPTION_FOLDER_NULL,
+ "folder object is NULL");
+ return;
+ }
+
CF_CLASS(folder)->set_full_name (folder, name, ex);
}
#endif
@@ -514,6 +564,12 @@ camel_folder_set_full_name (CamelFolder *folder, const gchar *name, CamelExcepti
static const gchar *
_get_name (CamelFolder *folder, CamelException *ex)
{
+ if (!folder) {
+ camel_exception_set (ex,
+ CAMEL_EXCEPTION_FOLDER_NULL,
+ "folder object is NULL");
+ return NULL;
+ }
return folder->name;
}
@@ -530,6 +586,13 @@ _get_name (CamelFolder *folder, CamelException *ex)
const gchar *
camel_folder_get_name (CamelFolder *folder, CamelException *ex)
{
+ if (!folder) {
+ camel_exception_set (ex,
+ CAMEL_EXCEPTION_FOLDER_NULL,
+ "folder object is NULL");
+ return NULL;
+ }
+
return CF_CLASS(folder)->get_name (folder, ex);
}
@@ -538,6 +601,13 @@ camel_folder_get_name (CamelFolder *folder, CamelException *ex)
static const gchar *
_get_full_name (CamelFolder *folder, CamelException *ex)
{
+ if (!folder) {
+ camel_exception_set (ex,
+ CAMEL_EXCEPTION_FOLDER_NULL,
+ "folder object is NULL");
+ return NULL;
+ }
+
return folder->full_name;
}
@@ -552,6 +622,13 @@ _get_full_name (CamelFolder *folder, CamelException *ex)
const gchar *
camel_folder_get_full_name (CamelFolder *folder, CamelException *ex)
{
+ if (!folder) {
+ camel_exception_set (ex,
+ CAMEL_EXCEPTION_FOLDER_NULL,
+ "folder object is NULL");
+ return NULL;
+ }
+
return CF_CLASS(folder)->get_full_name (folder, ex);
}
@@ -568,6 +645,13 @@ camel_folder_get_full_name (CamelFolder *folder, CamelException *ex)
static gboolean
_can_hold_folders (CamelFolder *folder, CamelException *ex)
{
+ if (!folder) {
+ camel_exception_set (ex,
+ CAMEL_EXCEPTION_FOLDER_NULL,
+ "folder object is NULL");
+ return FALSE;
+ }
+
return folder->can_hold_folders;
}
@@ -587,6 +671,13 @@ _can_hold_folders (CamelFolder *folder, CamelException *ex)
static gboolean
_can_hold_messages (CamelFolder *folder, CamelException *ex)
{
+ if (!folder) {
+ camel_exception_set (ex,
+ CAMEL_EXCEPTION_FOLDER_NULL,
+ "folder object is NULL");
+ return FALSE;
+ }
+
return folder->can_hold_messages;
}
@@ -595,6 +686,13 @@ _can_hold_messages (CamelFolder *folder, CamelException *ex)
static gboolean
_exists (CamelFolder *folder, CamelException *ex)
{
+ if (!folder) {
+ camel_exception_set (ex,
+ CAMEL_EXCEPTION_FOLDER_NULL,
+ "folder object is NULL");
+ return FALSE;
+ }
+
return FALSE;
}
@@ -612,6 +710,13 @@ _exists (CamelFolder *folder, CamelException *ex)
gboolean
camel_folder_exists (CamelFolder *folder, CamelException *ex)
{
+ if (!folder) {
+ camel_exception_set (ex,
+ CAMEL_EXCEPTION_FOLDER_NULL,
+ "folder object is NULL");
+ return FALSE;
+ }
+
return (CF_CLASS(folder)->exists (folder, ex));
}
@@ -629,6 +734,13 @@ camel_folder_exists (CamelFolder *folder, CamelException *ex)
static gboolean
_is_open (CamelFolder *folder, CamelException *ex)
{
+ if (!folder) {
+ camel_exception_set (ex,
+ CAMEL_EXCEPTION_FOLDER_NULL,
+ "folder object is NULL");
+ return FALSE;
+ }
+
return (folder->open_state == FOLDER_OPEN);
}
@@ -646,14 +758,32 @@ _get_subfolder (CamelFolder *folder,
const gchar *current_folder_full_name;
gchar separator;
- g_assert (folder);
- g_assert (folder_name);
+ if (!folder) {
+ camel_exception_set (ex,
+ CAMEL_EXCEPTION_FOLDER_NULL,
+ "folder object is NULL");
+ return;
+ }
+
- if (!folder->parent_store) return NULL;
+ if (!folder_name) {
+ camel_exception_set (ex,
+ CAMEL_EXCEPTION_INVALID_PARAM,
+ "folder_name parameter is NULL");
+ return;
+ }
- current_folder_full_name = camel_folder_get_full_name (folder, ex);
- if (!current_folder_full_name) return NULL;
+ if (!folder->parent_store) {
+ camel_exception_set (ex,
+ CAMEL_EXCEPTION_INVALID_FOLDER,
+ "folder has no parent store");
+ return;
+ }
+ current_folder_full_name = camel_folder_get_full_name (folder, ex);
+ if (camel_exception_get_id (ex)) return NULL;
+
+
separator = camel_store_get_separator (folder->parent_store);
full_name = g_strdup_printf ("%s%d%s", current_folder_full_name, separator, folder_name);
@@ -678,6 +808,13 @@ _get_subfolder (CamelFolder *folder,
CamelFolder *
camel_folder_get_subfolder (CamelFolder *folder, gchar *folder_name, CamelException *ex)
{
+ if (!folder) {
+ camel_exception_set (ex,
+ CAMEL_EXCEPTION_FOLDER_NULL,
+ "folder object is NULL");
+ return FALSE;
+ }
+
return (CF_CLASS(folder)->get_subfolder(folder,folder_name, ex));
}
@@ -699,7 +836,7 @@ camel_folder_get_subfolder (CamelFolder *folder, gchar *folder_name, CamelExcept
* Return value: %TRUE if the folder exists, %FALSE otherwise
**/
static gboolean
-_create(CamelFolder *folder, CamelException *ex)
+_create (CamelFolder *folder, CamelException *ex)
{
gchar *prefix;
gchar dich_result;
@@ -710,9 +847,34 @@ _create(CamelFolder *folder, CamelException *ex)
g_assert (folder->parent_store);
g_assert (folder->name);
+ if (!folder) {
+ camel_exception_set (ex,
+ CAMEL_EXCEPTION_FOLDER_NULL,
+ "folder object is NULL");
+ return FALSE;
+ }
+
+
+ if (!folder->name) {
+ camel_exception_set (ex,
+ CAMEL_EXCEPTION_INVALID_FOLDER,
+ "folder has no name");
+ return FALSE;
+ }
+
+ if (!folder->parent_store) {
+ camel_exception_set (ex,
+ CAMEL_EXCEPTION_INVALID_FOLDER,
+ "folder has no parent store");
+ return FALSE;
+ }
+
+ /* if the folder already exists on the
+ store, do nothing and return true */
if (CF_CLASS(folder)->exists (folder, ex))
return TRUE;
+ /*** Ber : finis les exceptions ici **/
sep = camel_store_get_separator (folder->parent_store);
if (folder->parent_folder)
camel_folder_create (folder->parent_folder, ex);