static void pin_callback(GtkWidget *dialog, gint response, gpointer user_data) { input_data *input = user_data; if (response == GTK_RESPONSE_OK) { const char *text; text = gtk_entry_get_text(GTK_ENTRY(input->entry)); if (input->numeric == TRUE) { guint pin = atoi(text); dbus_g_method_return(input->context, pin); } else { dbus_g_method_return(input->context, text); } } else { GError *error; error = g_error_new(AGENT_ERROR, AGENT_ERROR_REJECT, "Pairing request rejected"); dbus_g_method_return_error(input->context, error); } input_free(input); }
void _odccm_connection_broker_take_connection (OdccmConnectionBroker *self, GConn *conn) { OdccmConnectionBrokerPrivate *priv = ODCCM_CONNECTION_BROKER_GET_PRIVATE (self); GRand *rnd; GIOChannel *chan; guint uid; g_assert (priv->conn == NULL); priv->conn = conn; rnd = g_rand_new (); priv->filename = g_strdup_printf ("/tmp/odccm-%08x%08x%08x%08x.sock", g_rand_int (rnd), g_rand_int (rnd), g_rand_int (rnd), g_rand_int (rnd)); g_rand_free (rnd); priv->server = gnet_unix_socket_server_new (priv->filename); _odccm_get_dbus_sender_uid (dbus_g_method_get_sender (priv->ctx), &uid); chmod (priv->filename, S_IRUSR | S_IWUSR); chown (priv->filename, uid, -1); chan = gnet_unix_socket_get_io_channel (priv->server); g_io_add_watch (chan, G_IO_IN, server_socket_readable_cb, self); dbus_g_method_return (priv->ctx, priv->filename); priv->ctx = NULL; }
/** * up_device_get_statistics: **/ gboolean up_device_get_statistics (UpDevice *device, const gchar *type, DBusGMethodInvocation *context) { GError *error; GPtrArray *array = NULL; GPtrArray *complex; UpStatsItem *item; GValue *value; guint i; g_return_val_if_fail (UP_IS_DEVICE (device), FALSE); g_return_val_if_fail (type != NULL, FALSE); /* doesn't even try to support this */ if (!device->priv->has_statistics) { error = g_error_new (UP_DAEMON_ERROR, UP_DAEMON_ERROR_GENERAL, "device does not support getting stats"); dbus_g_method_return_error (context, error); goto out; } /* get the correct data */ if (g_strcmp0 (type, "charging") == 0) array = up_history_get_profile_data (device->priv->history, TRUE); else if (g_strcmp0 (type, "discharging") == 0) array = up_history_get_profile_data (device->priv->history, FALSE); /* maybe the device doesn't support histories */ if (array == NULL) { error = g_error_new (UP_DAEMON_ERROR, UP_DAEMON_ERROR_GENERAL, "device has no statistics"); dbus_g_method_return_error (context, error); goto out; } /* always 101 items of data */ if (array->len != 101) { error = g_error_new (UP_DAEMON_ERROR, UP_DAEMON_ERROR_GENERAL, "statistics invalid as have %i items", array->len); dbus_g_method_return_error (context, error); goto out; } /* copy data to dbus struct */ complex = g_ptr_array_sized_new (array->len); for (i=0; i<array->len; i++) { item = (UpStatsItem *) g_ptr_array_index (array, i); value = g_new0 (GValue, 1); g_value_init (value, UP_DBUS_STRUCT_DOUBLE_DOUBLE); g_value_take_boxed (value, dbus_g_type_specialized_construct (UP_DBUS_STRUCT_DOUBLE_DOUBLE)); dbus_g_type_struct_set (value, 0, up_stats_item_get_value (item), 1, up_stats_item_get_accuracy (item), -1); g_ptr_array_add (complex, g_value_get_boxed (value)); g_free (value); } dbus_g_method_return (context, complex); out: if (array != NULL) g_ptr_array_unref (array); return TRUE; }
static LmHandlerResult set_location_sent_cb (GabbleConnection *conn, LmMessage *sent_msg, LmMessage *reply_msg, GObject *object, gpointer user_data) { DBusGMethodInvocation *context = user_data; GError *error = NULL; error = gabble_message_get_xmpp_error (reply_msg); if (error == NULL) { dbus_g_method_return (context); } else { GError tp_error = { TP_ERRORS, TP_ERROR_NETWORK_ERROR, error->message }; DEBUG ("SetLocation failed: %s", error->message); dbus_g_method_return_error (context, &tp_error); g_error_free (error); } return LM_HANDLER_RESULT_REMOVE_MESSAGE; }
gboolean Services_list(Matahari *matahari, DBusGMethodInvocation *context) { GError* error = NULL; int i = 0; GList *services; char **list; if (!check_authorization(SERVICES_BUS_NAME ".list", &error, context)) { dbus_g_method_return_error(context, error); return FALSE; } // Get list of services services = services_list(); // Convert GList to (char **) list = g_new(char *, g_list_length(services) + 1); for (; services != NULL; services = services->next) list[i++] = strdup(services->data); list[i] = NULL; // Sentinel dbus_g_method_return(context, list); g_strfreev(list); g_list_free(services); return TRUE; }
gboolean Resources_list(Matahari *matahari, const char *standard, const char *provider, DBusGMethodInvocation *context) { GError* error = NULL; int i = 0; gchar **list; GList *agents = NULL; if (!check_authorization(RESOURCES_INTERFACE_NAME ".list", &error, context)) { dbus_g_method_return_error(context, error); g_error_free(error); return FALSE; } if (strlen(standard) == 0) standard = "ocf"; if (strlen(provider) == 0) provider = "heartbeat"; // Get list of agents agents = resources_list_agents(standard, provider); // Convert GList to (char **) list = g_new(char *, g_list_length(agents) + 1); for (; agents != NULL; agents = agents->next) list[i++] = strdup(agents->data); list[i] = NULL; // Sentinel dbus_g_method_return(context, list); g_strfreev(list); g_list_free_full(agents, free); return TRUE; }
void invoke_cb(svc_action_t *op) { struct invoke_cb_data *cb_data = op->cb_data; dbus_g_method_return(cb_data->context, op->rc, op->sequence, cb_data->userdata); free(cb_data->userdata); free(cb_data); }
static gboolean __bt_progress_callback(DBusGMethodInvocation *context, DBusGProxy *transfer, guint64 transferred, gpointer user_data) { int percentage_progress; gint64 size; int result = BLUETOOTH_ERROR_NONE; dbus_g_method_return(context); retv_if(sending_info == NULL, TRUE); retv_if(sending_info->transfer_info == NULL, TRUE); size = sending_info->transfer_info->size; if (size != 0) percentage_progress = (int)(((gdouble)transferred / (gdouble)size) * 100); else percentage_progress = 0; /* Send the event in only error none case */ _bt_send_event(BT_OPP_CLIENT_EVENT, BLUETOOTH_EVENT_OPC_TRANSFER_PROGRESS, DBUS_TYPE_INT32, &result, DBUS_TYPE_STRING, &sending_info->transfer_info->file_name, DBUS_TYPE_UINT64, &sending_info->transfer_info->size, DBUS_TYPE_INT32, &percentage_progress, DBUS_TYPE_INT32, &sending_info->request_id, DBUS_TYPE_INVALID); return TRUE; }
gboolean Resources_list_providers(Matahari *matahari, const char *standard, DBusGMethodInvocation *context) { GError* error = NULL; gchar **list; int i = 0; GList *providers; if (!check_authorization(RESOURCES_INTERFACE_NAME ".list_providers", &error, context)) { dbus_g_method_return_error(context, error); g_error_free(error); return FALSE; } // Get list of providers providers = resources_list_providers(standard); // Convert GList to (char **) list = g_new(char *, g_list_length(providers) + 1); for (; providers != NULL; providers = providers->next) list[i++] = strdup(providers->data); list[i] = NULL; // Sentinel dbus_g_method_return(context, list); g_strfreev(list); g_list_free_full(providers, free); return TRUE; }
void ring_text_manager_expunge_messages(RingTextManager *self, char const **messages, gpointer context) { /* XXX/KV: use ring_text_manager_is_connected () */ if (self->priv->status == TP_CONNECTION_STATUS_CONNECTED) { int i; ModemSMSService *service = self->priv->sms_service; GPtrArray *expunged = g_ptr_array_new(); for (i = 0; messages[i]; i++) { if (modem_sms_request_expunge(service, messages[i], NULL, NULL)) { g_ptr_array_add(expunged, (gpointer)g_strdup(messages[i])); } } g_ptr_array_add(expunged, NULL); dbus_g_method_return(context); rtcom_tp_svc_connection_interface_stored_messages_emit_messages_expunged( self->priv->connection, (char const **)expunged->pdata); g_strfreev((char **)g_ptr_array_free(expunged, FALSE)); } else { ring_text_manager_not_connected(context); } }
static void set_location_sent_cb (GabbleConnection *conn, WockyStanza *sent_msg, WockyStanza *reply_msg, GObject *object, gpointer user_data) { DBusGMethodInvocation *context = user_data; GError *error = NULL; if (!wocky_stanza_extract_errors (reply_msg, NULL, &error, NULL, NULL)) { dbus_g_method_return (context); } else { GError *tp_error = NULL; DEBUG ("SetLocation failed: %s", error->message); gabble_set_tp_error_from_wocky (error, &tp_error); dbus_g_method_return_error (context, tp_error); g_error_free (tp_error); g_error_free (error); } }
static int __bt_obex_server_reply_authorize(const guint accept, const char *filepath, obex_server_info_t *obex_server_info) { DBG("+\n"); if (obex_server_info) { if (accept == BT_OBEX_AGENT_ACCEPT) { dbus_g_method_return(obex_server_info->reply_context, filepath); } else { GError *error = NULL; error = __bt_obex_agent_error(BT_OBEX_AGENT_ERROR_CANCEL, "CanceledbyUser"); dbus_g_method_return_error(obex_server_info->reply_context, error); g_error_free(error); g_free(obex_server_info->filename); obex_server_info->filename = NULL; g_free(obex_server_info->transfer_path); obex_server_info->transfer_path = NULL; g_free(obex_server_info->device_name); obex_server_info->device_name = NULL; } } DBG("-\n"); return BLUETOOTH_ERROR_NONE; }
gboolean Host_list_power_profiles(Matahari* matahari, DBusGMethodInvocation *context) { GError *error = NULL; GList *list, *plist; char **profiles; int i = 0; if (!check_authorization(HOST_BUS_NAME ".list_power_profiles", &error, context)) { dbus_g_method_return_error(context, error); g_error_free(error); return FALSE; } // Get the list of profiles list = mh_host_list_power_profiles(); // Convert GList * with profiles to array (char **) profiles = g_new(char *, g_list_length(list) + 1); for (plist = g_list_first(list); plist; plist = g_list_next(plist)) { profiles[i++] = plist->data; } profiles[i] = NULL; // Sentinel dbus_g_method_return(context, profiles); g_list_free_full(list, free); g_free(profiles); return TRUE; }
static gboolean _set_time (GsdDatetimeMechanism *mechanism, const struct timeval *tv, DBusGMethodInvocation *context) { GError *error; if (!_check_polkit_for_action (mechanism, context)) return FALSE; if (settimeofday (tv, NULL) != 0) { error = g_error_new (GSD_DATETIME_MECHANISM_ERROR, GSD_DATETIME_MECHANISM_ERROR_GENERAL, "Error calling settimeofday({%lld,%lld}): %s", (gint64) tv->tv_sec, (gint64) tv->tv_usec, strerror (errno)); dbus_g_method_return_error (context, error); g_error_free (error); return FALSE; } if (!_sync_hwclock (context)) return FALSE; dbus_g_method_return (context); return TRUE; }
static gboolean do_async_increment (IncrementData *data) { gint32 newx = data->x + 1; dbus_g_method_return (data->context, newx); g_free (data); return FALSE; }
static void async_call_done (MMModem *modem, GError *error, gpointer user_data) { DBusGMethodInvocation *context = (DBusGMethodInvocation *) user_data; if (error) dbus_g_method_return_error (context, error); else dbus_g_method_return (context); }
/* IN_args contains that path to the GPS device we wish to open */ static void gypsy_server_create (GypsyServer *gps, const char *IN_device_path, DBusGMethodInvocation *context) { GypsyServerPrivate *priv; GypsyClient *client; char *path, *device_name, *sender; GList *list; priv = GET_PRIVATE (gps); /* We might be in the termination timeout when we receive a new create request, so cancel that timeout */ if (priv->terminate_id > 0) { g_source_remove (priv->terminate_id); priv->terminate_id = 0; } g_debug ("Creating client for %s", IN_device_path); device_name = g_path_get_basename (IN_device_path); g_debug ("Device name: %s", device_name); path = g_strdup_printf ("%s%s", GYPSY_GPS_PATH, g_strdelimit (device_name, ":", '_')); g_free (device_name); client = (GypsyClient *) dbus_g_connection_lookup_g_object (priv->connection, path); if (client == NULL) { /* If there isn't already an object registered on that path create and register it */ client = g_object_new (GYPSY_TYPE_CLIENT, "device_path", IN_device_path, NULL); dbus_g_connection_register_g_object (priv->connection, path, G_OBJECT (client)); } else { /* Ref the client so that when one client calls shutdown we won't destroy another clients object */ g_object_ref (client); } g_debug ("Registered client on %s", path); /* Update the hash of open connnctions */ sender = dbus_g_method_get_sender (context); list = g_hash_table_lookup (priv->connections, sender); list = g_list_prepend (list, client); g_hash_table_insert (priv->connections, sender, list); priv->client_count++; dbus_g_method_return (context, path); g_free (path); }
static void check_can_do (GsdDatetimeMechanism *mechanism, const char *action, DBusGMethodInvocation *context) { const char *sender; PolkitSubject *subject; PolkitAuthorizationResult *result; GError *error; /* Check that caller is privileged */ sender = dbus_g_method_get_sender (context); subject = polkit_system_bus_name_new (sender); error = NULL; result = polkit_authority_check_authorization_sync (mechanism->priv->auth, subject, action, NULL, 0, NULL, &error); g_object_unref (subject); if (error) { dbus_g_method_return_error (context, error); g_error_free (error); return; } if (polkit_authorization_result_get_is_authorized (result)) { dbus_g_method_return (context, 2); } else if (polkit_authorization_result_get_is_challenge (result)) { dbus_g_method_return (context, 1); } else { dbus_g_method_return (context, 0); } g_object_unref (result); }
static void ring_text_manager_set_storage_status_reply(ModemSMSService *service, ModemRequest *request, GError *error, gpointer context) { if (!error) dbus_g_method_return(context); else dbus_g_method_return_error(context, error); }
/** * up_device_refresh: * * Return %TRUE on success, %FALSE if we failed to refresh or no data **/ gboolean up_device_refresh (UpDevice *device, DBusGMethodInvocation *context) { gboolean ret; g_return_val_if_fail (UP_IS_DEVICE (device), FALSE); ret = up_device_refresh_internal (device); dbus_g_method_return (context); return ret; }
gboolean eas_add_item_req_MessageComplete (EasAddItemReq *self, xmlDoc* doc, GError* error) { GError *local_error = NULL; EasAddItemReqPrivate *priv = self->priv; GSList* added_items = NULL; gchar** ret_added_items_array = NULL; EasRequestBase *parent = EAS_REQUEST_BASE (&self->parent_instance); g_debug ("eas_add_item_req_MessageComplete++"); // If we have an error send it back to client if (error) { local_error = error; goto finish; } if (FALSE == eas_sync_msg_parse_response (priv->sync_msg, doc, &local_error)) { goto finish; } added_items = eas_sync_msg_get_added_items (priv->sync_msg); build_serialised_calendar_info_array (&ret_added_items_array, added_items, &error); finish: if (local_error) { dbus_g_method_return_error (eas_request_base_GetContext (parent), local_error); g_error_free (local_error); } else { dbus_g_method_return (eas_request_base_GetContext (parent), eas_sync_msg_get_syncKey (priv->sync_msg), ret_added_items_array); if (ret_added_items_array) { gint index = 0; while (NULL != ret_added_items_array[index]) { g_free (ret_added_items_array[index]); ret_added_items_array[index] = NULL; ++ index; } g_free (ret_added_items_array); ret_added_items_array = NULL; } } // We always need to free 'doc' and release the semaphore. xmlFreeDoc (doc); g_debug ("eas_add_item_req_MessageComplete--"); return TRUE; }
static void dbus_add_connection_cb (NMSettingsInterface *settings, GError *error, gpointer user_data) { DBusGMethodInvocation *context = user_data; if (error) dbus_g_method_return_error (context, error); else dbus_g_method_return (context); }
gboolean gsd_datetime_mechanism_get_hardware_clock_using_utc (GsdDatetimeMechanism *mechanism, DBusGMethodInvocation *context) { char **lines; char *data; gsize len; GError *error; gboolean is_utc; error = NULL; if (!g_file_get_contents ("/etc/adjtime", &data, &len, &error)) { GError *error2; error2 = g_error_new (GSD_DATETIME_MECHANISM_ERROR, GSD_DATETIME_MECHANISM_ERROR_GENERAL, "Error reading /etc/adjtime file: %s", error->message); g_error_free (error); dbus_g_method_return_error (context, error2); g_error_free (error2); return FALSE; } lines = g_strsplit (data, "\n", 0); g_free (data); if (g_strv_length (lines) < 3) { error = g_error_new (GSD_DATETIME_MECHANISM_ERROR, GSD_DATETIME_MECHANISM_ERROR_GENERAL, "Cannot parse /etc/adjtime"); dbus_g_method_return_error (context, error); g_error_free (error); g_strfreev (lines); return FALSE; } if (strcmp (lines[2], "UTC") == 0) { is_utc = TRUE; } else if (strcmp (lines[2], "LOCAL") == 0) { is_utc = FALSE; } else { error = g_error_new (GSD_DATETIME_MECHANISM_ERROR, GSD_DATETIME_MECHANISM_ERROR_GENERAL, "Expected UTC or LOCAL at line 3 of /etc/adjtime; found '%s'", lines[2]); dbus_g_method_return_error (context, error); g_error_free (error); g_strfreev (lines); return FALSE; } g_strfreev (lines); dbus_g_method_return (context, is_utc); return TRUE; }
gboolean _set_using_ntp_fedora (DBusGMethodInvocation *context, gboolean using_ntp) { GError *error; int exit_status; const char *ntp_client; char *cmd; error = NULL; ntp_client = get_ntp_client (); /* We omit --level 2345 so that systemd doesn't try to use the * SysV init scripts */ cmd = g_strconcat ("/sbin/chkconfig ", ntp_client, " ", using_ntp ? "on" : "off", NULL); if (!g_spawn_command_line_sync (cmd, NULL, NULL, &exit_status, &error)) { GError *error2; error2 = g_error_new (GSD_DATETIME_MECHANISM_ERROR, GSD_DATETIME_MECHANISM_ERROR_GENERAL, "Error spawning '%s': %s", cmd, error->message); g_error_free (error); dbus_g_method_return_error (context, error2); g_error_free (error2); g_free (cmd); return FALSE; } g_free (cmd); cmd = g_strconcat ("/sbin/service ", ntp_client, " ", using_ntp ? "restart" : "stop", NULL);; if (!g_spawn_command_line_sync (cmd, NULL, NULL, &exit_status, &error)) { GError *error2; error2 = g_error_new (GSD_DATETIME_MECHANISM_ERROR, GSD_DATETIME_MECHANISM_ERROR_GENERAL, "Error spawning '%s': %s", cmd, error->message); g_error_free (error); dbus_g_method_return_error (context, error2); g_error_free (error2); g_free (cmd); return FALSE; } g_free (cmd); dbus_g_method_return (context); return TRUE; }
/** * DBus message handler for the UserLoggedOff method. * * This method is called to notify the client that the PSM Daemon * has logged off a user. */ gboolean psmclient_user_logged_off ( PSMClient *server, gchar *oldUser, DBusGMethodInvocation *context) { gboolean success = TRUE; g_message("PSMClient: UserLoggedOff called, old user = %s", oldUser); dbus_g_method_return(context); return success; }
gboolean Host_reboot(Matahari* matahari, DBusGMethodInvocation *context) { GError* error = NULL; if (!check_authorization(HOST_BUS_NAME ".reboot", &error, context)) { dbus_g_method_return_error(context, error); g_error_free(error); return FALSE; } mh_host_reboot(); dbus_g_method_return(context, TRUE); return TRUE; }
static void gypsy_server_shutdown (GypsyServer *gps, const char *IN_device_path, DBusGMethodInvocation *context) { GypsyServerPrivate *priv; GypsyClient *client; GList *list, *owner; char *path, *device_name, *sender; priv = GET_PRIVATE (gps); g_debug ("Finding client for %s", IN_device_path); device_name = g_path_get_basename (IN_device_path); g_debug ("Device name: %s", device_name); path = g_strdup_printf ("%s%s", GYPSY_GPS_PATH, device_name); client = (GypsyClient *) dbus_g_connection_lookup_g_object (priv->connection, path); g_free (path); if (client == NULL) { dbus_g_method_return_error (context, g_error_new (GYPSY_SERVER_ERROR, GYPSY_SERVER_ERROR_NO_CLIENT, "No such client: %s", device_name)); } else { if (--priv->client_count == 0) { if (priv->terminate_id == 0) { priv->terminate_id = g_timeout_add (TERMINATE_TIMEOUT, gypsy_terminate, gps); } } /* Update the hash of open connnctions */ sender = dbus_g_method_get_sender (context); list = g_hash_table_lookup (priv->connections, sender); owner = g_list_find (list, client); if (owner) { g_object_unref (owner->data); } list = g_list_remove (list, client); g_hash_table_insert (priv->connections, sender, list); dbus_g_method_return (context); } g_free (device_name); }
gboolean gsd_datetime_mechanism_get_timezone (GsdDatetimeMechanism *mechism, DBusGMethodInvocation *context) { gchar *timezone; reset_killtimer (); timezone = system_timezone_find (); dbus_g_method_return (context, timezone); return TRUE; }
/** * tp_properties_context_return * @ctx: the properties context representing a SetProperties call * @error: If %NULL, return successfully; otherwise return this error * * Commit the property changes and return from the pending D-Bus call. */ void tp_properties_context_return (TpPropertiesContext *ctx, GError *error) { GObject *obj = ctx->mixin->priv->object; TpIntSet *changed_props_val, *changed_props_flags; guint i; DEBUG ("%s", (error) ? "failure" : "success"); changed_props_val = tp_intset_sized_new (ctx->mixin_cls->num_props); changed_props_flags = tp_intset_sized_new (ctx->mixin_cls->num_props); for (i = 0; i < ctx->mixin_cls->num_props; i++) { if (ctx->values[i]) { if (!error) { tp_properties_mixin_change_value (obj, i, ctx->values[i], changed_props_val); tp_properties_mixin_change_flags (obj, i, TP_PROPERTY_FLAG_READ, 0, changed_props_flags); } g_value_unset (ctx->values[i]); ctx->values[i] = NULL; } } if (!error) { tp_properties_mixin_emit_changed (obj, changed_props_val); tp_properties_mixin_emit_flags (obj, changed_props_flags); tp_intset_destroy (changed_props_val); tp_intset_destroy (changed_props_flags); dbus_g_method_return (ctx->dbus_ctx); } else { dbus_g_method_return_error (ctx->dbus_ctx, error); g_error_free (error); } ctx->dbus_ctx = NULL; tp_intset_destroy (ctx->remaining); ctx->remaining = NULL; /* The context itself is not freed - it's a static part of the mixin */ }
gboolean Host_get_uuid(Matahari* matahari, const char *lifetime, DBusGMethodInvocation *context) { GError* error = NULL; const char *uuid = NULL; if (!check_authorization(HOST_BUS_NAME ".get_uuid", &error, context)) { dbus_g_method_return_error(context, error); g_error_free(error); return FALSE; } uuid = mh_host_get_uuid(lifetime); dbus_g_method_return(context, uuid); return TRUE; }