Simplify: Use dbus_message_iter_get_args
authorDenis Kenzior <denkenz@gmail.com>
Tue, 22 Sep 2009 15:59:17 +0000 (10:59 -0500)
committerDenis Kenzior <denkenz@gmail.com>
Tue, 22 Sep 2009 16:24:21 +0000 (11:24 -0500)
src/call-barring.c
src/call-forwarding.c
src/call-meter.c
src/sim.c

index 75b1be7..cdd6331 100644 (file)
@@ -889,25 +889,21 @@ static DBusMessage *cb_disable_all(DBusConnection *conn, DBusMessage *msg,
                                        void *data, const char *fac)
 {
        struct ofono_call_barring *cb = data;
-       DBusMessageIter iter;
-       const char *passwd = "";
+       const char *passwd;
+
+       if (!cb->driver->set)
+               return __ofono_error_not_implemented(msg);
 
        if (cb->pending)
                return __ofono_error_busy(msg);
 
-       if (!dbus_message_iter_init(msg, &iter))
-               return __ofono_error_invalid_args(msg);
-
-       if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
+       if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &passwd,
+                                       DBUS_TYPE_INVALID) == FALSE)
                return __ofono_error_invalid_args(msg);
 
-       dbus_message_iter_get_basic(&iter, &passwd);
        if (!is_valid_pin(passwd))
                return __ofono_error_invalid_format(msg);
 
-       if (!cb->driver->set)
-               return __ofono_error_not_implemented(msg);
-
        cb_set_query_bounds(cb, fac, FALSE);
 
        cb->pending = dbus_message_ref(msg);
@@ -939,34 +935,26 @@ static DBusMessage *cb_set_passwd(DBusConnection *conn, DBusMessage *msg,
                                        void *data)
 {
        struct ofono_call_barring *cb = data;
-       DBusMessageIter iter;
-       const char *old_passwd, *new_passwd;
+       const char *old_passwd;
+       const char *new_passwd;
+
+       if (!cb->driver->set_passwd)
+               return __ofono_error_not_implemented(msg);
 
        if (cb->pending)
                return __ofono_error_busy(msg);
 
-       if (!dbus_message_iter_init(msg, &iter))
+       if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &old_passwd,
+                                       DBUS_TYPE_STRING, &new_passwd,
+                                       DBUS_TYPE_INVALID) == FALSE)
                return __ofono_error_invalid_args(msg);
 
-       if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
-               return __ofono_error_invalid_args(msg);
-
-       dbus_message_iter_get_basic(&iter, &old_passwd);
        if (!is_valid_pin(old_passwd))
                return __ofono_error_invalid_format(msg);
 
-       dbus_message_iter_next(&iter);
-
-       if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
-               return __ofono_error_invalid_args(msg);
-
-       dbus_message_iter_get_basic(&iter, &new_passwd);
        if (!is_valid_pin(new_passwd))
                return __ofono_error_invalid_format(msg);
 
-       if (!cb->driver->set_passwd)
-               return __ofono_error_not_implemented(msg);
-
        cb->pending = dbus_message_ref(msg);
        cb->driver->set_passwd(cb, "AB", old_passwd, new_passwd,
                        cb_set_passwd_callback, cb);
index 9ca5a54..f43772a 100644 (file)
@@ -701,12 +701,12 @@ static DBusMessage *cf_disable_all(DBusConnection *conn, DBusMessage *msg,
        const char *strtype;
        int type;
 
-       if (cf->pending)
-               return __ofono_error_busy(msg);
-
        if (!cf->driver->erasure)
                return __ofono_error_not_implemented(msg);
 
+       if (cf->pending)
+               return __ofono_error_busy(msg);
+
        if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &strtype,
                                        DBUS_TYPE_INVALID) == FALSE)
                return __ofono_error_invalid_args(msg);
index 45c41c5..e264029 100644 (file)
@@ -606,26 +606,21 @@ static DBusMessage *cm_acm_reset(DBusConnection *conn, DBusMessage *msg,
                                        void *data)
 {
        struct ofono_call_meter *cm = data;
-       DBusMessageIter iter;
        const char *pin2;
 
+       if (!cm->driver->acm_reset)
+               return __ofono_error_not_implemented(msg);
+
        if (cm->pending)
                return __ofono_error_busy(msg);
 
-       if (!dbus_message_iter_init(msg, &iter))
+       if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &pin2,
+                                       DBUS_TYPE_INVALID) == FALSE)
                return __ofono_error_invalid_args(msg);
 
-       if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
-               return __ofono_error_invalid_args(msg);
-
-       dbus_message_iter_get_basic(&iter, &pin2);
-
        if (!is_valid_pin(pin2))
                return __ofono_error_invalid_format(msg);
 
-       if (!cm->driver->acm_reset)
-               return __ofono_error_not_implemented(msg);
-
        cm->pending = dbus_message_ref(msg);
 
        cm->driver->acm_reset(cm, pin2, acm_reset_callback, cm);
index a4c8dfd..1a4edc4 100644 (file)
--- a/src/sim.c
+++ b/src/sim.c
@@ -442,7 +442,6 @@ static void sim_lock_cb(const struct ofono_error *error, void *data)
 static DBusMessage *sim_lock_or_unlock(struct ofono_sim *sim, int lock,
                                        DBusConnection *conn, DBusMessage *msg)
 {
-       DBusMessageIter iter;
        enum ofono_sim_password_type type;
        const char *typestr;
        const char *pin;
@@ -453,14 +452,11 @@ static DBusMessage *sim_lock_or_unlock(struct ofono_sim *sim, int lock,
        if (sim->pending)
                return __ofono_error_busy(msg);
 
-       if (!dbus_message_iter_init(msg, &iter))
-               return __ofono_error_invalid_args(msg);
-
-       if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
+       if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &typestr,
+                                       DBUS_TYPE_STRING, &pin,
+                                       DBUS_TYPE_INVALID) == FALSE)
                return __ofono_error_invalid_args(msg);
 
