main/sorcery: Provide log messages when a wizard does not support an operation
authorMatt Jordan <mjordan@digium.com>
Wed, 8 Jul 2015 21:32:25 +0000 (16:32 -0500)
committerMatt Jordan <mjordan@digium.com>
Sat, 11 Jul 2015 17:22:16 +0000 (12:22 -0500)
If a sorcery wizard does not support one of the 'optional' CRUD
operations (namely the CUD), log a WARNING message so we are aware of
why the operation failed. This also removes an assert in this case, as
the CUD operation may have been triggered by an external system, in
which case it is not a programming error but a configuration error.

Change-Id: Ifecd9df946d9deaa86235257b49c6e5e24423b53

main/sorcery.c

index fbbd146..790e782 100644 (file)
@@ -1945,9 +1945,7 @@ static int sorcery_wizard_create(void *obj, void *arg, int flags)
        const struct sorcery_details *details = arg;
 
        if (!object_wizard->wizard->callbacks.create) {
-               ast_assert(0);
-               ast_log(LOG_ERROR, "Sorcery wizard '%s' doesn't contain a 'create' virtual function.\n",
-                       object_wizard->wizard->callbacks.name);
+               ast_debug(5, "Sorcery wizard '%s' does not support creation\n", object_wizard->wizard->callbacks.name);
                return 0;
        }
        return (!object_wizard->caching && !object_wizard->wizard->callbacks.create(details->sorcery, object_wizard->data, details->obj)) ? CMP_MATCH | CMP_STOP : 0;
@@ -2040,7 +2038,12 @@ static int sorcery_wizard_update(void *obj, void *arg, int flags)
        const struct ast_sorcery_object_wizard *object_wizard = obj;
        const struct sorcery_details *details = arg;
 
-       return (object_wizard->wizard->callbacks.update && !object_wizard->wizard->callbacks.update(details->sorcery, object_wizard->data, details->obj) &&
+       if (!object_wizard->wizard->callbacks.update) {
+               ast_debug(5, "Sorcery wizard '%s' does not support updating\n", object_wizard->wizard->callbacks.name);
+               return 0;
+       }
+
+       return (!object_wizard->wizard->callbacks.update(details->sorcery, object_wizard->data, details->obj) &&
                !object_wizard->caching) ? CMP_MATCH | CMP_STOP : 0;
 }
 
@@ -2108,7 +2111,12 @@ static int sorcery_wizard_delete(void *obj, void *arg, int flags)
        const struct ast_sorcery_object_wizard *object_wizard = obj;
        const struct sorcery_details *details = arg;
 
-       return (object_wizard->wizard->callbacks.delete && !object_wizard->wizard->callbacks.delete(details->sorcery, object_wizard->data, details->obj) &&
+       if (!object_wizard->wizard->callbacks.delete) {
+               ast_debug(5, "Sorcery wizard '%s' does not support deletion\n", object_wizard->wizard->callbacks.name);
+               return 0;
+       }
+
+       return (!object_wizard->wizard->callbacks.delete(details->sorcery, object_wizard->data, details->obj) &&
                !object_wizard->caching) ? CMP_MATCH | CMP_STOP : 0;
 }