ae7247551b78a05a5397d3c790afad7ef51b0d9dPavel Březina Pavel Březina <pbrezina@redhat.com>
ae7247551b78a05a5397d3c790afad7ef51b0d9dPavel Březina Copyright (C) 2015 Red Hat
ae7247551b78a05a5397d3c790afad7ef51b0d9dPavel Březina This program is free software; you can redistribute it and/or modify
ae7247551b78a05a5397d3c790afad7ef51b0d9dPavel Březina it under the terms of the GNU General Public License as published by
ae7247551b78a05a5397d3c790afad7ef51b0d9dPavel Březina the Free Software Foundation; either version 3 of the License, or
ae7247551b78a05a5397d3c790afad7ef51b0d9dPavel Březina (at your option) any later version.
ae7247551b78a05a5397d3c790afad7ef51b0d9dPavel Březina This program is distributed in the hope that it will be useful,
ae7247551b78a05a5397d3c790afad7ef51b0d9dPavel Březina but WITHOUT ANY WARRANTY; without even the implied warranty of
ae7247551b78a05a5397d3c790afad7ef51b0d9dPavel Březina MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ae7247551b78a05a5397d3c790afad7ef51b0d9dPavel Březina GNU General Public License for more details.
ae7247551b78a05a5397d3c790afad7ef51b0d9dPavel Březina You should have received a copy of the GNU General Public License
ae7247551b78a05a5397d3c790afad7ef51b0d9dPavel Březina along with this program. If not, see <http://www.gnu.org/licenses/>.
365fe7479c753f198430812337a7ba8cdb0baf7dLukas Slebodnikstatic int sbus_incoming_signal_destructor(struct sbus_incoming_signal *a_signal)
ae7247551b78a05a5397d3c790afad7ef51b0d9dPavel Březinasbus_new_incoming_signal(struct sbus_connection *conn,
365fe7479c753f198430812337a7ba8cdb0baf7dLukas Slebodnik a_signal = talloc_zero(conn, struct sbus_incoming_signal);
ae7247551b78a05a5397d3c790afad7ef51b0d9dPavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Out of memory allocating D-Bus signal\n");
365fe7479c753f198430812337a7ba8cdb0baf7dLukas Slebodnik a_signal->message = dbus_message_ref(message);
365fe7479c753f198430812337a7ba8cdb0baf7dLukas Slebodnik a_signal->interface = dbus_message_get_interface(message);
365fe7479c753f198430812337a7ba8cdb0baf7dLukas Slebodnik a_signal->signal = dbus_message_get_member(message);
365fe7479c753f198430812337a7ba8cdb0baf7dLukas Slebodnik a_signal->path = dbus_message_get_path(message);
365fe7479c753f198430812337a7ba8cdb0baf7dLukas Slebodnik talloc_set_destructor(a_signal, sbus_incoming_signal_destructor);
b1afef0bc8d98c389a7f71307bee8ef9fc991cedPavel Březinasbus_incoming_signal_hash_init(TALLOC_CTX *mem_ctx)
b1afef0bc8d98c389a7f71307bee8ef9fc991cedPavel Březina return sss_ptr_hash_create(mem_ctx, NULL, NULL);
ae7247551b78a05a5397d3c790afad7ef51b0d9dPavel Březinasbus_incoming_signal_hash_add(hash_table_t *table,
b1afef0bc8d98c389a7f71307bee8ef9fc991cedPavel Březina key = talloc_asprintf(tmp_ctx, "%s.%s", iface, a_signal);
ae7247551b78a05a5397d3c790afad7ef51b0d9dPavel Březina data = talloc_zero(tmp_ctx, struct sbus_incoming_signal_data);
b1afef0bc8d98c389a7f71307bee8ef9fc991cedPavel Březina ret = sss_ptr_hash_add(table, key, data, struct sbus_incoming_signal_data);
ae7247551b78a05a5397d3c790afad7ef51b0d9dPavel Březinasbus_incoming_signal_hash_lookup(hash_table_t *table,
b1afef0bc8d98c389a7f71307bee8ef9fc991cedPavel Březina key = talloc_asprintf(NULL, "%s.%s", iface, a_signal);
b1afef0bc8d98c389a7f71307bee8ef9fc991cedPavel Březina data = sss_ptr_hash_lookup(table, key, struct sbus_incoming_signal_data);
ae7247551b78a05a5397d3c790afad7ef51b0d9dPavel Březinasbus_signal_listen(struct sbus_connection *conn,
ae7247551b78a05a5397d3c790afad7ef51b0d9dPavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "talloc_new() failed\n");
ae7247551b78a05a5397d3c790afad7ef51b0d9dPavel Březina ret = sbus_incoming_signal_hash_add(conn->incoming_signals, iface,
ae7247551b78a05a5397d3c790afad7ef51b0d9dPavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Unable to register signal handler "
ae7247551b78a05a5397d3c790afad7ef51b0d9dPavel Březina rule = talloc_asprintf(tmp_ctx, "type='signal',interface='%s',member='%s'",
ae7247551b78a05a5397d3c790afad7ef51b0d9dPavel Březina dbus_bus_add_match(conn->dbus.conn, rule, &error);
ae7247551b78a05a5397d3c790afad7ef51b0d9dPavel Březina "Cannot add D-Bus match rule, cause: %s\n", error.message);
365fe7479c753f198430812337a7ba8cdb0baf7dLukas Slebodnik DEBUG(SSSDBG_TRACE_FUNC, "Listening to signal %s.%s\n", iface, a_signal);
ae7247551b78a05a5397d3c790afad7ef51b0d9dPavel Březinasbus_signal_handler_got_caller_id(struct tevent_req *req);
ae7247551b78a05a5397d3c790afad7ef51b0d9dPavel Březina /* We ignore other types here. */
ae7247551b78a05a5397d3c790afad7ef51b0d9dPavel Březina conn = talloc_get_type(handler_data, struct sbus_connection);
ae7247551b78a05a5397d3c790afad7ef51b0d9dPavel Březina /* we have a valid handler, create D-Bus request */
365fe7479c753f198430812337a7ba8cdb0baf7dLukas Slebodnik a_signal = sbus_new_incoming_signal(conn, message);
ae7247551b78a05a5397d3c790afad7ef51b0d9dPavel Březina DEBUG(SSSDBG_TRACE_INTERNAL, "Received D-Bus signal %s.%s\n",
ae7247551b78a05a5397d3c790afad7ef51b0d9dPavel Březina /* now get the sender ID */
365fe7479c753f198430812337a7ba8cdb0baf7dLukas Slebodnik req = sbus_get_sender_id_send(a_signal, conn->ev, conn, sender);
365fe7479c753f198430812337a7ba8cdb0baf7dLukas Slebodnik tevent_req_set_callback(req, sbus_signal_handler_got_caller_id, a_signal);
ae7247551b78a05a5397d3c790afad7ef51b0d9dPavel Březinasbus_signal_handler_got_caller_id(struct tevent_req *req)
ae7247551b78a05a5397d3c790afad7ef51b0d9dPavel Březina struct sbus_incoming_signal_data *signal_data;
365fe7479c753f198430812337a7ba8cdb0baf7dLukas Slebodnik a_signal = tevent_req_callback_data(req, struct sbus_incoming_signal);
365fe7479c753f198430812337a7ba8cdb0baf7dLukas Slebodnik ret = sbus_get_sender_id_recv(req, &a_signal->client);
9118a539a5d59f669f551114f880fe91d6bb8741Jakub Hrozek DEBUG(SSSDBG_TRACE_FUNC, "Got a signal from the bus..\n");
ae7247551b78a05a5397d3c790afad7ef51b0d9dPavel Březina "Failed to resolve caller's ID: %s\n", sss_strerror(ret));
ae7247551b78a05a5397d3c790afad7ef51b0d9dPavel Březina signal_data = sbus_incoming_signal_hash_lookup(
ae7247551b78a05a5397d3c790afad7ef51b0d9dPavel Březina DEBUG(SSSDBG_MINOR_FAILURE, "Received signal %s.%s that we are "
365fe7479c753f198430812337a7ba8cdb0baf7dLukas Slebodnik "not listening to.\n", a_signal->interface, a_signal->signal);