-       dbus_message_iter_get_basic(&iter, &typestr);
-
        type = sim_string_to_passwd(typestr);
 
        /* SIM PIN2 cannot be locked / unlocked according to 27.007,
@@ -470,12 +466,6 @@ static DBusMessage *sim_lock_or_unlock(struct ofono_sim *sim, int lock,
                        type == OFONO_SIM_PASSWORD_SIM_PIN2)
                return __ofono_error_invalid_format(msg);
 
-       dbus_message_iter_next(&iter);
-       if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
-               return __ofono_error_invalid_args(msg);
-
-       dbus_message_iter_get_basic(&iter, &pin);
-
        if (!is_valid_pin(pin))
                return __ofono_error_invalid_format(msg);
 
@@ -519,7 +509,6 @@ static DBusMessage *sim_change_pin(DBusConnection *conn, DBusMessage *msg,
                                        void *data)
 {
        struct ofono_sim *sim = data;
-       DBusMessageIter iter;
        enum ofono_sim_password_type type;
        const char *typestr;
        const char *old;
@@ -531,34 +520,20 @@ static DBusMessage *sim_change_pin(DBusConnection *conn, DBusMessage *msg,
        if (sim->pending)
                return __ofono_error_busy(msg);
 
-       if (!dbus_message_iter_init(msg, &iter))
-               return __ofono_error_invalid_args(msg);
-
-       if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
+       if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &typestr,
+                                       DBUS_TYPE_STRING, &old,
+                                       DBUS_TYPE_STRING, &new,
+                                       DBUS_TYPE_INVALID) == FALSE)
                return __ofono_error_invalid_args(msg);
 
-       dbus_message_iter_get_basic(&iter, &typestr);
-
        type = sim_string_to_passwd(typestr);
 
        if (password_is_pin(type) == FALSE)
                return __ofono_error_invalid_format(msg);
 
-       dbus_message_iter_next(&iter);
-       if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
-               return __ofono_error_invalid_args(msg);
-
-       dbus_message_iter_get_basic(&iter, &old);
-
        if (!is_valid_pin(old))
                return __ofono_error_invalid_format(msg);
 
-       dbus_message_iter_next(&iter);
-       if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
-               return __ofono_error_invalid_args(msg);
-
-       dbus_message_iter_get_basic(&iter, &new);
-
        if (!is_valid_pin(new))
                return __ofono_error_invalid_format(msg);
 
@@ -591,7 +566,6 @@ static DBusMessage *sim_enter_pin(DBusConnection *conn, DBusMessage *msg,
                                        void *data)
 {
        struct ofono_sim *sim = data;
-       DBusMessageIter iter;
        const char *typestr;
        enum ofono_sim_password_type type;
        const char *pin;
@@ -602,25 +576,16 @@ static DBusMessage *sim_enter_pin(DBusConnection *conn, DBusMessage *msg,
        if (sim->pending)
                return __ofono_error_busy(msg);
 
-       if (!dbus_message_iter_init(msg, &iter))
-               return __ofono_error_invalid_args(msg);
-
-       if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
+       if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &typestr,
+                                       DBUS_TYPE_STRING, &pin,
+                                       DBUS_TYPE_INVALID) == FALSE)
                return __ofono_error_invalid_args(msg);
 
-       dbus_message_iter_get_basic(&iter, &typestr);
-
        type = sim_string_to_passwd(typestr);
 
        if (type == OFONO_SIM_PASSWORD_NONE || type != sim->pin_type)
                return __ofono_error_invalid_format(msg);
 
-       dbus_message_iter_next(&iter);
-       if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
-               return __ofono_error_invalid_args(msg);
-
-       dbus_message_iter_get_basic(&iter, &pin);
-
        if (!is_valid_pin(pin))
                return __ofono_error_invalid_format(msg);
 
@@ -634,7 +599,6 @@ static DBusMessage *sim_reset_pin(DBusConnection *conn, DBusMessage *msg,
                                        void *data)
 {
        struct ofono_sim *sim = data;
-       DBusMessageIter iter;
        const char *typestr;
        enum ofono_sim_password_type type;
        const char *puk;
@@ -646,34 +610,20 @@ static DBusMessage *sim_reset_pin(DBusConnection *conn, DBusMessage *msg,
        if (sim->pending)
                return __ofono_error_busy(msg);
 
-       if (!dbus_message_iter_init(msg, &iter))
-               return __ofono_error_invalid_args(msg);
-
-       if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
+       if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &typestr,
+                                       DBUS_TYPE_STRING, &puk,
+                                       DBUS_TYPE_STRING, &pin,
+                                       DBUS_TYPE_INVALID) == FALSE)
                return __ofono_error_invalid_args(msg);
 
-       dbus_message_iter_get_basic(&iter, &typestr);
-
        type = sim_string_to_passwd(typestr);
 
        if (type == OFONO_SIM_PASSWORD_NONE || type != sim->pin_type)
                return __ofono_error_invalid_format(msg);
 
-       dbus_message_iter_next(&iter);
-       if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
-               return __ofono_error_invalid_args(msg);
-
-       dbus_message_iter_get_basic(&iter, &puk);
-
        if (!is_valid_pin(puk))
                return __ofono_error_invalid_format(msg);
 
-       dbus_message_iter_next(&iter);
-       if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
-               return __ofono_error_invalid_args(msg);
-
-       dbus_message_iter_get_basic(&iter, &pin);
-
        if (!is_valid_pin(pin))
                return __ofono_error_invalid_format(msg);