/soc/2013/ankitkv/gobjectification: a3b0d16f69ef: Added error ar...
Ankit Vani
a at nevitus.org
Sat Aug 31 15:28:42 EDT 2013
Changeset: a3b0d16f69efacce993a579b2367921242996eb3
Author: Ankit Vani <a at nevitus.org>
Date: 2013-09-01 00:58 +0530
Branch: soc.2013.gobjectification.plugins
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/a3b0d16f69ef
Description:
Added error argument to protocol add/remove funcs, along with checks to ensure protocol being added/removed is valid
diffstat:
libpurple/protocols.c | 41 ++++++++++++++++++++++++++++++++++++++---
libpurple/protocols.h | 12 +++++++++---
2 files changed, 47 insertions(+), 6 deletions(-)
diffs (109 lines):
diff --git a/libpurple/protocols.c b/libpurple/protocols.c
--- a/libpurple/protocols.c
+++ b/libpurple/protocols.c
@@ -743,7 +743,7 @@ purple_protocols_find(const char *id)
}
PurpleProtocol *
-purple_protocols_add(GType protocol_type)
+purple_protocols_add(GType protocol_type, GError **error)
{
PurpleProtocol *protocol;
@@ -751,7 +751,34 @@ purple_protocols_add(GType protocol_type
protocol_type != G_TYPE_NONE, NULL);
protocol = g_object_new(protocol_type, NULL);
+
+ if (!purple_protocol_get_id(protocol)) {
+ g_set_error(error, PURPLE_PROTOCOLS_DOMAIN, 0,
+ _("Protocol does not provide an ID"));
+
+ g_object_unref(protocol);
+ return NULL;
+ }
+
if (purple_protocols_find(purple_protocol_get_id(protocol))) {
+ g_set_error(error, PURPLE_PROTOCOLS_DOMAIN, 0,
+ _("A protocol with the ID %s is already added."),
+ purple_protocol_get_id(protocol));
+
+ g_object_unref(protocol);
+ return NULL;
+ }
+
+ /* Make sure the protocol implements the required functions */
+ if (!PURPLE_PROTOCOL_IMPLEMENTS(protocol, list_icon) ||
+ !PURPLE_PROTOCOL_IMPLEMENTS(protocol, login) ||
+ !PURPLE_PROTOCOL_IMPLEMENTS(protocol, close))
+ {
+ g_set_error(error, PURPLE_PROTOCOLS_DOMAIN, 0,
+ _("Protocol %s does not implement all the required "
+ "functions (list_icon, login and close)"),
+ purple_protocol_get_id(protocol));
+
g_object_unref(protocol);
return NULL;
}
@@ -761,10 +788,18 @@ purple_protocols_add(GType protocol_type
return protocol;
}
-gboolean purple_protocols_remove(PurpleProtocol *protocol)
+gboolean purple_protocols_remove(PurpleProtocol *protocol, GError **error)
{
- if (purple_protocols_find(purple_protocol_get_id(protocol)) == NULL)
+ g_return_val_if_fail(protocol != NULL, FALSE);
+ g_return_val_if_fail(purple_protocol_get_id(protocol) != NULL, FALSE);
+
+ if (purple_protocols_find(purple_protocol_get_id(protocol)) == NULL) {
+ g_set_error(error, PURPLE_PROTOCOLS_DOMAIN, 0,
+ _("Protocol %s is not added."),
+ purple_protocol_get_id(protocol));
+
return FALSE;
+ }
g_hash_table_remove(protocols, purple_protocol_get_id(protocol));
return TRUE;
diff --git a/libpurple/protocols.h b/libpurple/protocols.h
--- a/libpurple/protocols.h
+++ b/libpurple/protocols.h
@@ -27,6 +27,8 @@
#ifndef _PURPLE_PROTOCOLS_H_
#define _PURPLE_PROTOCOLS_H_
+#define PURPLE_PROTOCOLS_DOMAIN (g_quark_from_static_string("protocols"))
+
#define PURPLE_TYPE_PROTOCOL_ACTION (purple_protocol_action_get_type())
/** @copydoc _PurpleProtocolAction */
@@ -564,10 +566,12 @@ PurpleProtocol *purple_protocols_find(co
* Adds a protocol to the list of protocols.
*
* @param protocol_type The type of the protocol to add.
+ * @param error Return location for a #GError or @c NULL. If provided, this
+ * will be set to the reason if adding fails.
*
* @return The protocol instance if the protocol was added, else @c NULL.
*/
-PurpleProtocol *purple_protocols_add(GType protocol_type);
+PurpleProtocol *purple_protocols_add(GType protocol_type, GError **error);
/**
* Removes a protocol from the list of protocols. This will disconnect all
@@ -575,10 +579,12 @@ PurpleProtocol *purple_protocols_add(GTy
* and protocol options.
*
* @param protocol The protocol to remove.
- *
+ * @param error Return location for a #GError or @c NULL. If provided, this
+ * will be set to the reason if removing fails.
+
* @return TRUE if the protocol was removed, else FALSE.
*/
-gboolean purple_protocols_remove(PurpleProtocol *protocol);
+gboolean purple_protocols_remove(PurpleProtocol *protocol, GError **error);
/**
* Returns a list of all loaded protocols.
More information about the Commits
mailing list