diff --git a/dbus.c b/dbus.c index acded1db..a89e4d3e 100644 --- a/dbus.c +++ b/dbus.c @@ -52,95 +52,34 @@ a_dbus_path_check(char **path, int nelem) } static void -a_dbus_process_request_client(DBusMessage *msg) +a_dbus_process_request_do(DBusMessage *msg) { - int i = 2; + int i; DBusMessageIter iter; - const char *m; - char **path, *arg; - client_t *c; - bool b; - uint64_t i64; - double d; + char **path, *cmd; if(!dbus_message_get_path_decomposed(msg, &path)) return; /* path is: - * /org/awesome/clients/bywhat/id */ - if(!a_dbus_path_check(path, 5) - || a_strcmp(path[2], "clients")) + * /org/awesome */ + if(!a_dbus_path_check(path, 2)) goto bailout; - /* handle by- */ - switch(a_tokenize(path[3], -1)) - { - case A_TK_BYNAME: - for(c = globalconf.clients; c; c = c->next) - if(!a_strcmp(c->name, path[4])) - break; - /* not found, return */ - if(!c) - goto bailout; - break; - default: - return; - } - if(!dbus_message_iter_init(msg, &iter)) { dbus_error_free(&err); - return; + goto bailout; } - - /* clear stack */ - lua_settop(globalconf.L, 0); - - /* push index function */ - lua_pushcfunction(globalconf.L, luaA_client_newindex); - - /* push the client */ - luaA_client_userdata_new(globalconf.L, c); - - /* get the method name */ - m = dbus_message_get_member(msg); - - /* push the method name */ - lua_pushstring(globalconf.L, m); - - do + else if(DBUS_TYPE_STRING != dbus_message_iter_get_arg_type(&iter)) { - switch(dbus_message_iter_get_arg_type(&iter)) - { - case DBUS_TYPE_STRING: - dbus_message_iter_get_basic(&iter, &arg); - lua_pushstring(globalconf.L, arg); - break; - case DBUS_TYPE_BOOLEAN: - dbus_message_iter_get_basic(&iter, &b); - lua_pushboolean(globalconf.L, b); - break; - case DBUS_TYPE_INT16: - case DBUS_TYPE_UINT16: - case DBUS_TYPE_INT32: - case DBUS_TYPE_UINT32: - case DBUS_TYPE_INT64: - case DBUS_TYPE_UINT64: - dbus_message_iter_get_basic(&iter, &i64); - lua_pushnumber(globalconf.L, i64); - break; - case DBUS_TYPE_DOUBLE: - dbus_message_iter_get_basic(&iter, &d); - lua_pushnumber(globalconf.L, d); - break; - default: - break; - } - i++; + dbus_error_free(&err); + goto bailout; } - while(dbus_message_iter_next(&iter)); + else + dbus_message_iter_get_basic(&iter, &cmd); - lua_pcall(globalconf.L, i, 0, 0); + luaA_dostring(globalconf.L, cmd); bailout: for(i = 0; path[i]; i++) @@ -153,8 +92,6 @@ a_dbus_process_requests(EV_P_ ev_io *w, int revents) { DBusMessage *msg; int nmsg = 0; - const char *n; - ssize_t len; if(!dbus_connection && !a_dbus_init()) return; @@ -172,31 +109,8 @@ a_dbus_process_requests(EV_P_ ev_io *w, int revents) dbus_message_unref(msg); return; } - else - { - /* get the interface */ - n = dbus_message_get_interface(msg); - len = a_strlen(n); - - /* check destination: at least has sizeof(org.awesome.) - * and match org.awesome */ - if(len > 12 && !a_strncmp(n, "org.awesome", 11)) - { - /* n is now after at the end of 'org.awesome.' */ - n += 12; - - /* we assume that after the dot there's a class name, like - * widget, client, etc… */ - switch(a_tokenize(n, -1)) - { - case A_TK_CLIENT: - a_dbus_process_request_client(msg); - break; - default: - break; - } - } - } + else if(dbus_message_is_method_call(msg, "org.awesome", "do")) + a_dbus_process_request_do(msg); dbus_message_unref(msg);