/* Note, this is all crack-a-rific; it isn't using DBusGProxy and thus is * a major pain */ static void send_echo_method_call (DBusConnection *connection) { DBusMessage *message; const char *hello = "Hello World!"; dbus_int32_t i32 = 123456; message = dbus_message_new_method_call (ECHO_SERVICE, ECHO_PATH, ECHO_INTERFACE, ECHO_PING_METHOD); dbus_message_append_args (message, DBUS_TYPE_STRING, &hello, DBUS_TYPE_INT32, &i32, #if PAYLOAD_SIZE > 0 DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE, &payload, PAYLOAD_SIZE, #endif DBUS_TYPE_INVALID); dbus_connection_send (connection, message, NULL); dbus_message_unref (message); dbus_connection_flush (connection); }
static int passkey_request_new(struct agent_request *req, const char *device_path) { struct agent *agent = req->agent; req->msg = dbus_message_new_method_call(agent->owner, agent->path, AGENT_INTERFACE, "RequestPasskey"); if (req->msg == NULL) { error("Couldn't allocate D-Bus message"); return -ENOMEM; } dbus_message_append_args(req->msg, DBUS_TYPE_OBJECT_PATH, &device_path, DBUS_TYPE_INVALID); if (g_dbus_send_message_with_reply(btd_get_dbus_connection(), req->msg, &req->call, REQUEST_TIMEOUT) == FALSE) { error("D-Bus send failed"); return -EIO; } dbus_pending_call_set_notify(req->call, passkey_reply, req, NULL); return 0; }
void dc_render_node_opacity_set(struct razer_daemon_controller *controller,int render_node_uid,float opacity) { DBusMessage *msg; DBusMessageIter args; char *path = str_CreateEmpty(); path = str_CatFree(path,"/"); char *suid = str_FromLong(render_node_uid); path = str_CatFree(path,suid); free(suid); double opc = (double)opacity; msg = dbus_message_new_method_call("org.voyagerproject.razer.daemon",path,"org.voyagerproject.razer.daemon.render_node.opacity","set"); if(!msg) dc_error_close(controller,"Error creating Message\n"); dbus_message_iter_init_append(msg,&args); if(!dbus_message_iter_append_basic(&args,DBUS_TYPE_DOUBLE,&opc)) dc_error_close(controller,"Out of memory!\n"); if(!dbus_connection_send_with_reply(controller->dbus,msg,&controller->pending,-1)) dc_error_close(controller,"Out of memory!\n"); if(!controller->pending) dc_error_close(controller,"No pending call\n"); dbus_connection_flush(controller->dbus); dbus_message_unref(msg); free(path);//TODO gets not freed on error }
int dc_render_node_parent_get(struct razer_daemon_controller *controller,int render_node_uid) { DBusMessage *msg; DBusMessageIter args; char *path = str_CreateEmpty(); path = str_CatFree(path,"/"); char *suid = str_FromLong(render_node_uid); path = str_CatFree(path,suid); free(suid); msg = dbus_message_new_method_call("org.voyagerproject.razer.daemon",path,"org.voyagerproject.razer.daemon.render_node.parent","get"); if(!msg) dc_error_close(controller,"Error creating Message\n"); if(!dbus_connection_send_with_reply(controller->dbus,msg,&controller->pending,-1)) dc_error_close(controller,"Out of memory!\n"); if(!controller->pending) dc_error_close(controller,"No pending call\n"); dbus_connection_flush(controller->dbus); dbus_message_unref(msg); int parent_uid = -1; dbus_pending_call_block(controller->pending); msg = dbus_pending_call_steal_reply(controller->pending); if(!msg) dc_error_close(controller,"Empty reply\n"); dbus_pending_call_unref(controller->pending); if(!dbus_message_iter_init(msg,&args)) dc_error_close(controller,"Message has no arguments!\n"); else if(dbus_message_iter_get_arg_type(&args) != DBUS_TYPE_INT32) dc_error_close(controller,"Argument is not an int!\n"); else dbus_message_iter_get_basic(&args,&parent_uid); dbus_message_unref(msg); free(path);//TODO gets not freed on error return(parent_uid); }
/** Initiate asynchronous connman service name ownership query * * @return TRUE if the method call was initiated, or FALSE in case of errors */ static gboolean xconnman_check_service(void) { gboolean res = FALSE; DBusMessage *req = 0; DBusPendingCall *pc = 0; const char *name = CONNMAN_SERVICE; if( !(req = dbus_message_new_method_call(DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS, "GetNameOwner")) ) goto EXIT; if( !dbus_message_append_args(req, DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID) ) goto EXIT; if( !dbus_connection_send_with_reply(connman_bus, req, &pc, -1) ) goto EXIT; if( !pc ) goto EXIT; if( !dbus_pending_call_set_notify(pc, xconnman_check_service_cb, 0, 0) ) goto EXIT; // success res = TRUE; EXIT: if( pc ) dbus_pending_call_unref(pc); if( req ) dbus_message_unref(req); return res; }
static int pincode_request_new(struct agent_request *req, const char *device_path, dbus_bool_t numeric) { struct agent *agent = req->agent; req->msg = dbus_message_new_method_call(agent->name, agent->path, "org.bluez.Agent", "RequestPinCode"); if (req->msg == NULL) { error("Couldn't allocate D-Bus message"); return -ENOMEM; } dbus_message_append_args(req->msg, DBUS_TYPE_OBJECT_PATH, &device_path, DBUS_TYPE_INVALID); if (dbus_connection_send_with_reply(connection, req->msg, &req->call, REQUEST_TIMEOUT) == FALSE) { error("D-Bus send failed"); return -EIO; } dbus_pending_call_set_notify(req->call, pincode_reply, req, NULL); return 0; }
static void send_spawned (DBusConnection *connection, gboolean succeeded, char *error_message) { DBusMessage *message; dbus_bool_t dbus_succeeded; if (error_message == NULL) error_message = ""; if (spawner_id == NULL || spawner_path == NULL) { if (!succeeded) { g_printerr (_("Error: %s"), error_message); g_printerr ("\n"); } return; } message = dbus_message_new_method_call (spawner_id, spawner_path, G_VFS_DBUS_SPAWNER_INTERFACE, G_VFS_DBUS_OP_SPAWNED); dbus_message_set_no_reply (message, TRUE); dbus_succeeded = succeeded; if (!dbus_message_append_args (message, DBUS_TYPE_BOOLEAN, &dbus_succeeded, DBUS_TYPE_STRING, &error_message, DBUS_TYPE_INVALID)) _g_dbus_oom (); dbus_connection_send (connection, message, NULL); /* Make sure the message is sent */ dbus_connection_flush (connection); }
static bool send_new_connection(struct ext_profile *ext, struct ext_io *conn, struct btd_device *dev) { DBusMessage *msg; const char *path; int fd; msg = dbus_message_new_method_call(ext->owner, ext->path, "org.bluez.Profile", "NewConnection"); if (!msg) { error("Unable to create NewConnection call for %s", ext->name); return false; } path = device_get_path(dev); fd = g_io_channel_unix_get_fd(conn->io); dbus_message_append_args(msg, DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_UNIX_FD, &fd, DBUS_TYPE_INVALID); if (!dbus_connection_send_with_reply(btd_get_dbus_connection(), msg, &conn->new_conn, -1)) { error("%s: sending NewConnection failed", ext->name); dbus_message_unref(msg); return false; } dbus_message_unref(msg); dbus_pending_call_set_notify(conn->new_conn, new_conn_reply, conn, NULL); return true; }
static void release_session(gpointer key, gpointer value, gpointer user_data) { struct connman_session *session = value; DBusMessage *message; DBG("owner %s path %s", session->owner, session->notify_path); if (session->notify_watch > 0) g_dbus_remove_watch(connection, session->notify_watch); g_dbus_unregister_interface(connection, session->session_path, CONNMAN_SESSION_INTERFACE); message = dbus_message_new_method_call(session->owner, session->notify_path, CONNMAN_NOTIFICATION_INTERFACE, "Release"); if (!message) return; dbus_message_set_no_reply(message, TRUE); g_dbus_send_message(connection, message); }
char* asdbus_GetConsoleSessionType (const char *session_id) { char *session_type = NULL; #ifdef HAVE_DBUS_CONTEXT if (ASDBus.system_conn && session_id) { DBusMessage *message = dbus_message_new_method_call (CK_NAME, session_id, CK_SESSION_INTERFACE, "GetSessionType"); if (message) { DBusMessage *reply; DBusError error; dbus_error_init (&error); reply = dbus_connection_send_with_reply_and_block (ASDBus.system_conn, message, -1, &error); dbus_message_unref (message); if (reply == NULL) { if (dbus_error_is_set (&error)) show_error ("Unable to determine Console Kit Session Type: %s", error.message); } else { DBusMessageIter iter; const char *val = NULL; dbus_message_iter_init (reply, &iter); dbus_message_iter_get_basic (&iter, &val); session_type = mystrdup (val); /* show_progress ("sess_type returned = \"%s\", arg_type = \"%c\"", val, dbus_message_iter_get_arg_type (&iter)); */ dbus_message_unref (reply); } if (dbus_error_is_set (&error)) dbus_error_free (&error); } } #endif return session_type; }
static void destroy_proxy_configuration(void) { DBusMessage *msg; DBusPendingCall *call; dbus_bool_t result; if (!current_config) return; DBG(""); msg = dbus_message_new_method_call(PACRUNNER_SERVICE, PACRUNNER_PATH, PACRUNNER_INTERFACE, "DestroyProxyConfiguration"); if (!msg) return; dbus_message_set_auto_start(msg, FALSE); dbus_message_append_args(msg, DBUS_TYPE_OBJECT_PATH, ¤t_config, DBUS_TYPE_INVALID); result = dbus_connection_send_with_reply(connection, msg, &call, DBUS_TIMEOUT); dbus_message_unref(msg); if (!result || !call) return; dbus_pending_call_set_notify(call, destroy_config_reply, NULL, NULL); dbus_pending_call_unref(call); g_free(current_config); current_config = NULL; }
gboolean rs_external_editor_gimp(RS_PHOTO *photo, RSFilter *prior_to_resample, guint snapshot) { #ifdef WIN32 return FALSE; #else RSOutput *output = NULL; g_assert(RS_IS_PHOTO(photo)); // We need at least GIMP 2.4.0 to export photo if (!rs_has_gimp(2,4,0)) { return FALSE; } DBusConnection *bus; DBusMessage *message, *reply; GString *filename; bus = dbus_bus_get (DBUS_BUS_SESSION, NULL); gchar* org_name = g_path_get_basename(photo->filename); gchar* org_name_noext = g_utf8_strchr(org_name, -1, '.'); /* Terminate string there */ if (NULL != org_name_noext) org_name_noext[0] = 0; filename = g_string_new(""); g_string_printf(filename, "%s/%s-rawstudio_%.0f.png",g_get_tmp_dir(), org_name, g_random_double()*10000); g_free(org_name); /* Setup our filter chain for saving */ RSFilter *ftransform_input = rs_filter_new("RSColorspaceTransform", prior_to_resample); RSFilter *fdcp = rs_filter_new("RSDcp", ftransform_input); RSFilter *fdenoise= rs_filter_new("RSDenoise", fdcp); RSFilter *ftransform_display = rs_filter_new("RSColorspaceTransform", fdenoise); RSFilter *fend = ftransform_display; GList *filters = g_list_append(NULL, fend); rs_photo_apply_to_filters(photo, filters, snapshot); g_list_free(filters); output = rs_output_new("RSPngfile"); g_object_set(output, "filename", filename->str, NULL); g_object_set(output, "save16bit", FALSE, NULL); g_object_set(output, "copy-metadata", TRUE, NULL); rs_output_execute(output, fend); g_object_unref(output); g_object_unref(ftransform_input); g_object_unref(ftransform_display); g_object_unref(fdenoise); g_object_unref(fdcp); message = dbus_message_new_method_call("org.gimp.GIMP.UI", "/org/gimp/GIMP/UI", "org.gimp.GIMP.UI", "OpenAsNew"); dbus_message_append_args (message, DBUS_TYPE_STRING, &filename->str, DBUS_TYPE_INVALID); /* Send DBus message to GIMP */ reply = dbus_connection_send_with_reply_and_block (bus, message, -1, NULL); /* If we didn't get a reply from GIMP - we try to start it and resend the message */ if (!reply) { gint retval = system("gimp &"); if (retval != 0) { g_warning("system(\"gimp &\") returned: %d\n", retval); g_unlink(filename->str); g_string_free(filename, TRUE); dbus_message_unref (message); return FALSE; } } /* Allow GIMP to start - we send the message every one second */ while (!reply) { gint i = 0; if (i > EXPORT_TO_GIMP_TIMEOUT_SECONDS) { g_warning("Never got a reply from GIMP - deleting temporary file"); g_unlink(filename->str); g_string_free(filename, TRUE); dbus_message_unref (message); return FALSE; } sleep(1); i++; reply = dbus_connection_send_with_reply_and_block (bus, message, -1, NULL); } dbus_message_unref (message); /* Depends on GIMP DBus signal: 'Opened' */ if (rs_has_gimp(2,6,2)) { /* Connect to GIMP and listen for "Opened" signal */ dbus_bus_add_match (bus, "type='signal',interface='org.gimp.GIMP.UI'", NULL); dbus_connection_add_filter(bus, dbus_gimp_opened, filename->str , NULL); g_string_free(filename, FALSE); } else { /* Old sad way - GIMP doesn't let us know that it has opened the photo */ g_warning("You have an old version of GIMP and we suggest that you upgrade to at least 2.6.2"); g_warning("Rawstudio will stop responding for 10 seconds while it waits for GIMP to open the file"); sleep(10); g_unlink(filename->str); g_string_free(filename, TRUE); } return TRUE; #endif }
/** * Initialize a libvlc instance * This function initializes a previously allocated libvlc instance: * - CPU detection * - gettext initialization * - message queue, module bank and playlist initialization * - configuration and commandline parsing */ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc, const char *ppsz_argv[] ) { libvlc_priv_t *priv = libvlc_priv (p_libvlc); char * psz_modules = NULL; char * psz_parser = NULL; char * psz_control = NULL; playlist_t *p_playlist = NULL; char *psz_val; /* System specific initialization code */ system_Init(); /* Initialize the module bank and load the configuration of the * main module. We need to do this at this stage to be able to display * a short help if required by the user. (short help == main module * options) */ module_InitBank (); /* Get command line options that affect module loading. */ if( config_LoadCmdLine( p_libvlc, i_argc, ppsz_argv, NULL ) ) { module_EndBank (false); return VLC_EGENERIC; } priv->i_verbose = var_InheritInteger( p_libvlc, "verbose" ); /* Find verbosity from VLC_VERBOSE environment variable */ { char *env = getenv( "VLC_VERBOSE" ); if( env != NULL ) priv->i_verbose = atoi( env ); } /* Announce who we are (TODO: only first instance?) */ msg_Dbg( p_libvlc, "VLC media player - %s", VERSION_MESSAGE ); msg_Dbg( p_libvlc, "%s", COPYRIGHT_MESSAGE ); msg_Dbg( p_libvlc, "revision %s", psz_vlc_changeset ); msg_Dbg( p_libvlc, "configured with %s", CONFIGURE_LINE ); /* Load the builtins and plugins into the module_bank. * We have to do it before config_Load*() because this also gets the * list of configuration options exported by each module and loads their * default values. */ size_t module_count = module_LoadPlugins (p_libvlc); /* * Override default configuration with config file settings */ if( !var_InheritBool( p_libvlc, "ignore-config" ) ) { if( var_InheritBool( p_libvlc, "reset-config" ) ) config_SaveConfigFile( p_libvlc ); /* Save default config */ else config_LoadConfigFile( p_libvlc ); } /* * Override configuration with command line settings */ int vlc_optind; if( config_LoadCmdLine( p_libvlc, i_argc, ppsz_argv, &vlc_optind ) ) { #ifdef WIN32 MessageBox (NULL, TEXT("The command line options could not be parsed.\n" "Make sure they are valid."), TEXT("VLC media player"), MB_OK|MB_ICONERROR); #endif module_EndBank (true); return VLC_EGENERIC; } priv->i_verbose = var_InheritInteger( p_libvlc, "verbose" ); /* * Support for gettext */ #if defined( ENABLE_NLS ) \ && ( defined( HAVE_GETTEXT ) || defined( HAVE_INCLUDED_GETTEXT ) ) vlc_bindtextdomain (PACKAGE_NAME); #endif /*xgettext: Translate "C" to the language code: "fr", "en_GB", "nl", "ru"... */ msg_Dbg( p_libvlc, "translation test: code is \"%s\"", _("C") ); if (config_PrintHelp (VLC_OBJECT(p_libvlc))) { module_EndBank (true); return VLC_EEXITSUCCESS; } if( module_count <= 1 ) { msg_Err( p_libvlc, "No plugins found! Check your VLC installation."); module_EndBank (true); return VLC_ENOITEM; } #ifdef HAVE_DAEMON /* Check for daemon mode */ if( var_InheritBool( p_libvlc, "daemon" ) ) { char *psz_pidfile = NULL; if( daemon( 1, 0) != 0 ) { msg_Err( p_libvlc, "Unable to fork vlc to daemon mode" ); module_EndBank (true); return VLC_EEXIT; } b_daemon = true; /* lets check if we need to write the pidfile */ psz_pidfile = var_CreateGetNonEmptyString( p_libvlc, "pidfile" ); if( psz_pidfile != NULL ) { FILE *pidfile; pid_t i_pid = getpid (); msg_Dbg( p_libvlc, "PID is %d, writing it to %s", i_pid, psz_pidfile ); pidfile = vlc_fopen( psz_pidfile,"w" ); if( pidfile != NULL ) { utf8_fprintf( pidfile, "%d", (int)i_pid ); fclose( pidfile ); } else { msg_Err( p_libvlc, "cannot open pid file for writing: %s (%m)", psz_pidfile ); } } free( psz_pidfile ); } #endif /* FIXME: could be replaced by using Unix sockets */ #ifdef HAVE_DBUS #define MPRIS_APPEND "/org/mpris/MediaPlayer2/TrackList/Append" #define MPRIS_BUS_NAME "org.mpris.MediaPlayer2.vlc" #define MPRIS_OBJECT_PATH "/org/mpris/MediaPlayer2" #define MPRIS_TRACKLIST_INTERFACE "org.mpris.MediaPlayer2.TrackList" dbus_threads_init_default(); if( var_InheritBool( p_libvlc, "one-instance" ) || ( var_InheritBool( p_libvlc, "one-instance-when-started-from-file" ) && var_InheritBool( p_libvlc, "started-from-file" ) ) ) { /* Initialise D-Bus interface, check for other instances */ DBusConnection *p_conn = NULL; DBusError dbus_error; dbus_error_init( &dbus_error ); /* connect to the session bus */ p_conn = dbus_bus_get( DBUS_BUS_SESSION, &dbus_error ); if( !p_conn ) { msg_Err( p_libvlc, "Failed to connect to D-Bus session daemon: %s", dbus_error.message ); dbus_error_free( &dbus_error ); } else { /* check if VLC is available on the bus * if not: D-Bus control is not enabled on the other * instance and we can't pass MRLs to it */ if( !dbus_bus_name_has_owner( p_conn, MPRIS_BUS_NAME, &dbus_error ) ) { if( dbus_error_is_set( &dbus_error ) ) { msg_Err( p_libvlc, "D-Bus error: %s", dbus_error.message ); dbus_error_free( &dbus_error ); } else msg_Dbg( p_libvlc, "No Media Player is running. " "Continuing normally." ); } else { int i_input; DBusMessage* p_dbus_msg = NULL; DBusMessageIter dbus_args; DBusPendingCall* p_dbus_pending = NULL; dbus_bool_t b_play; msg_Warn( p_libvlc, "Another Media Player is running. Exiting"); for( i_input = vlc_optind; i_input < i_argc;i_input++ ) { /* Skip input options, we can't pass them through D-Bus */ if( ppsz_argv[i_input][0] == ':' ) { msg_Warn( p_libvlc, "Ignoring option %s", ppsz_argv[i_input] ); continue; } /* We need to resolve relative paths in this instance */ char *psz_mrl; if( strstr( psz_mrl, "://" ) ) psz_mrl = strdup( ppsz_argv[i_input] ); else psz_mrl = vlc_path2uri( ppsz_argv[i_input], NULL ); const char *psz_after_track = MPRIS_APPEND; if( psz_mrl == NULL ) continue; msg_Dbg( p_libvlc, "Adds %s to the running Media Player", psz_mrl ); p_dbus_msg = dbus_message_new_method_call( MPRIS_BUS_NAME, MPRIS_OBJECT_PATH, MPRIS_TRACKLIST_INTERFACE, "AddTrack" ); if ( NULL == p_dbus_msg ) { msg_Err( p_libvlc, "D-Bus problem" ); free( psz_mrl ); system_End( ); exit( 1 ); } /* append MRLs */ dbus_message_iter_init_append( p_dbus_msg, &dbus_args ); if ( !dbus_message_iter_append_basic( &dbus_args, DBUS_TYPE_STRING, &psz_mrl ) ) { dbus_message_unref( p_dbus_msg ); free( psz_mrl ); system_End( ); exit( 1 ); } free( psz_mrl ); if( !dbus_message_iter_append_basic( &dbus_args, DBUS_TYPE_OBJECT_PATH, &psz_after_track ) ) { dbus_message_unref( p_dbus_msg ); system_End( ); exit( 1 ); } b_play = TRUE; if( var_InheritBool( p_libvlc, "playlist-enqueue" ) ) b_play = FALSE; if ( !dbus_message_iter_append_basic( &dbus_args, DBUS_TYPE_BOOLEAN, &b_play ) ) { dbus_message_unref( p_dbus_msg ); system_End( ); exit( 1 ); } /* send message and get a handle for a reply */ if ( !dbus_connection_send_with_reply ( p_conn, p_dbus_msg, &p_dbus_pending, -1 ) ) { msg_Err( p_libvlc, "D-Bus problem" ); dbus_message_unref( p_dbus_msg ); system_End( ); exit( 1 ); } if ( NULL == p_dbus_pending ) { msg_Err( p_libvlc, "D-Bus problem" ); dbus_message_unref( p_dbus_msg ); system_End( ); exit( 1 ); } dbus_connection_flush( p_conn ); dbus_message_unref( p_dbus_msg ); /* block until we receive a reply */ dbus_pending_call_block( p_dbus_pending ); dbus_pending_call_unref( p_dbus_pending ); } /* processes all command line MRLs */ /* bye bye */ system_End( ); exit( 0 ); } } /* we unreference the connection when we've finished with it */ if( p_conn ) dbus_connection_unref( p_conn ); } #undef MPRIS_APPEND #undef MPRIS_BUS_NAME #undef MPRIS_OBJECT_PATH #undef MPRIS_TRACKLIST_INTERFACE #endif // HAVE_DBUS /* * Message queue options */ /* Last chance to set the verbosity. Once we start interfaces and other * threads, verbosity becomes read-only. */ var_Create( p_libvlc, "verbose", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT ); if( var_InheritBool( p_libvlc, "quiet" ) ) { var_SetInteger( p_libvlc, "verbose", -1 ); priv->i_verbose = -1; } vlc_threads_setup( p_libvlc ); if( priv->b_color ) priv->b_color = var_InheritBool( p_libvlc, "color" ); vlc_CPU_dump( VLC_OBJECT(p_libvlc) ); vlc_object_set_name( p_libvlc, "main" ); priv->b_stats = var_InheritBool( p_libvlc, "stats" ); /* * Initialize hotkey handling */ priv->actions = vlc_InitActions( p_libvlc ); /* Create a variable for showing the fullscreen interface */ var_Create( p_libvlc, "intf-toggle-fscontrol", VLC_VAR_BOOL ); var_SetBool( p_libvlc, "intf-toggle-fscontrol", true ); /* Create a variable for the Boss Key */ var_Create( p_libvlc, "intf-boss", VLC_VAR_VOID ); /* Create a variable for showing the main interface */ var_Create( p_libvlc, "intf-show", VLC_VAR_BOOL ); /* Create a variable for showing the right click menu */ var_Create( p_libvlc, "intf-popupmenu", VLC_VAR_BOOL ); /* variables for signalling creation of new files */ var_Create( p_libvlc, "snapshot-file", VLC_VAR_STRING ); var_Create( p_libvlc, "record-file", VLC_VAR_STRING ); /* some default internal settings */ var_Create( p_libvlc, "window", VLC_VAR_STRING ); var_Create( p_libvlc, "user-agent", VLC_VAR_STRING ); var_SetString( p_libvlc, "user-agent", "(LibVLC "VERSION")" ); /* Initialize playlist and get commandline files */ p_playlist = playlist_Create( VLC_OBJECT(p_libvlc) ); if( !p_playlist ) { msg_Err( p_libvlc, "playlist initialization failed" ); module_EndBank (true); return VLC_EGENERIC; } /* System specific configuration */ system_Configure( p_libvlc, i_argc - vlc_optind, ppsz_argv + vlc_optind ); #if defined(MEDIA_LIBRARY) /* Get the ML */ if( var_GetBool( p_libvlc, "load-media-library-on-startup" ) ) { priv->p_ml = ml_Create( VLC_OBJECT( p_libvlc ), NULL ); if( !priv->p_ml ) { msg_Err( p_libvlc, "ML initialization failed" ); return VLC_EGENERIC; } } else { priv->p_ml = NULL; } #endif /* Add service discovery modules */ psz_modules = var_InheritString( p_libvlc, "services-discovery" ); if( psz_modules ) { char *p = psz_modules, *m; while( ( m = strsep( &p, " :," ) ) != NULL ) playlist_ServicesDiscoveryAdd( p_playlist, m ); free( psz_modules ); } #ifdef ENABLE_VLM /* Initialize VLM if vlm-conf is specified */ psz_parser = var_CreateGetNonEmptyString( p_libvlc, "vlm-conf" ); if( psz_parser ) { priv->p_vlm = vlm_New( p_libvlc ); if( !priv->p_vlm ) msg_Err( p_libvlc, "VLM initialization failed" ); } free( psz_parser ); #endif /* * Load background interfaces */ psz_modules = var_CreateGetNonEmptyString( p_libvlc, "extraintf" ); psz_control = var_CreateGetNonEmptyString( p_libvlc, "control" ); if( psz_modules && psz_control ) { char* psz_tmp; if( asprintf( &psz_tmp, "%s:%s", psz_modules, psz_control ) != -1 ) { free( psz_modules ); psz_modules = psz_tmp; } } else if( psz_control ) { free( psz_modules ); psz_modules = strdup( psz_control ); } psz_parser = psz_modules; while ( psz_parser && *psz_parser ) { char *psz_module, *psz_temp; psz_module = psz_parser; psz_parser = strchr( psz_module, ':' ); if ( psz_parser ) { *psz_parser = '\0'; psz_parser++; } if( asprintf( &psz_temp, "%s,none", psz_module ) != -1) { intf_Create( p_libvlc, psz_temp ); free( psz_temp ); } } free( psz_modules ); free( psz_control ); /* * Always load the hotkeys interface if it exists */ intf_Create( p_libvlc, "hotkeys,none" ); if( var_InheritBool( p_libvlc, "file-logging" ) #ifdef HAVE_SYSLOG_H && !var_InheritBool( p_libvlc, "syslog" ) #endif ) { intf_Create( p_libvlc, "logger,none" ); } #ifdef HAVE_SYSLOG_H if( var_InheritBool( p_libvlc, "syslog" ) ) { char *logmode = var_CreateGetNonEmptyString( p_libvlc, "logmode" ); var_SetString( p_libvlc, "logmode", "syslog" ); intf_Create( p_libvlc, "logger,none" ); if( logmode ) { var_SetString( p_libvlc, "logmode", logmode ); free( logmode ); } var_Destroy( p_libvlc, "logmode" ); } #endif if( var_InheritBool( p_libvlc, "network-synchronisation") ) { intf_Create( p_libvlc, "netsync,none" ); } #ifdef __APPLE__ var_Create( p_libvlc, "drawable-view-top", VLC_VAR_INTEGER ); var_Create( p_libvlc, "drawable-view-left", VLC_VAR_INTEGER ); var_Create( p_libvlc, "drawable-view-bottom", VLC_VAR_INTEGER ); var_Create( p_libvlc, "drawable-view-right", VLC_VAR_INTEGER ); var_Create( p_libvlc, "drawable-clip-top", VLC_VAR_INTEGER ); var_Create( p_libvlc, "drawable-clip-left", VLC_VAR_INTEGER ); var_Create( p_libvlc, "drawable-clip-bottom", VLC_VAR_INTEGER ); var_Create( p_libvlc, "drawable-clip-right", VLC_VAR_INTEGER ); var_Create( p_libvlc, "drawable-nsobject", VLC_VAR_ADDRESS ); #endif #if defined (WIN32) || defined (__OS2__) var_Create( p_libvlc, "drawable-hwnd", VLC_VAR_INTEGER ); #endif /* * Get input filenames given as commandline arguments. * We assume that the remaining parameters are filenames * and their input options. */ GetFilenames( p_libvlc, i_argc - vlc_optind, ppsz_argv + vlc_optind ); /* * Get --open argument */ psz_val = var_InheritString( p_libvlc, "open" ); if ( psz_val != NULL ) { playlist_AddExt( p_playlist, psz_val, NULL, PLAYLIST_INSERT, 0, -1, 0, NULL, 0, true, pl_Unlocked ); free( psz_val ); } return VLC_SUCCESS; }
static void start_target(const char *target, bool isolate) { DBusMessage *m = NULL, *reply = NULL; DBusError error; const char *mode, *basic_target = "basic.target"; DBusConnection *bus = NULL; assert(target); dbus_error_init(&error); if (bus_connect(DBUS_BUS_SYSTEM, &bus, NULL, &error) < 0) { log_error("Failed to get D-Bus connection: %s", bus_error_message(&error)); goto finish; } if (isolate) mode = "isolate"; else mode = "replace"; log_info("Running request %s/start/%s", target, mode); if (!(m = dbus_message_new_method_call("org.freedesktop.systemd1", "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", "StartUnitReplace"))) { log_error("Could not allocate message."); goto finish; } /* Start these units only if we can replace base.target with it */ if (!dbus_message_append_args(m, DBUS_TYPE_STRING, &basic_target, DBUS_TYPE_STRING, &target, DBUS_TYPE_STRING, &mode, DBUS_TYPE_INVALID)) { log_error("Could not attach target and flag information to message."); goto finish; } if (!(reply = dbus_connection_send_with_reply_and_block(bus, m, -1, &error))) { /* Don't print a warning if we aren't called during * startup */ if (!dbus_error_has_name(&error, BUS_ERROR_NO_SUCH_JOB)) log_error("Failed to start unit: %s", bus_error_message(&error)); goto finish; } finish: if (m) dbus_message_unref(m); if (reply) dbus_message_unref(reply); if (bus) { dbus_connection_flush(bus); dbus_connection_close(bus); dbus_connection_unref(bus); } dbus_error_free(&error); }
void register_machine(pid_t pid, const char *dest) { int rc; DBusError err; DBusConnection *conn; DBusMessageIter args; DBusMessage *req, *rep; DBusMessageIter uuid_iter, scope_iter; _free_ char *name = NULL; char *app = "pflask"; unsigned char uuid[16]; char *type = "container"; dbus_error_init(&err); rc = asprintf(&name, "pflask-%d", pid); if (rc < 0) fail_printf("OOM"); conn = dbus_bus_get_private(DBUS_BUS_SYSTEM, &err); if (dbus_error_is_set(&err)) return; req = dbus_message_new_method_call( "org.freedesktop.machine1", "/org/freedesktop/machine1", "org.freedesktop.machine1.Manager", "CreateMachine" ); dbus_message_iter_init_append(req, &args); /* name */ if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &name)) fail_printf("OOM"); /* id */ if (!dbus_message_iter_open_container(&args, DBUS_TYPE_ARRAY, "y", &uuid_iter)) fail_printf("OOM"); if (!dbus_message_iter_append_fixed_array(&uuid_iter, DBUS_TYPE_BYTE, uuid, 0)) fail_printf("OOM"); if (!dbus_message_iter_close_container(&args, &uuid_iter)) fail_printf("OOM"); /* service */ if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &app)) fail_printf("OOM"); /* type */ if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &type)) fail_printf("OOM"); /* leader */ if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_UINT32, &pid)) fail_printf("OOM"); /* root */ if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &dest)) fail_printf("OOM"); /* scope properties */ if (!dbus_message_iter_open_container(&args, DBUS_TYPE_ARRAY, "(sv)", &scope_iter)) fail_printf("OOM"); if (!dbus_message_iter_close_container(&args, &scope_iter)) fail_printf("OOM"); rep = dbus_connection_send_with_reply_and_block(conn, req, -1, &err); if (dbus_error_is_set(&err)) goto done; dbus_message_unref(rep); done: dbus_message_unref(req); dbus_connection_close(conn); dbus_error_free(&err); }
static void* send_msg1(void* data) { DBusConnection* connection; DBusError error; static int cnt = 1; dbus_int32_t no = 5; DBusPendingCall* pending; DBusMessage* msg1; DBusMessage* msg; int data_slot = *(int*)data; FILE* fp; threadData1* thrData; dbus_error_init(&error); connection = dbus_bus_get(DBUS_BUS_SESSION, &error); thrData = (threadData1*)dbus_connection_get_data(connection, data_slot); if(!thrData) return NULL; pthread_mutex_lock(&thrData->mutex); msg = dbus_message_new_method_call("Test.Method.Call", "/Test/Method/Object", "test.Method.Call", "simple"); dbus_message_append_args(msg, DBUS_TYPE_INT32, &no, DBUS_TYPE_INVALID); pthread_cond_wait(&thrData->cond, &thrData->mutex); // send message and get a handle for a reply if (!dbus_connection_send_with_reply (connection, msg, &pending, -1)) { // -1 is default timeout thrData->ret = 2; // exit(1); } if (NULL == pending) { thrData->ret = 2; // exit(1); } dbus_connection_flush(connection); // free message dbus_message_unref(msg); // block until we recieve a reply dbus_pending_call_block(pending); // get the reply message msg1 = dbus_pending_call_steal_reply(pending); if (NULL == msg1) { thrData->ret = 2; } // free the pending message handle dbus_pending_call_unref(pending); dbus_message_get_args(msg1, &error, DBUS_TYPE_INT32, &no, DBUS_TYPE_INVALID); fp = fopen("C:\\new.txt", "a+"); fprintf(fp, "%d\n", no); fclose(fp); if(no == 9090) { thrData->ret++; } // free reply and close connection dbus_message_unref(msg1); dbus_connection_unref(connection); pthread_mutex_unlock(&thrData->mutex); return NULL; }
static gboolean ck_tracker_init_get_seats_and_sessions (CKTracker *tracker) { gboolean ret; DBusError error; DBusMessage *message; DBusMessage *reply; DBusMessageIter iter; DBusMessageIter iter_array; ret = FALSE; /* first build array of existing seats and sessions */ message = dbus_message_new_method_call ("org.freedesktop.ConsoleKit", "/org/freedesktop/ConsoleKit/Manager", "org.freedesktop.ConsoleKit.Manager", "GetSeats"); dbus_error_init (&error); reply = dbus_connection_send_with_reply_and_block (tracker->dbus_connection, message, -1, &error); if (reply == NULL || dbus_error_is_set (&error)) { HAL_ERROR (("Error doing GetSeats on ConsoleKit: %s: %s", error.name, error.message)); dbus_message_unref (message); if (reply != NULL) dbus_message_unref (reply); goto error; } dbus_message_iter_init (reply, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_ARRAY) { HAL_WARNING (("Expecting an array from GetSeats on ConsoleKit.")); dbus_message_unref (message); dbus_message_unref (reply); goto error; } dbus_message_iter_recurse (&iter, &iter_array); while (dbus_message_iter_get_arg_type (&iter_array) == DBUS_TYPE_OBJECT_PATH) { const char *seat_objpath; CKSeat *seat; dbus_message_iter_get_basic (&iter_array, &seat_objpath); HAL_INFO (("got seat '%s'", seat_objpath)); seat = ck_seat_new (seat_objpath); /* get information */ if (!ck_seat_get_info (tracker, seat)) { HAL_ERROR (("Could not get information for seat '%s'", seat_objpath)); dbus_message_unref (message); dbus_message_unref (reply); goto error; } /* for each seat, get the sessions */ if (!ck_tracker_init_get_sessions_for_seat (tracker, seat)) { HAL_ERROR (("Could not get sessions for seat '%s'", seat_objpath)); dbus_message_unref (message); dbus_message_unref (reply); goto error; } tracker->seats = g_slist_prepend (tracker->seats, seat); dbus_message_iter_next (&iter_array); } dbus_message_unref (message); dbus_message_unref (reply); HAL_INFO (("Got seats")); ret = TRUE; error: if (dbus_error_is_set (&error)) dbus_error_free (&error); return ret; }
static gboolean ck_session_get_info (CKTracker *tracker, CKSession *session) { gboolean ret; DBusError error; DBusMessage *message; DBusMessage *reply; char *hostname; ret = FALSE; message = dbus_message_new_method_call ("org.freedesktop.ConsoleKit", session->session_objpath, "org.freedesktop.ConsoleKit.Session", "IsActive"); dbus_error_init (&error); reply = dbus_connection_send_with_reply_and_block (tracker->dbus_connection, message, -1, &error); if (reply == NULL || dbus_error_is_set (&error)) { HAL_ERROR (("Error doing Session.IsActive on ConsoleKit: %s: %s", error.name, error.message)); dbus_message_unref (message); if (reply != NULL) dbus_message_unref (reply); goto error; } if (!dbus_message_get_args (reply, NULL, DBUS_TYPE_BOOLEAN, &(session->is_active), DBUS_TYPE_INVALID)) { HAL_ERROR (("Invalid IsActive reply from CK")); goto error; } dbus_message_unref (message); dbus_message_unref (reply); message = dbus_message_new_method_call ("org.freedesktop.ConsoleKit", session->session_objpath, "org.freedesktop.ConsoleKit.Session", "IsLocal"); dbus_error_init (&error); reply = dbus_connection_send_with_reply_and_block (tracker->dbus_connection, message, -1, &error); if (reply == NULL || dbus_error_is_set (&error)) { HAL_ERROR (("Error doing Session.IsLocal on ConsoleKit: %s: %s", error.name, error.message)); dbus_message_unref (message); if (reply != NULL) dbus_message_unref (reply); goto error; } if (!dbus_message_get_args (reply, NULL, DBUS_TYPE_BOOLEAN, &(session->is_local), DBUS_TYPE_INVALID)) { HAL_ERROR (("Invalid IsLocal reply from CK")); goto error; } dbus_message_unref (message); dbus_message_unref (reply); message = dbus_message_new_method_call ("org.freedesktop.ConsoleKit", session->session_objpath, "org.freedesktop.ConsoleKit.Session", "GetRemoteHostName"); dbus_error_init (&error); reply = dbus_connection_send_with_reply_and_block (tracker->dbus_connection, message, -1, &error); if (reply == NULL || dbus_error_is_set (&error)) { HAL_ERROR (("Error doing Session.GetRemoteHostName on ConsoleKit: %s: %s", error.name, error.message)); dbus_message_unref (message); if (reply != NULL) dbus_message_unref (reply); goto error; } if (!dbus_message_get_args (reply, NULL, DBUS_TYPE_STRING, &hostname, DBUS_TYPE_INVALID)) { HAL_ERROR (("Invalid GetRemoteHostName reply from CK")); goto error; } session->hostname = g_strdup (hostname); dbus_message_unref (message); dbus_message_unref (reply); message = dbus_message_new_method_call ("org.freedesktop.ConsoleKit", session->session_objpath, "org.freedesktop.ConsoleKit.Session", "GetUnixUser"); dbus_error_init (&error); reply = dbus_connection_send_with_reply_and_block (tracker->dbus_connection, message, -1, &error); if (reply == NULL || dbus_error_is_set (&error)) { HAL_ERROR (("Error doing Session.GetUnixUser on ConsoleKit: %s: %s", error.name, error.message)); dbus_message_unref (message); if (reply != NULL) dbus_message_unref (reply); goto error; } if (!dbus_message_get_args (reply, NULL, #ifdef HAVE_CK_0_3 DBUS_TYPE_UINT32, &(session->user), #else DBUS_TYPE_INT32, &(session->user), #endif DBUS_TYPE_INVALID)) { HAL_ERROR (("Invalid GetUnixUser reply from CK")); goto error; } dbus_message_unref (message); dbus_message_unref (reply); HAL_INFO (("Got active state (%s) and uid %d on session '%s'", session->is_active ? "ACTIVE" : "INACTIVE", session->user, session->session_objpath)); ret = TRUE; error: if (dbus_error_is_set (&error)) dbus_error_free (&error); return ret; }
/** * @ingroup DBusMessageInternals * Unit test for DBusMessage. * * @returns #TRUE on success. */ dbus_bool_t _dbus_message_test (const char *test_data_dir) { DBusMessage *message, *message_without_unix_fds; DBusMessageLoader *loader; int i; const char *data; DBusMessage *copy; const char *name1; const char *name2; const dbus_uint32_t our_uint32_array[] = { 0x12345678, 0x23456781, 0x34567812, 0x45678123 }; const dbus_int32_t our_int32_array[] = { 0x12345678, -0x23456781, 0x34567812, -0x45678123 }; const dbus_uint32_t *v_ARRAY_UINT32 = our_uint32_array; const dbus_int32_t *v_ARRAY_INT32 = our_int32_array; #ifdef DBUS_HAVE_INT64 const dbus_uint64_t our_uint64_array[] = { 0x12345678, 0x23456781, 0x34567812, 0x45678123 }; const dbus_int64_t our_int64_array[] = { 0x12345678, -0x23456781, 0x34567812, -0x45678123 }; const dbus_uint64_t *v_ARRAY_UINT64 = our_uint64_array; const dbus_int64_t *v_ARRAY_INT64 = our_int64_array; #endif const char *our_string_array[] = { "Foo", "bar", "", "woo woo woo woo" }; const char **v_ARRAY_STRING = our_string_array; const double our_double_array[] = { 0.1234, 9876.54321, -300.0 }; const double *v_ARRAY_DOUBLE = our_double_array; const unsigned char our_byte_array[] = { 'a', 'b', 'c', 234 }; const unsigned char *v_ARRAY_BYTE = our_byte_array; const dbus_bool_t our_boolean_array[] = { TRUE, FALSE, TRUE, TRUE, FALSE }; const dbus_bool_t *v_ARRAY_BOOLEAN = our_boolean_array; char sig[64]; const char *s; const char *v_STRING; double v_DOUBLE; dbus_int16_t v_INT16; dbus_uint16_t v_UINT16; dbus_int32_t v_INT32; dbus_uint32_t v_UINT32; #ifdef DBUS_HAVE_INT64 dbus_int64_t v_INT64; dbus_uint64_t v_UINT64; #endif unsigned char v_BYTE; unsigned char v2_BYTE; dbus_bool_t v_BOOLEAN; DBusMessageIter iter, array_iter, struct_iter; #ifdef HAVE_UNIX_FD_PASSING int v_UNIX_FD; #endif char **decomposed; message = dbus_message_new_method_call ("org.freedesktop.DBus.TestService", "/org/freedesktop/TestPath", "Foo.TestInterface", "TestMethod"); _dbus_assert (dbus_message_has_destination (message, "org.freedesktop.DBus.TestService")); _dbus_assert (dbus_message_is_method_call (message, "Foo.TestInterface", "TestMethod")); _dbus_assert (strcmp (dbus_message_get_path (message), "/org/freedesktop/TestPath") == 0); dbus_message_set_serial (message, 1234); /* string length including nul byte not a multiple of 4 */ if (!dbus_message_set_sender (message, "org.foo.bar1")) _dbus_assert_not_reached ("out of memory"); _dbus_assert (dbus_message_has_sender (message, "org.foo.bar1")); dbus_message_set_reply_serial (message, 5678); _dbus_verbose_bytes_of_string (&message->header.data, 0, _dbus_string_get_length (&message->header.data)); _dbus_verbose_bytes_of_string (&message->body, 0, _dbus_string_get_length (&message->body)); if (!dbus_message_set_sender (message, NULL)) _dbus_assert_not_reached ("out of memory"); _dbus_verbose_bytes_of_string (&message->header.data, 0, _dbus_string_get_length (&message->header.data)); _dbus_verbose_bytes_of_string (&message->body, 0, _dbus_string_get_length (&message->body)); _dbus_assert (!dbus_message_has_sender (message, "org.foo.bar1")); _dbus_assert (dbus_message_get_serial (message) == 1234); _dbus_assert (dbus_message_get_reply_serial (message) == 5678); _dbus_assert (dbus_message_has_destination (message, "org.freedesktop.DBus.TestService")); _dbus_assert (dbus_message_get_no_reply (message) == FALSE); dbus_message_set_no_reply (message, TRUE); _dbus_assert (dbus_message_get_no_reply (message) == TRUE); dbus_message_set_no_reply (message, FALSE); _dbus_assert (dbus_message_get_no_reply (message) == FALSE); /* Set/get some header fields */ if (!dbus_message_set_path (message, "/foo")) _dbus_assert_not_reached ("out of memory"); _dbus_assert (strcmp (dbus_message_get_path (message), "/foo") == 0); if (!dbus_message_set_interface (message, "org.Foo")) _dbus_assert_not_reached ("out of memory"); _dbus_assert (strcmp (dbus_message_get_interface (message), "org.Foo") == 0); if (!dbus_message_set_member (message, "Bar")) _dbus_assert_not_reached ("out of memory"); _dbus_assert (strcmp (dbus_message_get_member (message), "Bar") == 0); /* Set/get them with longer values */ if (!dbus_message_set_path (message, "/foo/bar")) _dbus_assert_not_reached ("out of memory"); _dbus_assert (strcmp (dbus_message_get_path (message), "/foo/bar") == 0); if (!dbus_message_set_interface (message, "org.Foo.Bar")) _dbus_assert_not_reached ("out of memory"); _dbus_assert (strcmp (dbus_message_get_interface (message), "org.Foo.Bar") == 0); if (!dbus_message_set_member (message, "BarFoo")) _dbus_assert_not_reached ("out of memory"); _dbus_assert (strcmp (dbus_message_get_member (message), "BarFoo") == 0); /* Realloc shorter again */ if (!dbus_message_set_path (message, "/foo")) _dbus_assert_not_reached ("out of memory"); _dbus_assert (strcmp (dbus_message_get_path (message), "/foo") == 0); if (!dbus_message_set_interface (message, "org.Foo")) _dbus_assert_not_reached ("out of memory"); _dbus_assert (strcmp (dbus_message_get_interface (message), "org.Foo") == 0); if (!dbus_message_set_member (message, "Bar")) _dbus_assert_not_reached ("out of memory"); _dbus_assert (strcmp (dbus_message_get_member (message), "Bar") == 0); /* Path decomposing */ dbus_message_set_path (message, NULL); dbus_message_get_path_decomposed (message, &decomposed); _dbus_assert (decomposed == NULL); dbus_free_string_array (decomposed); dbus_message_set_path (message, "/"); dbus_message_get_path_decomposed (message, &decomposed); _dbus_assert (decomposed != NULL); _dbus_assert (decomposed[0] == NULL); dbus_free_string_array (decomposed); dbus_message_set_path (message, "/a/b"); dbus_message_get_path_decomposed (message, &decomposed); _dbus_assert (decomposed != NULL); _dbus_assert (strcmp (decomposed[0], "a") == 0); _dbus_assert (strcmp (decomposed[1], "b") == 0); _dbus_assert (decomposed[2] == NULL); dbus_free_string_array (decomposed); dbus_message_set_path (message, "/spam/eggs"); dbus_message_get_path_decomposed (message, &decomposed); _dbus_assert (decomposed != NULL); _dbus_assert (strcmp (decomposed[0], "spam") == 0); _dbus_assert (strcmp (decomposed[1], "eggs") == 0); _dbus_assert (decomposed[2] == NULL); dbus_free_string_array (decomposed); dbus_message_unref (message); /* Test the vararg functions */ message = dbus_message_new_method_call ("org.freedesktop.DBus.TestService", "/org/freedesktop/TestPath", "Foo.TestInterface", "TestMethod"); dbus_message_set_serial (message, 1); dbus_message_set_reply_serial (message, 5678); v_INT16 = -0x123; v_UINT16 = 0x123; v_INT32 = -0x12345678; v_UINT32 = 0x12300042; #ifdef DBUS_HAVE_INT64 v_INT64 = DBUS_INT64_CONSTANT (-0x123456789abcd); v_UINT64 = DBUS_UINT64_CONSTANT (0x123456789abcd); #endif v_STRING = "Test string"; v_DOUBLE = 3.14159; v_BOOLEAN = TRUE; v_BYTE = 42; v2_BYTE = 24; #ifdef HAVE_UNIX_FD_PASSING v_UNIX_FD = 1; #endif dbus_message_append_args (message, DBUS_TYPE_INT16, &v_INT16, DBUS_TYPE_UINT16, &v_UINT16, DBUS_TYPE_INT32, &v_INT32, DBUS_TYPE_UINT32, &v_UINT32, #ifdef DBUS_HAVE_INT64 DBUS_TYPE_INT64, &v_INT64, DBUS_TYPE_UINT64, &v_UINT64, #endif DBUS_TYPE_STRING, &v_STRING, DBUS_TYPE_DOUBLE, &v_DOUBLE, DBUS_TYPE_BOOLEAN, &v_BOOLEAN, DBUS_TYPE_BYTE, &v_BYTE, DBUS_TYPE_BYTE, &v2_BYTE, DBUS_TYPE_ARRAY, DBUS_TYPE_UINT32, &v_ARRAY_UINT32, _DBUS_N_ELEMENTS (our_uint32_array), DBUS_TYPE_ARRAY, DBUS_TYPE_INT32, &v_ARRAY_INT32, _DBUS_N_ELEMENTS (our_int32_array), #ifdef DBUS_HAVE_INT64 DBUS_TYPE_ARRAY, DBUS_TYPE_UINT64, &v_ARRAY_UINT64, _DBUS_N_ELEMENTS (our_uint64_array), DBUS_TYPE_ARRAY, DBUS_TYPE_INT64, &v_ARRAY_INT64, _DBUS_N_ELEMENTS (our_int64_array), #endif DBUS_TYPE_ARRAY, DBUS_TYPE_DOUBLE, &v_ARRAY_DOUBLE, _DBUS_N_ELEMENTS (our_double_array), DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE, &v_ARRAY_BYTE, _DBUS_N_ELEMENTS (our_byte_array), DBUS_TYPE_ARRAY, DBUS_TYPE_BOOLEAN, &v_ARRAY_BOOLEAN, _DBUS_N_ELEMENTS (our_boolean_array), DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &v_ARRAY_STRING, _DBUS_N_ELEMENTS (our_string_array), DBUS_TYPE_INVALID); i = 0; sig[i++] = DBUS_TYPE_INT16; sig[i++] = DBUS_TYPE_UINT16; sig[i++] = DBUS_TYPE_INT32; sig[i++] = DBUS_TYPE_UINT32; #ifdef DBUS_HAVE_INT64 sig[i++] = DBUS_TYPE_INT64; sig[i++] = DBUS_TYPE_UINT64; #endif sig[i++] = DBUS_TYPE_STRING; sig[i++] = DBUS_TYPE_DOUBLE; sig[i++] = DBUS_TYPE_BOOLEAN; sig[i++] = DBUS_TYPE_BYTE; sig[i++] = DBUS_TYPE_BYTE; sig[i++] = DBUS_TYPE_ARRAY; sig[i++] = DBUS_TYPE_UINT32; sig[i++] = DBUS_TYPE_ARRAY; sig[i++] = DBUS_TYPE_INT32; #ifdef DBUS_HAVE_INT64 sig[i++] = DBUS_TYPE_ARRAY; sig[i++] = DBUS_TYPE_UINT64; sig[i++] = DBUS_TYPE_ARRAY; sig[i++] = DBUS_TYPE_INT64; #endif sig[i++] = DBUS_TYPE_ARRAY; sig[i++] = DBUS_TYPE_DOUBLE; sig[i++] = DBUS_TYPE_ARRAY; sig[i++] = DBUS_TYPE_BYTE; sig[i++] = DBUS_TYPE_ARRAY; sig[i++] = DBUS_TYPE_BOOLEAN; sig[i++] = DBUS_TYPE_ARRAY; sig[i++] = DBUS_TYPE_STRING; message_without_unix_fds = dbus_message_copy(message); _dbus_assert(message_without_unix_fds); #ifdef HAVE_UNIX_FD_PASSING dbus_message_append_args (message, DBUS_TYPE_UNIX_FD, &v_UNIX_FD, DBUS_TYPE_INVALID); sig[i++] = DBUS_TYPE_UNIX_FD; #endif sig[i++] = DBUS_TYPE_INVALID; _dbus_assert (i < (int) _DBUS_N_ELEMENTS (sig)); _dbus_verbose ("HEADER\n"); _dbus_verbose_bytes_of_string (&message->header.data, 0, _dbus_string_get_length (&message->header.data)); _dbus_verbose ("BODY\n"); _dbus_verbose_bytes_of_string (&message->body, 0, _dbus_string_get_length (&message->body)); _dbus_verbose ("Signature expected \"%s\" actual \"%s\"\n", sig, dbus_message_get_signature (message)); s = dbus_message_get_signature (message); _dbus_assert (dbus_message_has_signature (message, sig)); _dbus_assert (strcmp (s, sig) == 0); verify_test_message (message); copy = dbus_message_copy (message); _dbus_assert (dbus_message_get_reply_serial (message) == dbus_message_get_reply_serial (copy)); _dbus_assert (message->header.padding == copy->header.padding); _dbus_assert (_dbus_string_get_length (&message->header.data) == _dbus_string_get_length (©->header.data)); _dbus_assert (_dbus_string_get_length (&message->body) == _dbus_string_get_length (©->body)); verify_test_message (copy); name1 = dbus_message_get_interface (message); name2 = dbus_message_get_interface (copy); _dbus_assert (strcmp (name1, name2) == 0); name1 = dbus_message_get_member (message); name2 = dbus_message_get_member (copy); _dbus_assert (strcmp (name1, name2) == 0); dbus_message_unref (copy); /* Message loader test */ dbus_message_lock (message); loader = _dbus_message_loader_new (); /* check ref/unref */ _dbus_message_loader_ref (loader); _dbus_message_loader_unref (loader); /* Write the header data one byte at a time */ data = _dbus_string_get_const_data (&message->header.data); for (i = 0; i < _dbus_string_get_length (&message->header.data); i++) { DBusString *buffer; _dbus_message_loader_get_buffer (loader, &buffer); _dbus_string_append_byte (buffer, data[i]); _dbus_message_loader_return_buffer (loader, buffer, 1); } /* Write the body data one byte at a time */ data = _dbus_string_get_const_data (&message->body); for (i = 0; i < _dbus_string_get_length (&message->body); i++) { DBusString *buffer; _dbus_message_loader_get_buffer (loader, &buffer); _dbus_string_append_byte (buffer, data[i]); _dbus_message_loader_return_buffer (loader, buffer, 1); } #ifdef HAVE_UNIX_FD_PASSING { int *unix_fds; unsigned n_unix_fds; /* Write unix fd */ _dbus_message_loader_get_unix_fds(loader, &unix_fds, &n_unix_fds); _dbus_assert(n_unix_fds > 0); _dbus_assert(message->n_unix_fds == 1); unix_fds[0] = _dbus_dup(message->unix_fds[0], NULL); _dbus_assert(unix_fds[0] >= 0); _dbus_message_loader_return_unix_fds(loader, unix_fds, 1); } #endif dbus_message_unref (message); /* Now pop back the message */ if (!_dbus_message_loader_queue_messages (loader)) _dbus_assert_not_reached ("no memory to queue messages"); if (_dbus_message_loader_get_is_corrupted (loader)) _dbus_assert_not_reached ("message loader corrupted"); message = _dbus_message_loader_pop_message (loader); if (!message) _dbus_assert_not_reached ("received a NULL message"); if (dbus_message_get_reply_serial (message) != 5678) _dbus_assert_not_reached ("reply serial fields differ"); dbus_message_unref (message); /* ovveride the serial, since it was reset by dbus_message_copy() */ dbus_message_set_serial(message_without_unix_fds, 8901); dbus_message_lock (message_without_unix_fds); verify_test_message (message_without_unix_fds); { /* Marshal and demarshal the message. */ DBusMessage *message2; DBusError error = DBUS_ERROR_INIT; char *marshalled = NULL; int len = 0; char garbage_header[DBUS_MINIMUM_HEADER_SIZE] = "xxx"; if (!dbus_message_marshal (message_without_unix_fds, &marshalled, &len)) _dbus_assert_not_reached ("failed to marshal message"); _dbus_assert (len != 0); _dbus_assert (marshalled != NULL); _dbus_assert (dbus_message_demarshal_bytes_needed (marshalled, len) == len); message2 = dbus_message_demarshal (marshalled, len, &error); _dbus_assert (message2 != NULL); _dbus_assert (!dbus_error_is_set (&error)); verify_test_message (message2); dbus_message_unref (message2); dbus_free (marshalled); /* Demarshal invalid message. */ message2 = dbus_message_demarshal ("invalid", 7, &error); _dbus_assert (message2 == NULL); _dbus_assert (dbus_error_is_set (&error)); dbus_error_free (&error); /* Demarshal invalid (empty) message. */ message2 = dbus_message_demarshal ("", 0, &error); _dbus_assert (message2 == NULL); _dbus_assert (dbus_error_is_set (&error)); dbus_error_free (&error); /* Bytes needed to demarshal empty message: 0 (more) */ _dbus_assert (dbus_message_demarshal_bytes_needed ("", 0) == 0); /* Bytes needed to demarshal invalid message: -1 (error). */ _dbus_assert (dbus_message_demarshal_bytes_needed (garbage_header, DBUS_MINIMUM_HEADER_SIZE) == -1); } dbus_message_unref (message_without_unix_fds); _dbus_message_loader_unref (loader); check_memleaks (); _dbus_check_fdleaks(); /* Check that we can abandon a container */ message = dbus_message_new_method_call ("org.freedesktop.DBus.TestService", "/org/freedesktop/TestPath", "Foo.TestInterface", "Method"); dbus_message_iter_init_append (message, &iter); _dbus_assert (dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, (DBUS_STRUCT_BEGIN_CHAR_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_STRING_AS_STRING DBUS_STRUCT_END_CHAR_AS_STRING), &array_iter)); _dbus_assert (dbus_message_iter_open_container (&array_iter, DBUS_TYPE_STRUCT, NULL, &struct_iter)); s = "peaches"; _dbus_assert (dbus_message_iter_append_basic (&struct_iter, DBUS_TYPE_STRING, &s)); /* uh-oh, error, try and unwind */ dbus_message_iter_abandon_container (&array_iter, &struct_iter); dbus_message_iter_abandon_container (&array_iter, &iter); dbus_message_unref (message); /* Load all the sample messages from the message factory */ { DBusMessageDataIter diter; DBusMessageData mdata; int count; reset_validities_seen (); count = 0; _dbus_message_data_iter_init (&diter); while (_dbus_message_data_iter_get_and_next (&diter, &mdata)) { if (!dbus_internal_do_not_use_try_message_data (&mdata.data, mdata.expected_validity)) { _dbus_warn ("expected validity %d and did not get it\n", mdata.expected_validity); _dbus_assert_not_reached ("message data failed"); } _dbus_message_data_free (&mdata); count += 1; } printf ("%d sample messages tested\n", count); print_validities_seen (FALSE); print_validities_seen (TRUE); } check_memleaks (); _dbus_check_fdleaks(); /* Now load every message in test_data_dir if we have one */ if (test_data_dir == NULL) return TRUE; return dbus_internal_do_not_use_foreach_message_file (test_data_dir, (DBusForeachMessageFileFunc) dbus_internal_do_not_use_try_message_file, NULL); }
static char *device_get_ieee1284_id(const char *adapter, const char *device) { DBusMessage *message, *reply; DBusMessageIter iter, reply_iter; DBusMessageIter reply_iter_entry; const char *hcr_print = "00001126-0000-1000-8000-00805f9b34fb"; const char *xml; char *id = NULL; /* Look for the service handle of the HCRP service */ message = dbus_message_new_method_call("org.bluez", device, "org.bluez.Device", "DiscoverServices"); dbus_message_iter_init_append(message, &iter); dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &hcr_print); reply = dbus_connection_send_with_reply_and_block(conn, message, -1, NULL); dbus_message_unref(message); if (!reply) return NULL; dbus_message_iter_init(reply, &reply_iter); if (dbus_message_iter_get_arg_type(&reply_iter) != DBUS_TYPE_ARRAY) { dbus_message_unref(reply); return NULL; } dbus_message_iter_recurse(&reply_iter, &reply_iter_entry); /* Hopefully we only get one handle, or take a punt */ while (dbus_message_iter_get_arg_type(&reply_iter_entry) == DBUS_TYPE_DICT_ENTRY) { guint32 key; DBusMessageIter dict_entry; dbus_message_iter_recurse(&reply_iter_entry, &dict_entry); /* Key ? */ dbus_message_iter_get_basic(&dict_entry, &key); if (!key) { dbus_message_iter_next(&reply_iter_entry); continue; } /* Try to get the value */ if (!dbus_message_iter_next(&dict_entry)) { dbus_message_iter_next(&reply_iter_entry); continue; } dbus_message_iter_get_basic(&dict_entry, &xml); id = sdp_xml_parse_record(xml); if (id != NULL) break; dbus_message_iter_next(&reply_iter_entry); } dbus_message_unref(reply); return id; }
struct Hmd_Board_Info_show* show_hmd_info_show(DBusConnection *dcli_dbus_connection, int *board_num, int *ret) { DBusMessage *query, *reply; DBusError err; DBusMessageIter iter; DBusMessageIter iter_array; int i =0; int j =0; int k =0; struct Hmd_Board_Info_show* hmd_board_head = NULL; struct Hmd_Board_Info_show* hmd_board_node = NULL; query = dbus_message_new_method_call(HMD_DBUS_BUSNAME,HMD_DBUS_OBJPATH,HMD_DBUS_INTERFACE,HMD_DBUS_METHOD_SHOW_HMD_INFO); dbus_error_init(&err); reply = dbus_connection_send_with_reply_and_block (dcli_dbus_connection,query,-1, &err); dbus_message_unref(query); if (NULL == reply) { if (dbus_error_is_set(&err)) { dbus_error_free(&err); } return NULL; } dbus_message_iter_init(reply,&iter); dbus_message_iter_get_basic(&iter,ret); dbus_message_iter_next(&iter); dbus_message_iter_get_basic(&iter,board_num); //printf(" board_num = %d \n",*board_num); if((*ret ==0)&&(*board_num != 0)) { if((hmd_board_head = (struct Hmd_Board_Info_show*)malloc(sizeof(struct Hmd_Board_Info_show))) == NULL) { *ret = MALLOC_ERROR; dbus_message_unref(reply); return NULL; } memset(hmd_board_head,0,sizeof(struct Hmd_Board_Info_show)); hmd_board_head->next; hmd_board_head->hmd_board_list = NULL; hmd_board_head->hmd_board_last = NULL; dbus_message_iter_next(&iter); dbus_message_iter_recurse(&iter,&iter_array); for(i = 0; i < *board_num ; i++) { //DBusMessageIter iter_board_array; DBusMessageIter iter_board_struct; DBusMessageIter iter_inst_array; DBusMessageIter iter_inst_struct; DBusMessageIter iter_inst_uplink_array; DBusMessageIter iter_inst_uplink_struct; DBusMessageIter iter_inst_downlink_array; DBusMessageIter iter_inst_downlink_struct; DBusMessageIter iter_inst_gateway_array; DBusMessageIter iter_inst_gateway_struct; DBusMessageIter iter_l_inst_array; DBusMessageIter iter_l_inst_struct; DBusMessageIter iter_l_inst_uplink_array; DBusMessageIter iter_l_inst_uplink_struct; DBusMessageIter iter_l_inst_downlink_array; DBusMessageIter iter_l_inst_downlink_struct; DBusMessageIter iter_l_inst_gateway_array; DBusMessageIter iter_l_inst_gateway_struct; if((hmd_board_node = (struct Hmd_Board_Info_show*)malloc(sizeof(struct Hmd_Board_Info_show))) == NULL) { dcli_free_HmdBoardInfo(hmd_board_head); *ret = MALLOC_ERROR; dbus_message_unref(reply); return NULL; } memset(hmd_board_node,0,sizeof(struct Hmd_Board_Info_show)); hmd_board_node->next; hmd_board_node->hmd_board_list = NULL; hmd_board_node->hmd_board_last = NULL; if(hmd_board_head->hmd_board_list == NULL) { hmd_board_head->hmd_board_list = hmd_board_node; hmd_board_head->next = hmd_board_node; } else { hmd_board_head->hmd_board_last->next = hmd_board_node; } hmd_board_head->hmd_board_last = hmd_board_node; dbus_message_iter_recurse(&iter_array,&iter_board_struct); dbus_message_iter_get_basic(&iter_board_struct,&(hmd_board_node->slot_no)); dbus_message_iter_next(&iter_board_struct); dbus_message_iter_get_basic(&iter_board_struct,&(hmd_board_node->InstNum)); //printf(" hmd_board_node->InstNum = %d \n",hmd_board_node->InstNum); dbus_message_iter_next(&iter_board_struct); dbus_message_iter_get_basic(&iter_board_struct,&(hmd_board_node->LocalInstNum)); //printf(" hmd_board_node->LocalInstNum = %d \n",hmd_board_node->LocalInstNum); dbus_message_iter_next(&iter_board_struct); dbus_message_iter_recurse(&iter_board_struct,&iter_inst_array); /*Hmd_Inst begin*/ for(j = 0; j < hmd_board_node->InstNum; j++) { hmd_board_node->Hmd_Inst[j] = (struct Hmd_Inst_Mgmt *)malloc(sizeof(struct Hmd_Inst_Mgmt)); dbus_message_iter_recurse(&iter_inst_array,&iter_inst_struct); //printf(" hmd_board_node = %p \n",hmd_board_node); //printf(" Hmd_Inst[%d] = %p \n",j,hmd_board_node->Hmd_Inst[j]); dbus_message_iter_get_basic(&iter_inst_struct,&(hmd_board_node->Hmd_Inst[j]->Inst_ID)); dbus_message_iter_next(&iter_inst_struct); dbus_message_iter_get_basic(&iter_inst_struct,&(hmd_board_node->Hmd_Inst[j]->slot_no)); dbus_message_iter_next(&iter_inst_struct); dbus_message_iter_get_basic(&iter_inst_struct,&(hmd_board_node->Hmd_Inst[j]->InstState)); dbus_message_iter_next(&iter_inst_struct); dbus_message_iter_get_basic(&iter_inst_struct,&(hmd_board_node->Hmd_Inst[j]->Inst_UNum)); dbus_message_iter_next(&iter_inst_struct); dbus_message_iter_get_basic(&iter_inst_struct,&(hmd_board_node->Hmd_Inst[j]->Inst_DNum)); dbus_message_iter_next(&iter_inst_struct); dbus_message_iter_get_basic(&iter_inst_struct,&(hmd_board_node->Hmd_Inst[j]->Inst_GNum)); dbus_message_iter_next(&iter_inst_struct); dbus_message_iter_get_basic(&iter_inst_struct,&(hmd_board_node->Hmd_Inst[j]->priority)); dbus_message_iter_next(&iter_inst_struct); dbus_message_iter_get_basic(&iter_inst_struct,&(hmd_board_node->Hmd_Inst[j]->isActive)); /*Inst_Hb begin*/ char *ifname = NULL; dbus_message_iter_next(&iter_inst_struct); dbus_message_iter_get_basic(&iter_inst_struct,&(ifname)); //printf(" ifname = %s \n ",ifname); memset(hmd_board_node->Hmd_Inst[j]->Inst_Hb.ifname, 0, strlen(ifname)+1); memcpy(hmd_board_node->Hmd_Inst[j]->Inst_Hb.ifname, ifname, strlen(ifname)); dbus_message_iter_next(&iter_inst_struct); dbus_message_iter_get_basic(&iter_inst_struct,&(hmd_board_node->Hmd_Inst[j]->Inst_Hb.real_ip)); dbus_message_iter_next(&iter_inst_struct); dbus_message_iter_get_basic(&iter_inst_struct,&(hmd_board_node->Hmd_Inst[j]->Inst_Hb.vir_ip)); dbus_message_iter_next(&iter_inst_struct); dbus_message_iter_get_basic(&iter_inst_struct,&(hmd_board_node->Hmd_Inst[j]->Inst_Hb.remote_r_ip)); // dbus_message_iter_next(&iter_inst_struct); // dbus_message_iter_get_basic(&iter_inst_struct,&(hmd_board_node->Hmd_Inst[j]->Inst_Hb.umask)); // dbus_message_iter_next(&iter_inst_struct); // dbus_message_iter_get_basic(&iter_inst_struct,&(hmd_board_node->Hmd_Inst[j]->Inst_Hb.dmask)); /*Inst_Hb end*/ /*Inst_Uplink begin*/ dbus_message_iter_next(&iter_inst_struct); dbus_message_iter_recurse(&iter_inst_struct,&iter_inst_uplink_array); for(k = 0; k < (hmd_board_node->Hmd_Inst[j]->Inst_UNum) ; k++) { dbus_message_iter_recurse(&iter_inst_uplink_array,&iter_inst_uplink_struct); dbus_message_iter_get_basic(&iter_inst_uplink_struct,&(ifname)); memset(hmd_board_node->Hmd_Inst[j]->Inst_Uplink[k].ifname, 0, strlen(ifname)+1); memcpy(hmd_board_node->Hmd_Inst[j]->Inst_Uplink[k].ifname, ifname, strlen(ifname)); dbus_message_iter_next(&iter_inst_uplink_struct); dbus_message_iter_get_basic(&iter_inst_uplink_struct,&(hmd_board_node->Hmd_Inst[j]->Inst_Uplink[k].real_ip)); dbus_message_iter_next(&iter_inst_uplink_struct); dbus_message_iter_get_basic(&iter_inst_uplink_struct,&(hmd_board_node->Hmd_Inst[j]->Inst_Uplink[k].vir_ip)); dbus_message_iter_next(&iter_inst_uplink_struct); dbus_message_iter_get_basic(&iter_inst_uplink_struct,&(hmd_board_node->Hmd_Inst[j]->Inst_Uplink[k].remote_r_ip)); dbus_message_iter_next(&iter_inst_uplink_struct); dbus_message_iter_get_basic(&iter_inst_uplink_struct,&(hmd_board_node->Hmd_Inst[j]->Inst_Uplink[k].mask)); // dbus_message_iter_next(&iter_inst_uplink_struct); // dbus_message_iter_get_basic(&iter_inst_uplink_struct,&(hmd_board_node->Hmd_Inst[j]->Inst_Uplink[k].dmask)); dbus_message_iter_next(&iter_inst_uplink_array); } /*Inst_Uplink end*/ /*Inst_Downlink begin*/ dbus_message_iter_next(&iter_inst_struct); dbus_message_iter_recurse(&iter_inst_struct,&iter_inst_downlink_array); for(k = 0; k < (hmd_board_node->Hmd_Inst[j]->Inst_DNum) ; k++) { dbus_message_iter_recurse(&iter_inst_downlink_array,&iter_inst_downlink_struct); dbus_message_iter_get_basic(&iter_inst_downlink_struct,&(ifname)); memset(hmd_board_node->Hmd_Inst[j]->Inst_Downlink[k].ifname, 0, strlen(ifname)+1); memcpy(hmd_board_node->Hmd_Inst[j]->Inst_Downlink[k].ifname, ifname, strlen(ifname)); dbus_message_iter_next(&iter_inst_downlink_struct); dbus_message_iter_get_basic(&iter_inst_downlink_struct,&(hmd_board_node->Hmd_Inst[j]->Inst_Downlink[k].real_ip)); dbus_message_iter_next(&iter_inst_downlink_struct); dbus_message_iter_get_basic(&iter_inst_downlink_struct,&(hmd_board_node->Hmd_Inst[j]->Inst_Downlink[k].vir_ip)); dbus_message_iter_next(&iter_inst_downlink_struct); dbus_message_iter_get_basic(&iter_inst_downlink_struct,&(hmd_board_node->Hmd_Inst[j]->Inst_Downlink[k].remote_r_ip)); dbus_message_iter_next(&iter_inst_downlink_struct); dbus_message_iter_get_basic(&iter_inst_downlink_struct,&(hmd_board_node->Hmd_Inst[j]->Inst_Downlink[k].mask)); // dbus_message_iter_next(&iter_inst_downlink_struct); // dbus_message_iter_get_basic(&iter_inst_downlink_struct,&(hmd_board_node->Hmd_Inst[j]->Inst_Downlink[k].dmask)); dbus_message_iter_next(&iter_inst_downlink_array); } /*Inst_Downlink end*/ /*Inst_Gateway begin*/ dbus_message_iter_next(&iter_inst_struct); dbus_message_iter_recurse(&iter_inst_struct,&iter_inst_gateway_array); for(k = 0; k < (hmd_board_node->Hmd_Inst[j]->Inst_GNum) ; k++) { dbus_message_iter_recurse(&iter_inst_gateway_array,&iter_inst_gateway_struct); dbus_message_iter_get_basic(&iter_inst_gateway_struct,&(ifname)); memset(hmd_board_node->Hmd_Inst[j]->Inst_Gateway[k].ifname, 0, strlen(ifname)+1); memcpy(hmd_board_node->Hmd_Inst[j]->Inst_Gateway[k].ifname, ifname, strlen(ifname)); dbus_message_iter_next(&iter_inst_gateway_struct); dbus_message_iter_get_basic(&iter_inst_gateway_struct,&(hmd_board_node->Hmd_Inst[j]->Inst_Gateway[k].real_ip)); dbus_message_iter_next(&iter_inst_gateway_struct); dbus_message_iter_get_basic(&iter_inst_gateway_struct,&(hmd_board_node->Hmd_Inst[j]->Inst_Gateway[k].vir_ip)); dbus_message_iter_next(&iter_inst_gateway_struct); dbus_message_iter_get_basic(&iter_inst_gateway_struct,&(hmd_board_node->Hmd_Inst[j]->Inst_Gateway[k].remote_r_ip)); dbus_message_iter_next(&iter_inst_gateway_struct); dbus_message_iter_get_basic(&iter_inst_gateway_struct,&(hmd_board_node->Hmd_Inst[j]->Inst_Gateway[k].mask)); // dbus_message_iter_next(&iter_inst_gateway_struct); // dbus_message_iter_get_basic(&iter_inst_gateway_struct,&(hmd_board_node->Hmd_Inst[j]->Inst_Gateway[k].dmask)); dbus_message_iter_next(&iter_inst_gateway_array); } /*Inst_Gateway end*/ dbus_message_iter_next(&iter_inst_array); } /*Hmd_Inst end*/ dbus_message_iter_next(&iter_board_struct); dbus_message_iter_recurse(&iter_board_struct,&iter_l_inst_array); /*Hmd_Local_Inst begin*/ for(j = 0; j < hmd_board_node->LocalInstNum; j++) { hmd_board_node->Hmd_Local_Inst[j] = (struct Hmd_L_Inst_Mgmt *)malloc(sizeof(struct Hmd_L_Inst_Mgmt)); dbus_message_iter_recurse(&iter_l_inst_array,&iter_l_inst_struct); dbus_message_iter_get_basic(&iter_l_inst_struct,&(hmd_board_node->Hmd_Local_Inst[j]->Inst_ID)); dbus_message_iter_next(&iter_l_inst_struct); dbus_message_iter_get_basic(&iter_l_inst_struct,&(hmd_board_node->Hmd_Local_Inst[j]->slot_no)); dbus_message_iter_next(&iter_l_inst_struct); dbus_message_iter_get_basic(&iter_l_inst_struct,&(hmd_board_node->Hmd_Local_Inst[j]->InstState)); dbus_message_iter_next(&iter_l_inst_struct); dbus_message_iter_get_basic(&iter_l_inst_struct,&(hmd_board_node->Hmd_Local_Inst[j]->Inst_UNum)); dbus_message_iter_next(&iter_l_inst_struct); dbus_message_iter_get_basic(&iter_l_inst_struct,&(hmd_board_node->Hmd_Local_Inst[j]->Inst_DNum)); dbus_message_iter_next(&iter_l_inst_struct); dbus_message_iter_get_basic(&iter_l_inst_struct,&(hmd_board_node->Hmd_Local_Inst[j]->Inst_GNum)); dbus_message_iter_next(&iter_l_inst_struct); dbus_message_iter_get_basic(&iter_l_inst_struct,&(hmd_board_node->Hmd_Local_Inst[j]->priority)); dbus_message_iter_next(&iter_l_inst_struct); dbus_message_iter_get_basic(&iter_l_inst_struct,&(hmd_board_node->Hmd_Local_Inst[j]->isActive)); char *ifname = NULL; /*Inst_Uplink begin*/ dbus_message_iter_next(&iter_l_inst_struct); dbus_message_iter_recurse(&iter_l_inst_struct,&iter_l_inst_uplink_array); for(k = 0; k < (hmd_board_node->Hmd_Local_Inst[j]->Inst_UNum) ; k++) { dbus_message_iter_recurse(&iter_l_inst_uplink_array,&iter_l_inst_uplink_struct); dbus_message_iter_get_basic(&iter_l_inst_uplink_struct,&(ifname)); memset(hmd_board_node->Hmd_Local_Inst[j]->Inst_Uplink[k].ifname, 0, strlen(ifname)+1); memcpy(hmd_board_node->Hmd_Local_Inst[j]->Inst_Uplink[k].ifname, ifname, strlen(ifname)); dbus_message_iter_next(&iter_l_inst_uplink_struct); dbus_message_iter_get_basic(&iter_l_inst_uplink_struct,&(hmd_board_node->Hmd_Local_Inst[j]->Inst_Uplink[k].real_ip)); dbus_message_iter_next(&iter_l_inst_uplink_struct); dbus_message_iter_get_basic(&iter_l_inst_uplink_struct,&(hmd_board_node->Hmd_Local_Inst[j]->Inst_Uplink[k].vir_ip)); dbus_message_iter_next(&iter_l_inst_uplink_struct); dbus_message_iter_get_basic(&iter_l_inst_uplink_struct,&(hmd_board_node->Hmd_Local_Inst[j]->Inst_Uplink[k].remote_r_ip)); dbus_message_iter_next(&iter_l_inst_uplink_struct); dbus_message_iter_get_basic(&iter_l_inst_uplink_struct,&(hmd_board_node->Hmd_Local_Inst[j]->Inst_Uplink[k].mask)); // dbus_message_iter_next(&iter_l_inst_uplink_struct); // dbus_message_iter_get_basic(&iter_l_inst_uplink_struct,&(hmd_board_node->Hmd_Local_Inst[j]->Inst_Uplink[k].dmask)); dbus_message_iter_next(&iter_l_inst_uplink_array); } /*Inst_Uplink end*/ /*Inst_Downlink begin*/ dbus_message_iter_next(&iter_l_inst_struct); dbus_message_iter_recurse(&iter_l_inst_struct,&iter_l_inst_downlink_array); for(k = 0; k < (hmd_board_node->Hmd_Local_Inst[j]->Inst_DNum) ; k++) { dbus_message_iter_recurse(&iter_l_inst_downlink_array,&iter_l_inst_downlink_struct); dbus_message_iter_get_basic(&iter_l_inst_downlink_struct,&(ifname)); memset(hmd_board_node->Hmd_Local_Inst[j]->Inst_Downlink[k].ifname, 0, strlen(ifname)+1); memcpy(hmd_board_node->Hmd_Local_Inst[j]->Inst_Downlink[k].ifname, ifname, strlen(ifname)); dbus_message_iter_next(&iter_l_inst_downlink_struct); dbus_message_iter_get_basic(&iter_l_inst_downlink_struct,&(hmd_board_node->Hmd_Local_Inst[j]->Inst_Downlink[k].real_ip)); dbus_message_iter_next(&iter_l_inst_downlink_struct); dbus_message_iter_get_basic(&iter_l_inst_downlink_struct,&(hmd_board_node->Hmd_Local_Inst[j]->Inst_Downlink[k].vir_ip)); dbus_message_iter_next(&iter_l_inst_downlink_struct); dbus_message_iter_get_basic(&iter_l_inst_downlink_struct,&(hmd_board_node->Hmd_Local_Inst[j]->Inst_Downlink[k].remote_r_ip)); dbus_message_iter_next(&iter_l_inst_downlink_struct); dbus_message_iter_get_basic(&iter_l_inst_downlink_struct,&(hmd_board_node->Hmd_Local_Inst[j]->Inst_Downlink[k].mask)); // dbus_message_iter_next(&iter_l_inst_downlink_struct); // dbus_message_iter_get_basic(&iter_l_inst_downlink_struct,&(hmd_board_node->Hmd_Local_Inst[j]->Inst_Downlink[k].dmask)); dbus_message_iter_next(&iter_l_inst_downlink_array); } /*Inst_Downlink end*/ /*Inst_Gateway begin*/ dbus_message_iter_next(&iter_l_inst_struct); dbus_message_iter_recurse(&iter_l_inst_struct,&iter_l_inst_gateway_array); for(k = 0; k < (hmd_board_node->Hmd_Local_Inst[j]->Inst_GNum) ; k++) { dbus_message_iter_recurse(&iter_l_inst_gateway_array,&iter_l_inst_gateway_struct); dbus_message_iter_get_basic(&iter_l_inst_gateway_struct,&(ifname)); memset(hmd_board_node->Hmd_Local_Inst[j]->Inst_Gateway[k].ifname, 0, strlen(ifname)+1); memcpy(hmd_board_node->Hmd_Local_Inst[j]->Inst_Gateway[k].ifname, ifname, strlen(ifname)); dbus_message_iter_next(&iter_l_inst_gateway_struct); dbus_message_iter_get_basic(&iter_l_inst_gateway_struct,&(hmd_board_node->Hmd_Local_Inst[j]->Inst_Gateway[k].real_ip)); dbus_message_iter_next(&iter_l_inst_gateway_struct); dbus_message_iter_get_basic(&iter_l_inst_gateway_struct,&(hmd_board_node->Hmd_Local_Inst[j]->Inst_Gateway[k].vir_ip)); dbus_message_iter_next(&iter_l_inst_gateway_struct); dbus_message_iter_get_basic(&iter_l_inst_gateway_struct,&(hmd_board_node->Hmd_Local_Inst[j]->Inst_Gateway[k].remote_r_ip)); dbus_message_iter_next(&iter_l_inst_gateway_struct); dbus_message_iter_get_basic(&iter_l_inst_gateway_struct,&(hmd_board_node->Hmd_Local_Inst[j]->Inst_Gateway[k].mask)); // dbus_message_iter_next(&iter_l_inst_gateway_struct); // dbus_message_iter_get_basic(&iter_l_inst_gateway_struct,&(hmd_board_node->Hmd_Local_Inst[j]->Inst_Gateway[k].dmask)); dbus_message_iter_next(&iter_l_inst_gateway_array); } /*Inst_Gateway end*/ dbus_message_iter_next(&iter_l_inst_array); } /*//Hmd_Local_Inst end*/ dbus_message_iter_next(&iter_array); } } dbus_message_unref(reply); return hmd_board_head; }
/* For a synchronous 'op', returns FALSE if 'op' fails */ gboolean upstart_job_exec(svc_action_t * op, gboolean synchronous) { char *job = NULL; int arg_wait = TRUE; const char *arg_env = "pacemaker=1"; const char *action = op->action; DBusError error; DBusMessage *msg = NULL; DBusMessage *reply = NULL; DBusMessageIter iter, array_iter; op->rc = PCMK_OCF_UNKNOWN_ERROR; CRM_ASSERT(upstart_init()); if (safe_str_eq(op->action, "meta-data")) { op->stdout_data = upstart_job_metadata(op->agent); op->rc = PCMK_OCF_OK; goto cleanup; } if(!upstart_job_by_name(op->agent, &job, op->timeout)) { crm_debug("Could not obtain job named '%s' to %s", op->agent, action); if (!g_strcmp0(action, "stop")) { op->rc = PCMK_OCF_OK; } else { op->rc = PCMK_OCF_NOT_INSTALLED; op->status = PCMK_LRM_OP_NOT_INSTALLED; } goto cleanup; } if (safe_str_eq(op->action, "monitor") || safe_str_eq(action, "status")) { char *path = get_first_instance(job, op->timeout); op->rc = PCMK_OCF_NOT_RUNNING; if(path) { DBusPendingCall *pending = NULL; char *state = pcmk_dbus_get_property( upstart_proxy, BUS_NAME, path, UPSTART_06_API ".Instance", "state", op->synchronous?NULL:upstart_job_check, op, op->synchronous?NULL:&pending, op->timeout); free(job); free(path); if(op->synchronous) { upstart_job_check("state", state, op); free(state); return op->rc == PCMK_OCF_OK; } else if (pending) { services_set_op_pending(op, pending); services_add_inflight_op(op); return TRUE; } return FALSE; } goto cleanup; } else if (!g_strcmp0(action, "start")) { action = "Start"; } else if (!g_strcmp0(action, "stop")) { action = "Stop"; } else if (!g_strcmp0(action, "restart")) { action = "Restart"; } else { op->rc = PCMK_OCF_UNIMPLEMENT_FEATURE; goto cleanup; } crm_debug("Calling %s for %s on %s", action, op->rsc, job); msg = dbus_message_new_method_call(BUS_NAME, // target for the method call job, // object to call on UPSTART_JOB_IFACE, // interface to call on action); // method name CRM_ASSERT(msg != NULL); dbus_message_iter_init_append (msg, &iter); CRM_LOG_ASSERT(dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &array_iter)); CRM_LOG_ASSERT(dbus_message_iter_append_basic (&array_iter, DBUS_TYPE_STRING, &arg_env)); CRM_LOG_ASSERT(dbus_message_iter_close_container (&iter, &array_iter)); CRM_LOG_ASSERT(dbus_message_append_args(msg, DBUS_TYPE_BOOLEAN, &arg_wait, DBUS_TYPE_INVALID)); if (op->synchronous == FALSE) { DBusPendingCall* pending = pcmk_dbus_send(msg, upstart_proxy, upstart_async_dispatch, op, op->timeout); free(job); if(pending) { services_set_op_pending(op, pending); services_add_inflight_op(op); return TRUE; } return FALSE; } dbus_error_init(&error); reply = pcmk_dbus_send_recv(msg, upstart_proxy, &error, op->timeout); if(error.name) { if(!upstart_mask_error(op, error.name)) { crm_err("Could not issue %s for %s: %s (%s)", action, op->rsc, error.name, job); } } else if (!g_strcmp0(op->action, "stop")) { /* No return vaue */ op->rc = PCMK_OCF_OK; } else if(!pcmk_dbus_type_check(reply, NULL, DBUS_TYPE_OBJECT_PATH, __FUNCTION__, __LINE__)) { crm_warn("Call to %s passed but return type was unexpected", op->action); op->rc = PCMK_OCF_OK; } else { const char *path = NULL; dbus_message_get_args (reply, NULL, DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID); crm_info("Call to %s passed: %s", op->action, path); op->rc = PCMK_OCF_OK; } cleanup: free(job); if(msg) { dbus_message_unref(msg); } if(reply) { dbus_message_unref(reply); } if (op->synchronous == FALSE) { return operation_finalize(op); } return op->rc == PCMK_OCF_OK; }
int rdc_get_radius_conf(DBusConnection *connection, int hansitype, int insid, char *domain,struct rdc_coa_radius_conf *radiusconf ) { DBusMessage *query, *reply; DBusError err; DBusMessageIter iter; DBusMessageIter iter_array; int ret=0,i=0; unsigned long num = 0; char *auth_secret=NULL; if( NULL == domain ){ domain = ""; } if( NULL == radiusconf ){ return EAG_ERR_INPUT_PARAM_ERR; } rdc_dbus_path_reinit(hansitype,insid); query = dbus_message_new_method_call( RDC_DBUS_NAME, RDC_DBUS_OBJPATH, RDC_DBUS_INTERFACE, RDC_DBUS_METHOD_GET_RADIUS_CONF ); dbus_error_init(&err); dbus_message_append_args(query, DBUS_TYPE_STRING, &domain, DBUS_TYPE_INVALID ); reply = dbus_connection_send_with_reply_and_block ( connection, query, -1, &err ); dbus_message_unref(query); if ( NULL == reply ){ if (dbus_error_is_set(&err)){ dbus_error_free(&err); } return EAG_ERR_DBUS_FAILED; } else{ dbus_message_iter_init(reply,&iter); dbus_message_iter_get_basic(&iter, &ret); if( EAG_RETURN_OK == ret ){ dbus_message_iter_next(&iter); dbus_message_iter_get_basic(&iter, &num); if( num > MAX_RADIUS_SRV_NUM ){ num = MAX_RADIUS_SRV_NUM; } radiusconf->current_num = num; if( num > 0 ){ dbus_message_iter_next(&iter); dbus_message_iter_recurse(&iter,&iter_array); for( i=0; i<num; i++ ){ DBusMessageIter iter_struct; dbus_message_iter_recurse(&iter_array,&iter_struct); /*domain*/ /*dbus_message_iter_get_basic(&iter_struct, &domain ); if( NULL != domain ){ strncpy( radiusconf->radius_srv[i].domain, domain, MAX_RADIUS_DOMAIN_LEN-1); } dbus_message_iter_next(&iter_struct); */ /*auth*/ dbus_message_iter_get_basic(&iter_struct, &(radiusconf->radius_srv[i].auth_ip)); dbus_message_iter_next(&iter_struct); dbus_message_iter_get_basic(&iter_struct, &(radiusconf->radius_srv[i].auth_port)); dbus_message_iter_next(&iter_struct); dbus_message_iter_get_basic(&iter_struct,&auth_secret); if( NULL != auth_secret ){ strncpy(radiusconf->radius_srv[i].auth_secret, auth_secret, RADIUS_SECRETSIZE-1); } dbus_message_iter_next(&iter_array); } } } } dbus_message_unref(reply); return ret; }
TEST_F(LibdbusTest, DISABLED_NonreplyingLibdbusConnectionsAreHandled) { const char problemServiceName[] = "problem.service"; replyArrived = false; bool running = true; dbus_threads_init_default(); ::DBusConnection* serviceConnection = createConnection(); ::DBusConnection* clientConnection = createConnection(); dbus_bus_request_name(serviceConnection, problemServiceName, DBUS_NAME_FLAG_DO_NOT_QUEUE, NULL); dbus_connection_try_register_object_path(serviceConnection, "/", &libdbusObjectPathVTable, NULL, NULL); std::thread([&, this] { while(running) { dbus_connection_read_write_dispatch(serviceConnection, 10); } }).detach(); usleep(100000); ::DBusMessage* message = dbus_message_new_method_call(problemServiceName, "/", NULL, "someMethod"); ::DBusPendingCall* libdbusPendingCall; dbus_connection_send_with_reply( clientConnection, message, &libdbusPendingCall, 3000); dbus_pending_call_set_notify( libdbusPendingCall, onLibdbusPendingCallNotifyThunk, NULL, NULL); //100*50 = 5000 (ms) ==> 3 seconds timeout pending call *should* have arrived by now. for (unsigned int i = 0; i < 100 && (!replyArrived); i++) { dbus_connection_read_write_dispatch(clientConnection, 50); } EXPECT_TRUE(replyArrived); running = false; usleep(100000); dbus_connection_close(serviceConnection); dbus_connection_unref(serviceConnection); dbus_connection_close(clientConnection); dbus_connection_unref(clientConnection); }
static gboolean ck_tracker_init_get_sessions_for_seat (CKTracker *tracker, CKSeat *seat) { gboolean ret; DBusError error; DBusMessage *message; DBusMessage *reply; DBusMessageIter iter; DBusMessageIter iter_array; ret = FALSE; message = dbus_message_new_method_call ("org.freedesktop.ConsoleKit", seat->seat_objpath, "org.freedesktop.ConsoleKit.Seat", "GetSessions"); dbus_error_init (&error); reply = dbus_connection_send_with_reply_and_block (tracker->dbus_connection, message, -1, &error); if (reply == NULL || dbus_error_is_set (&error)) { HAL_ERROR (("Error doing GetSeats on ConsoleKit: %s: %s", error.name, error.message)); dbus_message_unref (message); if (reply != NULL) dbus_message_unref (reply); goto error; } dbus_message_iter_init (reply, &iter); if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_ARRAY) { HAL_WARNING (("Expecting an array from GetSessions on ConsoleKit.")); dbus_message_unref (message); dbus_message_unref (reply); goto error; } dbus_message_iter_recurse (&iter, &iter_array); while (dbus_message_iter_get_arg_type (&iter_array) == DBUS_TYPE_OBJECT_PATH) { const char *session_objpath; CKSession *session; dbus_message_iter_get_basic (&iter_array, &session_objpath); HAL_INFO (("got session '%s' for seat '%s'", session_objpath, seat->seat_objpath)); session = ck_session_new (session_objpath); /* get information: is_active etc. */ if (!ck_session_get_info (tracker, session)) { HAL_ERROR (("Could not get information for session '%s'", session_objpath)); dbus_message_unref (message); dbus_message_unref (reply); goto error; } ck_seat_attach_session (seat, session); tracker->sessions = g_slist_prepend (tracker->sessions, session); dbus_message_iter_next (&iter_array); } dbus_message_unref (message); dbus_message_unref (reply); HAL_INFO (("Got all sessions on seat '%s'", seat->seat_objpath)); ret = TRUE; error: if (dbus_error_is_set (&error)) dbus_error_free (&error); return ret; }
static int check_version(AvahiClient *client, int *ret_error) { DBusMessage *message = NULL, *reply = NULL; DBusError error; uint32_t version; int e = AVAHI_ERR_NO_MEMORY; assert(client); dbus_error_init(&error); if (!(message = dbus_message_new_method_call(AVAHI_DBUS_NAME, AVAHI_DBUS_PATH_SERVER, AVAHI_DBUS_INTERFACE_SERVER, "GetAPIVersion"))) goto fail; reply = dbus_connection_send_with_reply_and_block (client->bus, message, -1, &error); if (!reply || dbus_error_is_set (&error)) { char *version_str; if (!dbus_error_is_set(&error) || strcmp(error.name, DBUS_ERROR_UNKNOWN_METHOD)) goto fail; /* If the method GetAPIVersion is not known, we look if * GetVersionString matches "avahi 0.6" which is the only * version we support which doesn't have GetAPIVersion() .*/ dbus_message_unref(message); if (reply) dbus_message_unref(reply); dbus_error_free(&error); if (!(message = dbus_message_new_method_call(AVAHI_DBUS_NAME, AVAHI_DBUS_PATH_SERVER, AVAHI_DBUS_INTERFACE_SERVER, "GetVersionString"))) goto fail; reply = dbus_connection_send_with_reply_and_block (client->bus, message, -1, &error); if (!reply || dbus_error_is_set (&error)) goto fail; if (!dbus_message_get_args (reply, &error, DBUS_TYPE_STRING, &version_str, DBUS_TYPE_INVALID) || dbus_error_is_set (&error)) goto fail; version = strcmp(version_str, "avahi 0.6") == 0 ? 0x0201 : 0x0000; } else { if (!dbus_message_get_args (reply, &error, DBUS_TYPE_UINT32, &version, DBUS_TYPE_INVALID) || dbus_error_is_set(&error)) goto fail; } /*fprintf(stderr, "API Version 0x%04x\n", version);*/ if ((version & 0xFF00) != (AVAHI_CLIENT_DBUS_API_SUPPORTED & 0xFF00) || (version & 0x00FF) < (AVAHI_CLIENT_DBUS_API_SUPPORTED & 0x00FF)) { e = AVAHI_ERR_VERSION_MISMATCH; goto fail; } dbus_message_unref(message); dbus_message_unref(reply); return AVAHI_OK; fail: if (dbus_error_is_set(&error)) { e = avahi_error_dbus_to_number (error.name); dbus_error_free(&error); } if (ret_error) *ret_error = e; if (message) dbus_message_unref(message); if (reply) dbus_message_unref(reply); return e; }
int cras_bt_transport_release(struct cras_bt_transport *transport, unsigned int blocking) { DBusMessage *method_call, *reply; DBusPendingCall *pending_call; DBusError dbus_error; if (transport->fd < 0) return 0; /* Close the transport on our end no matter whether or not the server * gives us an error. */ close(transport->fd); transport->fd = -1; method_call = dbus_message_new_method_call( BLUEZ_SERVICE, transport->object_path, BLUEZ_INTERFACE_MEDIA_TRANSPORT, "Release"); if (!method_call) return -ENOMEM; if (blocking) { dbus_error_init(&dbus_error); reply = dbus_connection_send_with_reply_and_block( transport->conn, method_call, DBUS_TIMEOUT_USE_DEFAULT, &dbus_error); if (!reply) { syslog(LOG_ERR, "Failed to release transport %s: %s", transport->object_path, dbus_error.message); dbus_error_free(&dbus_error); dbus_message_unref(method_call); return -EIO; } dbus_message_unref(method_call); if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR) { syslog(LOG_ERR, "Release returned error: %s", dbus_message_get_error_name(reply)); dbus_message_unref(reply); return -EIO; } dbus_message_unref(reply); } else { if (!dbus_connection_send_with_reply( transport->conn, method_call, &pending_call, DBUS_TIMEOUT_USE_DEFAULT)) { dbus_message_unref(method_call); return -ENOMEM; } dbus_message_unref(method_call); if (!pending_call) return -EIO; if (!dbus_pending_call_set_notify(pending_call, cras_bt_on_transport_release, transport, NULL)) { dbus_pending_call_cancel(pending_call); dbus_pending_call_unref(pending_call); return -ENOMEM; } } return 0; }
AvahiClient *avahi_client_new(const AvahiPoll *poll_api, AvahiClientFlags flags, AvahiClientCallback callback, void *userdata, int *ret_error) { AvahiClient *client = NULL; DBusError error; DBusMessage *message = NULL, *reply = NULL; avahi_init_i18n(); dbus_error_init(&error); if (!(client = avahi_new(AvahiClient, 1))) { if (ret_error) *ret_error = AVAHI_ERR_NO_MEMORY; goto fail; } client->poll_api = poll_api; client->error = AVAHI_OK; client->callback = callback; client->userdata = userdata; client->state = (AvahiClientState) -1; client->flags = flags; client->host_name = NULL; client->host_name_fqdn = NULL; client->domain_name = NULL; client->version_string = NULL; client->local_service_cookie_valid = 0; AVAHI_LLIST_HEAD_INIT(AvahiEntryGroup, client->groups); AVAHI_LLIST_HEAD_INIT(AvahiDomainBrowser, client->domain_browsers); AVAHI_LLIST_HEAD_INIT(AvahiServiceBrowser, client->service_browsers); AVAHI_LLIST_HEAD_INIT(AvahiServiceTypeBrowser, client->service_type_browsers); AVAHI_LLIST_HEAD_INIT(AvahiServiceResolver, client->service_resolvers); AVAHI_LLIST_HEAD_INIT(AvahiHostNameResolver, client->host_name_resolvers); AVAHI_LLIST_HEAD_INIT(AvahiAddressResolver, client->address_resolvers); AVAHI_LLIST_HEAD_INIT(AvahiRecordBrowser, client->record_browsers); if (!(client->bus = avahi_dbus_bus_get(&error)) || dbus_error_is_set(&error)) { if (ret_error) *ret_error = AVAHI_ERR_DBUS_ERROR; goto fail; } if (avahi_dbus_connection_glue(client->bus, poll_api) < 0) { if (ret_error) *ret_error = AVAHI_ERR_NO_MEMORY; /* Not optimal */ goto fail; } if (!dbus_connection_add_filter(client->bus, filter_func, client, NULL)) { if (ret_error) *ret_error = AVAHI_ERR_NO_MEMORY; goto fail; } dbus_bus_add_match( client->bus, "type='signal', " "interface='" AVAHI_DBUS_INTERFACE_SERVER "', " "sender='" AVAHI_DBUS_NAME "', " "path='" AVAHI_DBUS_PATH_SERVER "'", &error); if (dbus_error_is_set(&error)) goto fail; dbus_bus_add_match ( client->bus, "type='signal', " "interface='" DBUS_INTERFACE_DBUS "', " "sender='" DBUS_SERVICE_DBUS "', " "path='" DBUS_PATH_DBUS "'", &error); if (dbus_error_is_set(&error)) goto fail; dbus_bus_add_match( client->bus, "type='signal', " "interface='" DBUS_INTERFACE_LOCAL "'", &error); if (dbus_error_is_set(&error)) goto fail; if (!(message = dbus_message_new_method_call(AVAHI_DBUS_NAME, AVAHI_DBUS_PATH_SERVER, "org.freedesktop.DBus.Peer", "Ping"))) goto fail; reply = dbus_connection_send_with_reply_and_block (client->bus, message, -1, &error); if (!reply || dbus_error_is_set (&error)) { /* We free the error so its not set, that way the fail target * will return the NO_DAEMON error rather than a DBUS error */ dbus_error_free(&error); if (!(flags & AVAHI_CLIENT_NO_FAIL)) { if (ret_error) *ret_error = AVAHI_ERR_NO_DAEMON; goto fail; } /* The user doesn't want this call to fail if the daemon is not * available, so let's return succesfully */ client_set_state(client, AVAHI_CLIENT_CONNECTING); } else { if (init_server(client, ret_error) < 0) goto fail; } dbus_message_unref(message); if (reply) dbus_message_unref(reply); return client; fail: if (message) dbus_message_unref(message); if (reply) dbus_message_unref(reply); if (client) avahi_client_free(client); if (dbus_error_is_set(&error)) { if (ret_error) { if (strcmp(error.name, DBUS_ERROR_FILE_NOT_FOUND) == 0) /* DBUS returns this error when the DBUS daemon is not running */ *ret_error = AVAHI_ERR_NO_DAEMON; else *ret_error = avahi_error_dbus_to_number(error.name); } dbus_error_free(&error); } return NULL; }
gboolean fun_dbus_perform_service (guint service, gchar *ip_arg, gchar **op_arg1, gchar **op_arg2) { DBusMessage *message = NULL; DBusMessage *reply = NULL; DBusError error; int reply_timeout = -1; switch (service) { case PERFORM_UPDATE: { dbus_error_init (&error); message = dbus_message_new_method_call ("org.frugalware.FWUpdateNotifier", "/org/frugalware/FWUpdateNotifier", "org.frugalware.FWUpdateNotifier", "PerformUpdate"); reply = dbus_connection_send_with_reply_and_block (fun_conn, message, reply_timeout, &error); if (dbus_error_is_set(&error)) { fprintf (stderr, "ERROR: %s\n", error.message); dbus_error_free (&error); return FALSE; } if (!dbus_message_get_args (reply, &error, DBUS_TYPE_STRING, op_arg1, DBUS_TYPE_INVALID)) { fprintf (stderr, "ERROR: %s\n", error.message); dbus_error_free (&error); return FALSE; } dbus_message_unref (reply); dbus_message_unref (message); break; } case TEST_SERVICE: { guint ret = 0; dbus_error_init (&error); message = dbus_message_new_method_call ("org.frugalware.FWUpdateNotifier", "/org/frugalware/FWUpdateNotifier", "org.frugalware.FWUpdateNotifier", "TestService"); reply = dbus_connection_send_with_reply_and_block (fun_conn, message, reply_timeout, &error); if (dbus_error_is_set(&error)) { fprintf (stderr, "ERROR: %s\n", error.message); dbus_error_free (&error); return FALSE; } if (!dbus_message_get_args (reply, &error, DBUS_TYPE_INT32, &ret, DBUS_TYPE_INVALID)) { fprintf (stderr, "ERROR: %s\n", error.message); dbus_error_free (&error); return FALSE; } dbus_message_unref (reply); dbus_message_unref (message); break; } case GET_PACKAGE_INFO: { dbus_error_init (&error); message = dbus_message_new_method_call ("org.frugalware.FWUpdateNotifier", "/org/frugalware/FWUpdateNotifier", "org.frugalware.FWUpdateNotifier", "GetPackageInfo"); dbus_message_append_args (message, DBUS_TYPE_STRING, &ip_arg); reply = dbus_connection_send_with_reply_and_block (fun_conn, message, reply_timeout, &error); if (dbus_error_is_set(&error)) { fprintf (stderr, "ERROR: %s\n", error.message); dbus_error_free (&error); return FALSE; } if (!dbus_message_get_args (reply, &error, DBUS_TYPE_STRING, op_arg1, DBUS_TYPE_STRING, op_arg2, DBUS_TYPE_INVALID)) { fprintf (stderr, "ERROR: %s\n", error.message); dbus_error_free (&error); return FALSE; } dbus_message_unref (reply); dbus_message_unref (message); break; } default: break; } return TRUE; }
int rd_acquire( rd_device **_d, DBusConnection *connection, const char *device_name, const char *application_name, int32_t priority, rd_request_cb_t request_cb, DBusError *error) { rd_device *d = NULL; int r, k; DBusError _error; DBusMessage *m = NULL, *reply = NULL; dbus_bool_t good; if (!error) error = &_error; dbus_error_init(error); if (!_d) return -EINVAL; if (!connection) return -EINVAL; if (!device_name) return -EINVAL; if (!request_cb && priority != INT32_MAX) return -EINVAL; if (!(d = calloc(sizeof(rd_device), 1))) return -ENOMEM; d->ref = 1; if (!(d->device_name = strdup(device_name))) { r = -ENOMEM; goto fail; } if (!(d->application_name = strdup(application_name))) { r = -ENOMEM; goto fail; } d->priority = priority; d->connection = dbus_connection_ref(connection); d->request_cb = request_cb; if (!(d->service_name = malloc(sizeof(SERVICE_PREFIX) + strlen(device_name)))) { r = -ENOMEM; goto fail; } sprintf(d->service_name, SERVICE_PREFIX "%s", d->device_name); if (!(d->object_path = malloc(sizeof(OBJECT_PREFIX) + strlen(device_name)))) { r = -ENOMEM; goto fail; } sprintf(d->object_path, OBJECT_PREFIX "%s", d->device_name); if ((k = dbus_bus_request_name( d->connection, d->service_name, DBUS_NAME_FLAG_DO_NOT_QUEUE| (priority < INT32_MAX ? DBUS_NAME_FLAG_ALLOW_REPLACEMENT : 0), error)) < 0) { r = -EIO; goto fail; } if (k == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) goto success; if (k != DBUS_REQUEST_NAME_REPLY_EXISTS) { r = -EIO; goto fail; } if (priority <= INT32_MIN) { r = -EBUSY; goto fail; } if (!(m = dbus_message_new_method_call( d->service_name, d->object_path, "org.freedesktop.ReserveDevice1", "RequestRelease"))) { r = -ENOMEM; goto fail; } if (!dbus_message_append_args( m, DBUS_TYPE_INT32, &d->priority, DBUS_TYPE_INVALID)) { r = -ENOMEM; goto fail; } if (!(reply = dbus_connection_send_with_reply_and_block( d->connection, m, 5000, /* 5s */ error))) { if (dbus_error_has_name(error, DBUS_ERROR_TIMED_OUT) || dbus_error_has_name(error, DBUS_ERROR_UNKNOWN_METHOD) || dbus_error_has_name(error, DBUS_ERROR_NO_REPLY)) { /* This must be treated as denied. */ r = -EBUSY; goto fail; } r = -EIO; goto fail; } if (!dbus_message_get_args( reply, error, DBUS_TYPE_BOOLEAN, &good, DBUS_TYPE_INVALID)) { r = -EIO; goto fail; } if (!good) { r = -EBUSY; goto fail; } if ((k = dbus_bus_request_name( d->connection, d->service_name, DBUS_NAME_FLAG_DO_NOT_QUEUE| (priority < INT32_MAX ? DBUS_NAME_FLAG_ALLOW_REPLACEMENT : 0)| DBUS_NAME_FLAG_REPLACE_EXISTING, error)) < 0) { r = -EIO; goto fail; } if (k != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) { r = -EIO; goto fail; } success: d->owning = 1; if (!(dbus_connection_register_object_path( d->connection, d->object_path, &vtable, d))) { r = -ENOMEM; goto fail; } d->registered = 1; if (!dbus_connection_add_filter( d->connection, filter_handler, d, NULL)) { r = -ENOMEM; goto fail; } d->filtering = 1; *_d = d; return 0; fail: if (m) dbus_message_unref(m); if (reply) dbus_message_unref(reply); if (&_error == error) dbus_error_free(&_error); if (d) rd_release(d); return r; }