void ibus_connection_set_connection (IBusConnection *connection, DBusConnection *dbus_connection, gboolean shared) { gboolean result; IBusConnectionPrivate *priv; g_assert (IBUS_IS_CONNECTION (connection)); g_assert (dbus_connection != NULL); g_assert (dbus_connection_get_is_connected (dbus_connection)); priv = IBUS_CONNECTION_GET_PRIVATE (connection); g_assert (priv->connection == NULL); priv->connection = dbus_connection_ref (dbus_connection); priv->shared = shared; dbus_connection_set_data (priv->connection, _get_slot(), connection, NULL); dbus_connection_set_unix_user_function (priv->connection, (DBusAllowUnixUserFunction) _connection_allow_unix_user_cb, connection, NULL); result = dbus_connection_add_filter (priv->connection, (DBusHandleMessageFunction) _connection_handle_message_cb, connection, NULL); ibus_dbus_connection_setup (priv->connection); g_warn_if_fail (result); }
void hcid_dbus_unregister(void) { DBusConnection *conn = get_dbus_connection(); char **children; int i; uint16_t dev_id; if (!conn || !dbus_connection_get_is_connected(conn)) return; /* Unregister all paths in Adapter path hierarchy */ if (!dbus_connection_list_registered(conn, "/", &children)) return; for (i = 0; children[i]; i++) { char path[MAX_PATH_LENGTH]; struct btd_adapter *adapter; if (children[i][0] != 'h') continue; snprintf(path, sizeof(path), "/%s", children[i]); adapter = manager_find_adapter_by_path(path); if (!adapter) continue; dev_id = adapter_get_dev_id(adapter); manager_unregister_adapter(dev_id); } dbus_free_string_array(children); }
static int ldbus_connection_get_is_connected(lua_State *L) { DBusConnection *connection = check_DBusConnection(L, 1); lua_pushboolean(L, dbus_connection_get_is_connected(connection)); return 1; }
void VolumeBarLogic::openConnection (bool init) { /* * Check the connection first, maybe this function * only called because of lost connection */ if ((dbus_conn != NULL) && (dbus_connection_get_is_connected (dbus_conn))) return; DBusError dbus_err; char *pa_bus_address = getenv ("PULSE_DBUS_SERVER"); if (pa_bus_address == NULL) pa_bus_address = (char *) DEFAULT_ADDRESS; dbus_error_init (&dbus_err); dbus_conn = dbus_connection_open (pa_bus_address, &dbus_err); DBUS_ERR_CHECK (dbus_err); if (dbus_conn != NULL) { dbus_connection_setup_with_g_main (dbus_conn, NULL); dbus_connection_add_filter ( dbus_conn, (DBusHandleMessageFunction) VolumeBarLogic::stepsUpdatedSignal, (void *) this, NULL); if (init == true) initValues (); } }
int avahi_client_is_connected(AvahiClient *client) { assert(client); return client->bus && dbus_connection_get_is_connected(client->bus) && (client->state == AVAHI_CLIENT_S_RUNNING || client->state == AVAHI_CLIENT_S_REGISTERING || client->state == AVAHI_CLIENT_S_COLLISION); }
static void dispatch_status(DBusConnection *conn, DBusDispatchStatus status, void *data) { if (!dbus_connection_get_is_connected(conn)) return; queue_dispatch(conn, status); }
static void dispatch_status_cb(DBusConnection *conn, DBusDispatchStatus new_status, void *data) { if (!dbus_connection_get_is_connected(conn)) return; if (new_status == DBUS_DISPATCH_DATA_REMAINS) g_timeout_add(DISPATCH_TIMEOUT, message_dispatch_cb, data); }
void __ofono_dbus_cleanup(void) { DBusConnection *conn = ofono_dbus_get_connection(); if (conn == NULL || !dbus_connection_get_is_connected(conn)) return; dbus_gsm_set_connection(NULL); }
gboolean ibus_connection_is_connected (IBusConnection *connection) { IBusConnectionPrivate *priv; priv = IBUS_CONNECTION_GET_PRIVATE (connection); if (priv->connection == NULL) { return FALSE; } return dbus_connection_get_is_connected (priv->connection); }
static void finalize(GObject *base) { struct Private *priv = GET_PRIVATE(base); if (priv->connection) { if (dbus_connection_get_is_connected(priv->connection)) { dbus_connection_close(priv->connection); } dbus_connection_unref(priv->connection); } G_OBJECT_CLASS(joy_dbus_parent_class)->finalize(base); }
static void efl_dbus_dispatch_status(DBusConnection *connection, DBusDispatchStatus new_status, void *data) { DBusDispatchStatus status; if (dbus_connection_get_is_connected(connection) == FALSE) return; status = dbus_connection_get_dispatch_status(connection); if (status == DBUS_DISPATCH_DATA_REMAINS) ecore_timer_add(0, efl_dispatch_dbus, connection); }
static bool _changed(pxNetworkModule *s) { pxNetworkManagerNetworkModule *self = (pxNetworkManagerNetworkModule *) s; // Make sure we have a valid connection with a proper match DBusConnection *conn = self->conn; if (!conn || !dbus_connection_get_is_connected(conn)) { // If the connection was disconnected, // close it an clear the queue if (conn) { dbus_connection_close(conn); dbus_connection_read_write(conn, 0); for (DBusMessage *msg=NULL ; (msg = dbus_connection_pop_message(conn)) ; dbus_message_unref(msg)); } // Create a new connections conn = dbus_bus_get_private(DBUS_BUS_SYSTEM, NULL); self->conn = conn; if (!conn) return false; // If connection was successful, set it up dbus_connection_set_exit_on_disconnect(conn, false); dbus_bus_add_match(conn, "type='signal',interface='" NM_DBUS_INTERFACE "',member='StateChange'", NULL); dbus_connection_flush(conn); } // We are guaranteed a connection, // so check for incoming messages bool changed = false; while (true) { DBusMessage *msg = NULL; uint32_t state; // Pull messages off the queue dbus_connection_read_write(conn, 0); if (!(msg = dbus_connection_pop_message(conn))) break; // If a message is the right type and value, // we'll reset the network if (dbus_message_get_args(msg, NULL, DBUS_TYPE_UINT32, &state, DBUS_TYPE_INVALID)) if (state == NM_STATE_CONNECTED) changed = true; dbus_message_unref(msg); } return changed; }
static gboolean system_bus_reconnect(void *data) { DBusConnection *conn = get_dbus_connection(); struct hci_dev_list_req *dl = NULL; struct hci_dev_req *dr; int sk, i; gboolean ret_val = TRUE; if (conn) { if (dbus_connection_get_is_connected(conn)) return FALSE; } if (hcid_dbus_init() < 0) return TRUE; /* Create and bind HCI socket */ sk = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI); if (sk < 0) { error("Can't open HCI socket: %s (%d)", strerror(errno), errno); return TRUE; } dl = g_malloc0(HCI_MAX_DEV * sizeof(*dr) + sizeof(*dl)); dl->dev_num = HCI_MAX_DEV; dr = dl->dev_req; if (ioctl(sk, HCIGETDEVLIST, (void *) dl) < 0) { info("Can't get device list: %s (%d)", strerror(errno), errno); goto failed; } /* reset the default device */ manager_set_default_adapter(-1); /* FIXME: it shouldn't be needed to register adapters again */ for (i = 0; i < dl->dev_num; i++, dr++) manager_register_adapter(dr->dev_id, TRUE); ret_val = FALSE; failed: if (sk >= 0) close(sk); g_free(dl); return ret_val; }
/* * This function should be called before we're showing the * current volume on the screen... * * Because sometimes we can lost the connection to PulseAudio, * and meanwhile PulseAudio volume-values changed, and we * didn't get any info about those... */ void VolumeBarLogic::ping () { if ((dbus_conn != NULL) && (dbus_connection_get_is_connected (dbus_conn))) return; /* * Connection lost, re-query the values */ openConnection (true); stepsUpdated (currentvolume, currentmax); }
void hcid_dbus_exit(void) { DBusConnection *conn = get_dbus_connection(); if (!conn || !dbus_connection_get_is_connected(conn)) return; manager_cleanup(conn, "/"); set_dbus_connection(NULL); dbus_connection_unref(conn); }
static void wakeup_handler(void *data, int err, void *read_mask) { struct dbus_core_info *info = data; if (info->connection && FD_ISSET(info->fd, (fd_set *) read_mask)) { do { dbus_connection_read_write_dispatch(info->connection, 0); } while (info->connection && dbus_connection_get_is_connected(info->connection) && dbus_connection_get_dispatch_status(info->connection) == DBUS_DISPATCH_DATA_REMAINS); } }
/******************************************************************************* ** ** Function sdp_dbus_exit ** ** Description Exit function of sdp module ** *******************************************************************************/ void sdp_dbus_exit (void) { debug("Exit Obex interface"); // dtun_client_stop(DTUN_INTERFACE_OBEX); if (!conn || !dbus_connection_get_is_connected(conn)) { return; } g_dbus_unregister_interface(conn, BTLA_SDP_PATH, BTLA_SDP_INTERFACE); conn = NULL; }
static void _cs_dbus_rrp_faulty_event(char *nodename, uint32_t nodeid, uint32_t iface_no, const char *state) { DBusMessage *msg = NULL; if (err_set) { qb_log(LOG_ERR, "%s", _err); err_set = 0; } if (!db) { goto out_free; } if (dbus_connection_get_is_connected(db) != TRUE) { err_set = 1; snprintf(_err, sizeof(_err), "DBus connection lost"); _cs_dbus_release(); goto out_unlock; } _cs_dbus_auto_flush(); if (!(msg = dbus_message_new_signal(DBUS_CS_PATH, DBUS_CS_IFACE, "QuorumStateChange"))) { qb_log(LOG_ERR, "error creating dbus signal"); goto out_unlock; } if (!dbus_message_append_args(msg, DBUS_TYPE_STRING, &nodename, DBUS_TYPE_UINT32, &nodeid, DBUS_TYPE_UINT32, &iface_no, DBUS_TYPE_STRING, &state, DBUS_TYPE_INVALID)) { qb_log(LOG_ERR, "error adding args to rrp signal"); goto out_unlock; } dbus_connection_send(db, msg, NULL); out_unlock: if (msg) { dbus_message_unref(msg); } out_free: return; }
void pa_dbus_wrap_connection_free(pa_dbus_wrap_connection* c) { pa_assert(c); if (dbus_connection_get_is_connected(c->connection)) { dbus_connection_close(c->connection); /* must process remaining messages, bit of a kludge to handle * both unload and shutdown */ while (dbus_connection_read_write_dispatch(c->connection, -1)) ; } c->mainloop->defer_free(c->dispatch_event); dbus_connection_unref(c->connection); pa_xfree(c); }
int nfblock_dbus_send_blocked(log_func_t do_log, time_t curtime, dbus_log_message_t signal, bool dropped, char *addr, const char **ranges, uint32_t hits) { DBusMessage *dbmsg = NULL; dbus_bool_t dbb = TRUE; /* create dbus signal */ switch (signal) { case LOG_NF_IN: dbmsg = dbus_message_new_signal ("/org/netfilter/nfblock", "org.netfilter.nfblock.Blocked", "blocked_in"); break; case LOG_NF_OUT: dbmsg = dbus_message_new_signal ("/org/netfilter/nfblock", "org.netfilter.nfblock.Blocked", "blocked_out"); break; /* case LOG_NF_FWD: dbmsg = dbus_message_new_signal ("/org/netfilter/nfblock", "org.netfilter.nfblock.Blocked", "blocked_fwd"); assert(0); break; */ } if (!dbmsg) return -1; dbb &= nfblock_dbus_message_append_blocked(dbmsg, addr, ranges, hits, dropped, curtime); if (dbb && dbus_connection_get_is_connected(dbconn)) { dbus_connection_send (dbconn, dbmsg, NULL); } if (!dbb) do_log(LOG_CRIT, "Cannot create D-Bus message (out of memory?)."); dbus_message_unref(dbmsg); return dbb ? 0 : -1; }
JoyDBus * joy_dbus_new(JoyApplication *app, const gchar *address, GError **error) { joy_return_error_if_fail(JOY_IS_APPLICATION(app), NULL, error); joy_return_error_if_fail(address, NULL, error); DBusError dbus_error; dbus_error_init(&dbus_error); DBusConnection *connection = dbus_connection_open_private(address, &dbus_error); if (!connection) { g_set_error(error, JOY_ERROR, JOY_ERROR_DBUS, "%s", dbus_error.message); goto error; } if (!dbus_bus_register(connection, &dbus_error)) { g_set_error(error, JOY_ERROR, JOY_ERROR_DBUS, "%s", dbus_error.message); goto error; } JoyDBus *self = g_object_new(JOY_TYPE_DBUS, "application", app, "connection", connection, NULL); if (!self) { g_set_error_literal(error, JOY_ERROR, JOY_ERROR_NO_MEMORY, Q_("out of memory")); goto error; } if (!dbus_connection_set_watch_functions(connection, add, remove, toggled, self, NULL)) { g_set_error_literal(error, JOY_ERROR, JOY_ERROR_NO_MEMORY, Q_("out of memory")); goto error; } return self; error: dbus_error_free(&dbus_error); if (connection) { if (dbus_connection_get_is_connected(connection)) { dbus_connection_close(connection); } dbus_connection_unref(connection); } return NULL; }
int hal_ready(void) { if (hal_ctx && dbus_connection_get_is_connected(dbus_ctx)) { return 1; } else { /* The messy business of reconnecting. * dbus's design is crap when it comes to reconnecting. * If dbus is down, can't actually close the connection to hal, * since libhal wants to use dbus to do it. */ if (dbus_ctx) { dbus_connection_close(dbus_ctx); dbus_connection_unref(dbus_ctx); } dbus_ctx = NULL; hal_ctx = NULL; return connect_hal(); } }
static void disconnect_hook(void *data) { DBusError error; struct config_hal_info *info = data; if (info->hal_ctx) { if (dbus_connection_get_is_connected(info->system_bus)) { dbus_error_init(&error); if (!libhal_ctx_shutdown(info->hal_ctx, &error)) LogMessage(X_WARNING, "config/hal: disconnect_hook couldn't shut down context: %s (%s)\n", error.name, error.message); dbus_error_free(&error); } libhal_ctx_free(info->hal_ctx); } info->hal_ctx = NULL; info->system_bus = NULL; }
static DBusConnection* get_connection(GError **error) { DBusError derror; g_return_val_if_fail(error == NULL || *error == NULL, FALSE); if (session_connection && dbus_connection_get_is_connected(session_connection)) return session_connection; /* this unref is only allowed if we know it's disconnected */ if (session_connection) dbus_connection_unref(session_connection); dbus_error_init(&derror); session_connection = dbus_bus_get(DBUS_BUS_SESSION, &derror); if (session_connection == NULL) { propagate_dbus_error(error, &derror); } return session_connection; }
static gboolean systemd_init(void) { static int need_init = 1; /* http://dbus.freedesktop.org/doc/api/html/group__DBusConnection.html */ if (systemd_proxy && dbus_connection_get_is_connected(systemd_proxy) == FALSE) { crm_warn("Connection to System DBus is closed. Reconnecting..."); pcmk_dbus_disconnect(systemd_proxy); systemd_proxy = NULL; need_init = 1; } if (need_init) { need_init = 0; systemd_proxy = pcmk_dbus_connect(); } if (systemd_proxy == NULL) { return FALSE; } return TRUE; }
void PulseAudioControl::openConnection() { //! If the connection already exists, do nothing if ((dbusConnection != NULL) && (dbus_connection_get_is_connected(dbusConnection))) { return; } // Establish a connection to the server char *pa_bus_address = getenv("PULSE_DBUS_SERVER"); QByteArray addressArray; if (pa_bus_address == NULL) { QDBusMessage message = QDBusMessage::createMethodCall("org.pulseaudio.Server", "/org/pulseaudio/server_lookup1", "org.freedesktop.DBus.Properties", "Get"); message.setArguments(QVariantList() << "org.PulseAudio.ServerLookup1" << "Address"); QDBusMessage reply = QDBusConnection::sessionBus().call(message); if (reply.type() == QDBusMessage::ReplyMessage && reply.arguments().count() > 0) { addressArray = reply.arguments().first().value<QDBusVariant>().variant().toString().toAscii(); pa_bus_address = addressArray.data(); } } if (pa_bus_address != NULL) { DBusError dbus_err; dbus_error_init(&dbus_err); dbusConnection = dbus_connection_open(pa_bus_address, &dbus_err); DBUS_ERR_CHECK(dbus_err); } if (dbusConnection != NULL) { dbus_connection_setup_with_g_main(dbusConnection, NULL); dbus_connection_add_filter(dbusConnection, PulseAudioControl::stepsUpdatedSignalHandler, (void *)this, NULL); addSignalMatch(); } }
static int sync_auth(DBusConnection *bus, DBusError *error) { usec_t begin, tstamp; assert(bus); /* This complexity should probably move into D-Bus itself: * * https://bugs.freedesktop.org/show_bug.cgi?id=35189 */ begin = tstamp = now(CLOCK_MONOTONIC); for (;;) { if (tstamp > begin + DEFAULT_TIMEOUT_USEC) break; if (dbus_connection_get_is_authenticated(bus)) break; if (!dbus_connection_read_write_dispatch(bus, ((begin + DEFAULT_TIMEOUT_USEC - tstamp) + USEC_PER_MSEC - 1) / USEC_PER_MSEC)) break; tstamp = now(CLOCK_MONOTONIC); } if (!dbus_connection_get_is_connected(bus)) { dbus_set_error_const(error, DBUS_ERROR_NO_SERVER, "Connection terminated during authentication."); return -ECONNREFUSED; } if (!dbus_connection_get_is_authenticated(bus)) { dbus_set_error_const(error, DBUS_ERROR_TIMEOUT, "Failed to authenticate in time."); return -EACCES; } return 0; }
HippoSystemDBus* hippo_system_dbus_open(GError **error) { HippoSystemDBus *dbus; DBusGConnection *gconnection; DBusConnection *connection; DBusError derror; g_debug("attempting connect to system dbus"); /* dbus_bus_get is a little hosed in old versions since you can't * unref unless you know it's disconnected. I guess it turns out * we more or less want to do that anyway. */ gconnection = dbus_g_bus_get(DBUS_BUS_SYSTEM, error); if (gconnection == NULL) return NULL; connection = dbus_g_connection_get_connection(gconnection); /* the purpose of this check is to be sure we will get a "Disconnected" * message in the future */ if (!dbus_connection_get_is_connected(connection)) { dbus_connection_unref(connection); g_set_error(error, HIPPO_ERROR, HIPPO_ERROR_FAILED, _("No active connection to the system's message bus")); return NULL; } dbus_error_init(&derror); /* Add NetworkManager signal match */ dbus_bus_add_match(connection, "type='signal',sender='" "org.freedesktop.NetworkManager" "',interface='" "org.freedesktop.NetworkManager" "',member='" "StateChange" "'", &derror); dbus_bus_add_match(connection, "type='signal',sender='" "com.nokia.icd" "',interface='" "com.nokia.icd" "',member='" "status_changed" "'", &derror); if (dbus_error_is_set(&derror)) { propagate_dbus_error(error, &derror); /* FIXME leak bus connection since unref isn't allowed */ return NULL; } /* the connection is already set up with the main loop. * We just need to create our object, filters, etc. */ g_debug("D-BUS system bus connection established"); dbus = g_object_new(HIPPO_TYPE_SYSTEM_DBUS, NULL); dbus->connection = connection; if (!dbus_connection_add_filter(connection, handle_message, dbus, NULL)) g_error("no memory adding system dbus connection filter"); /* add an extra ref, which is owned by the "connected" state on * the connection. We drop it in our filter func if we get * the disconnected message or lose our bus name. */ g_object_ref(dbus); /* we'll deal with this ourselves */ dbus_connection_set_exit_on_disconnect(connection, FALSE); /* also returning a ref to the caller */ return dbus; }
int /* O - Exit status */ main(int argc, /* I - Number of command-line args */ char *argv[]) /* I - Command-line arguments */ { ipp_t *msg; /* Event message from scheduler */ ipp_state_t state; /* IPP event state */ struct sigaction action; /* POSIX sigaction data */ DBusConnection *con = NULL; /* Connection to DBUS server */ DBusError error; /* Error, if any */ DBusMessage *message; /* Message to send */ DBusMessageIter iter; /* Iterator for message data */ int lock_fd = -1; /* Lock file descriptor */ /* * Don't buffer stderr... */ setbuf(stderr, NULL); /* * Ignore SIGPIPE signals... */ memset(&action, 0, sizeof(action)); action.sa_handler = SIG_IGN; sigaction(SIGPIPE, &action, NULL); /* * Validate command-line options... */ if (argc != 3) { fputs("Usage: dbus dbus:/// notify-user-data\n", stderr); return (1); } if (strncmp(argv[1], "dbus:", 5)) { fprintf(stderr, "ERROR: Bad URI \"%s\"!\n", argv[1]); return (1); } /* * Loop forever until we run out of events... */ for (;;) { ipp_attribute_t *attr; /* Current attribute */ const char *event; /* Event name */ const char *signame = NULL;/* DBUS signal name */ char *printer_reasons = NULL; /* Printer reasons string */ char *job_reasons = NULL; /* Job reasons string */ const char *nul = ""; /* Empty string value */ int no = 0; /* Boolean "no" value */ int params = PARAMS_NONE; /* What parameters to include? */ /* * Get the next event... */ msg = ippNew(); while ((state = ippReadFile(0, msg)) != IPP_DATA) { if (state <= IPP_IDLE) break; } fprintf(stderr, "DEBUG: state=%d\n", state); if (state == IPP_ERROR) fputs("DEBUG: ippReadFile() returned IPP_ERROR!\n", stderr); if (state <= IPP_IDLE) { /* * Out of messages, free memory and then exit... */ ippDelete(msg); break; } /* * Verify connection to DBUS server... */ if (con && !dbus_connection_get_is_connected(con)) { dbus_connection_unref(con); con = NULL; } if (!con) { dbus_error_init(&error); con = dbus_bus_get(DBUS_BUS_SYSTEM, &error); if (!con) dbus_error_free(&error); else fputs("DEBUG: Connected to D-BUS\n", stderr); } if (!con) continue; if (lock_fd == -1 && acquire_lock(&lock_fd, lock_filename, sizeof(lock_filename))) continue; attr = ippFindAttribute(msg, "notify-subscribed-event", IPP_TAG_KEYWORD); if (!attr) continue; event = ippGetString(attr, 0, NULL); if (!strncmp(event, "server-", 7)) { const char *word2 = event + 7; /* Second word */ if (!strcmp(word2, "restarted")) signame = "ServerRestarted"; else if (!strcmp(word2, "started")) signame = "ServerStarted"; else if (!strcmp(word2, "stopped")) signame = "ServerStopped"; else if (!strcmp(word2, "audit")) signame = "ServerAudit"; else continue; } else if (!strncmp(event, "printer-", 8)) { const char *word2 = event + 8; /* Second word */ params = PARAMS_PRINTER; if (!strcmp(word2, "restarted")) signame = "PrinterRestarted"; else if (!strcmp(word2, "shutdown")) signame = "PrinterShutdown"; else if (!strcmp(word2, "stopped")) signame = "PrinterStopped"; else if (!strcmp(word2, "state-changed")) signame = "PrinterStateChanged"; else if (!strcmp(word2, "finishings-changed")) signame = "PrinterFinishingsChanged"; else if (!strcmp(word2, "media-changed")) signame = "PrinterMediaChanged"; else if (!strcmp(word2, "added")) signame = "PrinterAdded"; else if (!strcmp(word2, "deleted")) signame = "PrinterDeleted"; else if (!strcmp(word2, "modified")) signame = "PrinterModified"; else continue; } else if (!strncmp(event, "job-", 4)) { const char *word2 = event + 4; /* Second word */ params = PARAMS_JOB; if (!strcmp(word2, "state-changed")) signame = "JobState"; else if (!strcmp(word2, "created")) signame = "JobCreated"; else if (!strcmp(word2, "completed")) signame = "JobCompleted"; else if (!strcmp(word2, "stopped")) signame = "JobStopped"; else if (!strcmp(word2, "config-changed")) signame = "JobConfigChanged"; else if (!strcmp(word2, "progress")) signame = "JobProgress"; else continue; } else continue; /* * Create and send the new message... */ fprintf(stderr, "DEBUG: %s\n", signame); message = dbus_message_new_signal("/org/cups/cupsd/Notifier", "org.cups.cupsd.Notifier", signame); dbus_message_append_iter_init(message, &iter); attr = ippFindAttribute(msg, "notify-text", IPP_TAG_TEXT); if (attr) { const char *val = ippGetString(attr, 0, NULL); if (!dbus_message_iter_append_string(&iter, &val)) goto bail; } else goto bail; if (params >= PARAMS_PRINTER) { char *p; /* Pointer into printer_reasons */ size_t reasons_length; /* Required size of printer_reasons */ int i; /* Looping var */ int have_printer_params = 1;/* Do we have printer URI? */ /* STRING printer-uri or "" */ attr = ippFindAttribute(msg, "notify-printer-uri", IPP_TAG_URI); if (attr) { const char *val = ippGetString(attr, 0, NULL); if (!dbus_message_iter_append_string(&iter, &val)) goto bail; } else { have_printer_params = 0; dbus_message_iter_append_string(&iter, &nul); } /* STRING printer-name */ if (have_printer_params) { attr = ippFindAttribute(msg, "printer-name", IPP_TAG_NAME); if (attr) { const char *val = ippGetString(attr, 0, NULL); if (!dbus_message_iter_append_string(&iter, &val)) goto bail; } else goto bail; } else dbus_message_iter_append_string(&iter, &nul); /* UINT32 printer-state */ if (have_printer_params) { attr = ippFindAttribute(msg, "printer-state", IPP_TAG_ENUM); if (attr) { dbus_uint32_t val = ippGetInteger(attr, 0); dbus_message_iter_append_uint32(&iter, &val); } else goto bail; } else dbus_message_iter_append_uint32(&iter, &no); /* STRING printer-state-reasons */ if (have_printer_params) { attr = ippFindAttribute(msg, "printer-state-reasons", IPP_TAG_KEYWORD); if (attr) { int num_values = ippGetCount(attr); for (reasons_length = 0, i = 0; i < num_values; i++) /* All need commas except the last, which needs a nul byte. */ reasons_length += 1 + strlen(ippGetString(attr, i, NULL)); printer_reasons = malloc(reasons_length); if (!printer_reasons) goto bail; p = printer_reasons; for (i = 0; i < num_values; i++) { if (i) *p++ = ','; strlcpy(p, ippGetString(attr, i, NULL), reasons_length - (p - printer_reasons)); p += strlen(p); } if (!dbus_message_iter_append_string(&iter, &printer_reasons)) goto bail; } else goto bail; } else dbus_message_iter_append_string(&iter, &nul); /* BOOL printer-is-accepting-jobs */ if (have_printer_params) { attr = ippFindAttribute(msg, "printer-is-accepting-jobs", IPP_TAG_BOOLEAN); if (attr) { dbus_bool_t val = ippGetBoolean(attr, 0); dbus_message_iter_append_boolean(&iter, &val); } else goto bail; } else dbus_message_iter_append_boolean(&iter, &no); } if (params >= PARAMS_JOB) { char *p; /* Pointer into job_reasons */ size_t reasons_length; /* Required size of job_reasons */ int i; /* Looping var */ /* UINT32 job-id */ attr = ippFindAttribute(msg, "notify-job-id", IPP_TAG_INTEGER); if (attr) { dbus_uint32_t val = ippGetInteger(attr, 0); dbus_message_iter_append_uint32(&iter, &val); } else goto bail; /* UINT32 job-state */ attr = ippFindAttribute(msg, "job-state", IPP_TAG_ENUM); if (attr) { dbus_uint32_t val = ippGetInteger(attr, 0); dbus_message_iter_append_uint32(&iter, &val); } else goto bail; /* STRING job-state-reasons */ attr = ippFindAttribute(msg, "job-state-reasons", IPP_TAG_KEYWORD); if (attr) { int num_values = ippGetCount(attr); for (reasons_length = 0, i = 0; i < num_values; i++) /* All need commas except the last, which needs a nul byte. */ reasons_length += 1 + strlen(ippGetString(attr, i, NULL)); job_reasons = malloc(reasons_length); if (!job_reasons) goto bail; p = job_reasons; for (i = 0; i < num_values; i++) { if (i) *p++ = ','; strlcpy(p, ippGetString(attr, i, NULL), reasons_length - (p - job_reasons)); p += strlen(p); } if (!dbus_message_iter_append_string(&iter, &job_reasons)) goto bail; } else goto bail; /* STRING job-name or "" */ attr = ippFindAttribute(msg, "job-name", IPP_TAG_NAME); if (attr) { const char *val = ippGetString(attr, 0, NULL); if (!dbus_message_iter_append_string(&iter, &val)) goto bail; } else dbus_message_iter_append_string(&iter, &nul); /* UINT32 job-impressions-completed */ attr = ippFindAttribute(msg, "job-impressions-completed", IPP_TAG_INTEGER); if (attr) { dbus_uint32_t val = ippGetInteger(attr, 0); dbus_message_iter_append_uint32(&iter, &val); } else goto bail; } dbus_connection_send(con, message, NULL); dbus_connection_flush(con); /* * Cleanup... */ bail: dbus_message_unref(message); if (printer_reasons) free(printer_reasons); if (job_reasons) free(job_reasons); ippDelete(msg); } /* * Remove lock file... */ if (lock_fd >= 0) { close(lock_fd); release_lock(); } return (0); }
static void cupsd_send_dbus(cupsd_eventmask_t event,/* I - Event to send */ cupsd_printer_t *dest,/* I - Destination, if any */ cupsd_job_t *job) /* I - Job, if any */ { DBusError error; /* Error, if any */ DBusMessage *message; /* Message to send */ DBusMessageIter iter; /* Iterator for message data */ const char *what; /* What to send */ static DBusConnection *con = NULL; /* Connection to DBUS server */ /* * Figure out what to send, if anything... */ if (event & CUPSD_EVENT_PRINTER_ADDED) what = "PrinterAdded"; else if (event & CUPSD_EVENT_PRINTER_DELETED) what = "PrinterRemoved"; else if (event & CUPSD_EVENT_PRINTER_CHANGED) what = "QueueChanged"; else if (event & CUPSD_EVENT_JOB_CREATED) what = "JobQueuedLocal"; else if ((event & CUPSD_EVENT_JOB_STATE) && job && job->state_value == IPP_JOB_PROCESSING) what = "JobStartedLocal"; else return; /* * Verify connection to DBUS server... */ if (con && !dbus_connection_get_is_connected(con)) { dbus_connection_unref(con); con = NULL; } if (!con) { dbus_error_init(&error); con = dbus_bus_get(getuid() ? DBUS_BUS_SESSION : DBUS_BUS_SYSTEM, &error); if (!con) { dbus_error_free(&error); return; } } /* * Create and send the new message... */ message = dbus_message_new_signal("/com/redhat/PrinterSpooler", "com.redhat.PrinterSpooler", what); dbus_message_append_iter_init(message, &iter); if (dest) dbus_message_iter_append_string(&iter, dest->name); if (job) { dbus_message_iter_append_uint32(&iter, job->id); dbus_message_iter_append_string(&iter, job->username); } dbus_connection_send(con, message, NULL); dbus_connection_flush(con); dbus_message_unref(message); }