bool FCodeLiteSourceCodeAccessor::OpenSourceFiles(const TArray<FString>& AbsoluteSourcePaths)
{
	FString CodeLitePath;
	if(!CanRunCodeLite(CodeLitePath))
	{
		UE_LOG(LogCodeLiteAccessor, Warning, TEXT("FCodeLiteSourceCodeAccessor::OpenSourceFiles: Cannot find CodeLite binary"));
		return false;
	}

#ifdef USE_DBUS	

	for(const auto& SourcePath : AbsoluteSourcePaths)
	{
		
		DBusMessage* message = nullptr;
		DBusMessageIter args;
		
		// Create new message.
		message = dbus_message_new_signal ("/org/codelite/command", "org.codelite.command", "OpenFile");

		char* fileName = TCHAR_TO_ANSI(*SourcePath);

		// Add parameters to the message.
		dbus_message_iter_init_append(message, &args);
		if(!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &fileName)) {
			UE_LOG(LogCodeLiteAccessor, Warning, TEXT("Sdbus_message_iter_append_basic failed."));
			return false;
		}
		
		// Send the message.
		dbus_connection_send(DBusConnection, message, nullptr);
		if(dbus_error_is_set(&DBusError))
		{
			UE_LOG(LogCodeLiteAccessor, Warning, TEXT("dbus_connection_send failed: %s"), DBusError.message);
			return false;
		}

		// Free the message resources.
		dbus_message_unref(message);

	}

	dbus_connection_flush(DBusConnection);

	return true;

#else

	for(const auto& SourcePath : AbsoluteSourcePaths)
	{
		const FString Path = FString::Printf(TEXT("\"%s\""), *SourcePath);

		FProcHandle Proc = FPlatformProcess::CreateProc(*CodeLitePath, *Path, true, false, false, nullptr, 0, nullptr, nullptr);
		if(Proc.IsValid())
		{
			UE_LOG(LogCodeLiteAccessor, Warning, TEXT("CodeLiteSourceCodeAccessor::OpenSourceFiles: %s"), *Path);
			FPlatformProcess::CloseProc(Proc);
			return true;
		}
	}

#endif

	return false;
}
static dbus_bool_t
GalagoNotification_notifyAppendArgs(
    JNIEnv *env, DBusMessage *message, jstring appName, jlong replacesId,
    jobject icon, jstring summary, jstring body, jint expireTimeout)
{
    DBusMessageIter iter;
    dbus_uint32_t _replacesId;
    DBusMessageIter subIter;
    dbus_int32_t _expireTimeout;

    dbus_message_iter_init_append(message, &iter);

    if (!GalagoNotification_messageAppendString(env, &iter, appName))
        return FALSE;

    _replacesId = replacesId;
    if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_UINT32, &_replacesId))
        return FALSE;

    if (!GalagoNotification_messageAppendString(env, &iter, NULL))
        return FALSE;

    if (!GalagoNotification_messageAppendString(env, &iter, summary))
        return FALSE;

    if (!GalagoNotification_messageAppendString(env, &iter, body))
        return FALSE;

    if (!dbus_message_iter_open_container(
            &iter,
            DBUS_TYPE_ARRAY,
            DBUS_TYPE_STRING_AS_STRING,
            &subIter))
        return FALSE;
    if (!dbus_message_iter_close_container(&iter, &subIter))
        return FALSE;

    if (!dbus_message_iter_open_container(
            &iter,
            DBUS_TYPE_ARRAY,
            "{sv}",
            &subIter))
        return FALSE;
    if (icon)
    {
        Image _icon;

        _icon.jdata = NULL;
        _icon.data = NULL;
        if (GalagoNotification_jobject2Image(env, icon, &_icon))
        {
            dbus_bool_t success;

            success
                = GalagoNotification_messageAppendIconHint(&subIter, &_icon);
            if (_icon.jdata && _icon.data)
                (*env)
                    ->ReleaseIntArrayElements(
                        env,
                        _icon.jdata,
                        _icon.data,
                        JNI_ABORT);
            if (!success)
                return FALSE;
        }
    }
    if (!dbus_message_iter_close_container(&iter, &subIter))
        return FALSE;

    _expireTimeout = expireTimeout;
    if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &_expireTimeout))
        return FALSE;

    return TRUE;
}
Esempio n. 3
0
DBusMessage * wbmd_dbus_interface_show_wbridge_mint_info(DBusConnection *conn, DBusMessage *msg, void *user_data){
	
	DBusMessage* reply;	
	DBusMessageIter	 iter;
	DBusMessageIter	 iter_array;
	DBusMessageIter iter_sub_array;
	DBusMessageIter iter_sub_struct;
	unsigned int num=0;
	DBusError err;
	int ret = WBMD_DBUS_SUCCESS;
	dbus_error_init(&err);
	int i=0;
	int j = 0;
	int WBID;
	char *name = NULL;
	struct wbridge_info *wb[WBRIDGE_NUM];
	dbus_error_init(&err);
	if (!(dbus_message_get_args ( msg, &err,
								DBUS_TYPE_UINT32,&WBID,
								DBUS_TYPE_INVALID))){

		printf("Unable to get input args\n");
				
		if (dbus_error_is_set(&err)) {
			printf("%s raised: %s",err.name,err.message);
			dbus_error_free(&err);
		}
		return NULL;
	}
	if(WBID == 0){
		while(i<WBRIDGE_NUM){
			if(wBridge[i] != NULL)
			{
				wb[num] = wBridge[i];
				num++;
			}
			i++;
		}
	}else{
		if(wBridge[WBID] != NULL){
			wb[num] = wBridge[WBID];
			num++;
		}
	}
	if(num == 0)
		ret = WBMD_DBUS_ID_NO_EXIST;
	
	reply = dbus_message_new_method_return(msg);
		
	dbus_message_iter_init_append (reply, &iter);
		
	dbus_message_iter_append_basic (&iter,
										 DBUS_TYPE_UINT32,
										 &ret);
	if(ret == WBMD_DBUS_SUCCESS){
		name = (char *)malloc(DEFAULT_LEN);
		memset(name, 0, DEFAULT_LEN);
		dbus_message_iter_append_basic (&iter,
											 DBUS_TYPE_UINT32,
											 &num);
			
		dbus_message_iter_open_container (&iter,
										DBUS_TYPE_ARRAY,
										DBUS_STRUCT_BEGIN_CHAR_AS_STRING
												DBUS_TYPE_UINT32_AS_STRING					
												DBUS_TYPE_UINT32_AS_STRING
												DBUS_TYPE_UINT32_AS_STRING
												DBUS_TYPE_ARRAY_AS_STRING
												DBUS_STRUCT_BEGIN_CHAR_AS_STRING
													DBUS_TYPE_BYTE_AS_STRING
													DBUS_TYPE_BYTE_AS_STRING
													DBUS_TYPE_BYTE_AS_STRING
													DBUS_TYPE_BYTE_AS_STRING
													DBUS_TYPE_BYTE_AS_STRING
													DBUS_TYPE_BYTE_AS_STRING
													DBUS_TYPE_UINT32_AS_STRING
													DBUS_TYPE_UINT32_AS_STRING
													DBUS_TYPE_UINT32_AS_STRING
													DBUS_TYPE_UINT32_AS_STRING
													DBUS_TYPE_UINT32_AS_STRING
													DBUS_TYPE_UINT32_AS_STRING
													DBUS_TYPE_STRING_AS_STRING
													DBUS_TYPE_UINT32_AS_STRING
													DBUS_TYPE_UINT32_AS_STRING
													DBUS_TYPE_UINT32_AS_STRING
													DBUS_TYPE_UINT32_AS_STRING
													DBUS_TYPE_UINT32_AS_STRING
													DBUS_TYPE_UINT32_AS_STRING
													DBUS_TYPE_UINT32_AS_STRING
													DBUS_TYPE_UINT32_AS_STRING
													DBUS_TYPE_UINT32_AS_STRING
													DBUS_TYPE_UINT32_AS_STRING
													DBUS_TYPE_UINT32_AS_STRING
													DBUS_TYPE_UINT32_AS_STRING
													DBUS_TYPE_UINT32_AS_STRING
													DBUS_TYPE_UINT32_AS_STRING
													DBUS_TYPE_UINT32_AS_STRING
													DBUS_TYPE_UINT32_AS_STRING
													DBUS_TYPE_UINT32_AS_STRING
													DBUS_TYPE_UINT32_AS_STRING
													DBUS_TYPE_STRING_AS_STRING
												DBUS_STRUCT_END_CHAR_AS_STRING
										DBUS_STRUCT_END_CHAR_AS_STRING,
										&iter_array);

		for(i = 0; i < num; i++){			
			DBusMessageIter iter_struct;
			dbus_message_iter_open_container (&iter_array,
											DBUS_TYPE_STRUCT,
											NULL,
											&iter_struct);
			dbus_message_iter_append_basic
						(&iter_struct,
						  DBUS_TYPE_UINT32,
						  &(wb[i]->WBID));

			dbus_message_iter_append_basic
						(&iter_struct,
						  DBUS_TYPE_UINT32,
						  &(wb[i]->IP));
				
			dbus_message_iter_append_basic
						(&iter_struct,
						  DBUS_TYPE_UINT32,
						  &(wb[i]->WBState));
							
			dbus_message_iter_open_container (&iter_struct,
											DBUS_TYPE_ARRAY,
											DBUS_STRUCT_BEGIN_CHAR_AS_STRING
												DBUS_TYPE_BYTE_AS_STRING
												DBUS_TYPE_BYTE_AS_STRING
												DBUS_TYPE_BYTE_AS_STRING
												DBUS_TYPE_BYTE_AS_STRING
												DBUS_TYPE_BYTE_AS_STRING
												DBUS_TYPE_BYTE_AS_STRING
												DBUS_TYPE_UINT32_AS_STRING
												DBUS_TYPE_UINT32_AS_STRING
												DBUS_TYPE_UINT32_AS_STRING
												DBUS_TYPE_UINT32_AS_STRING
												DBUS_TYPE_UINT32_AS_STRING
												DBUS_TYPE_UINT32_AS_STRING
												DBUS_TYPE_STRING_AS_STRING
												DBUS_TYPE_UINT32_AS_STRING
												DBUS_TYPE_UINT32_AS_STRING
												DBUS_TYPE_UINT32_AS_STRING
												DBUS_TYPE_UINT32_AS_STRING
												DBUS_TYPE_UINT32_AS_STRING
												DBUS_TYPE_UINT32_AS_STRING
												DBUS_TYPE_UINT32_AS_STRING
												DBUS_TYPE_UINT32_AS_STRING
												DBUS_TYPE_UINT32_AS_STRING
												DBUS_TYPE_UINT32_AS_STRING
												DBUS_TYPE_UINT32_AS_STRING
												DBUS_TYPE_UINT32_AS_STRING
												DBUS_TYPE_UINT32_AS_STRING
												DBUS_TYPE_UINT32_AS_STRING
												DBUS_TYPE_UINT32_AS_STRING
												DBUS_TYPE_UINT32_AS_STRING
												DBUS_TYPE_UINT32_AS_STRING
												DBUS_TYPE_UINT32_AS_STRING
												DBUS_TYPE_STRING_AS_STRING
											DBUS_STRUCT_END_CHAR_AS_STRING,
										  &iter_sub_array);
			for(j = 0;j < 1; j++)
		   	{
		       
				dbus_message_iter_open_container (&iter_sub_array,
				 									 DBUS_TYPE_STRUCT,
				 									 NULL,
													 &iter_sub_struct);
						
				dbus_message_iter_append_basic (&iter_sub_struct,DBUS_TYPE_BYTE ,&(wb[i]->WBMintNode.netAddress[0]));

				dbus_message_iter_append_basic (&iter_sub_struct,DBUS_TYPE_BYTE ,&(wb[i]->WBMintNode.netAddress[1]));

				dbus_message_iter_append_basic (&iter_sub_struct,DBUS_TYPE_BYTE ,&(wb[i]->WBMintNode.netAddress[2]));

				dbus_message_iter_append_basic (&iter_sub_struct,DBUS_TYPE_BYTE ,&(wb[i]->WBMintNode.netAddress[3]));

				dbus_message_iter_append_basic (&iter_sub_struct,DBUS_TYPE_BYTE ,&(wb[i]->WBMintNode.netAddress[4]));

				dbus_message_iter_append_basic (&iter_sub_struct,DBUS_TYPE_BYTE ,&(wb[i]->WBMintNode.netAddress[5]));

				dbus_message_iter_append_basic (&iter_sub_struct,DBUS_TYPE_UINT32 ,&(wb[i]->WBMintNode.nodeType));

				dbus_message_iter_append_basic (&iter_sub_struct,DBUS_TYPE_UINT32 ,&(wb[i]->WBMintNode.nodeMode));

				dbus_message_iter_append_basic (&iter_sub_struct,DBUS_TYPE_UINT32 ,&(wb[i]->WBMintNode.linksCount));

				dbus_message_iter_append_basic (&iter_sub_struct,DBUS_TYPE_UINT32 ,&(wb[i]->WBMintNode.nodesCount));

				dbus_message_iter_append_basic (&iter_sub_struct,DBUS_TYPE_UINT32 ,&(wb[i]->WBMintNode.nodeInterfaceId));

				dbus_message_iter_append_basic (&iter_sub_struct,DBUS_TYPE_UINT32 ,&(wb[i]->WBMintNode.protocolEnabled));

				memset(name, 0, DEFAULT_LEN);
				strcpy(name, wb[i]->WBMintNode.nodeName);
				dbus_message_iter_append_basic (&iter_sub_struct,DBUS_TYPE_STRING ,&name);

				dbus_message_iter_append_basic (&iter_sub_struct,DBUS_TYPE_UINT32 ,&(wb[i]->WBMintNode.autoBitrateEnable));

				dbus_message_iter_append_basic (&iter_sub_struct,DBUS_TYPE_UINT32 ,&(wb[i]->WBMintNode.autoBitrateAddition));

				dbus_message_iter_append_basic (&iter_sub_struct,DBUS_TYPE_UINT32 ,&(wb[i]->WBMintNode.autoBitrateMinLevel));

				dbus_message_iter_append_basic (&iter_sub_struct,DBUS_TYPE_UINT32 ,&(wb[i]->WBMintNode.extraCost));

				dbus_message_iter_append_basic (&iter_sub_struct,DBUS_TYPE_UINT32 ,&(wb[i]->WBMintNode.fixedCost));

				dbus_message_iter_append_basic (&iter_sub_struct,DBUS_TYPE_UINT32 ,&(wb[i]->WBMintNode.nodeID));

				dbus_message_iter_append_basic (&iter_sub_struct,DBUS_TYPE_UINT32 ,&(wb[i]->WBMintNode.ampLow));

				dbus_message_iter_append_basic (&iter_sub_struct,DBUS_TYPE_UINT32 ,&(wb[i]->WBMintNode.ampHigh));

				dbus_message_iter_append_basic (&iter_sub_struct,DBUS_TYPE_UINT32 ,&(wb[i]->WBMintNode.authMode));

				dbus_message_iter_append_basic (&iter_sub_struct,DBUS_TYPE_UINT32 ,&(wb[i]->WBMintNode.authRelay));

				dbus_message_iter_append_basic (&iter_sub_struct,DBUS_TYPE_UINT32 ,&(wb[i]->WBMintNode.crypt));

				dbus_message_iter_append_basic (&iter_sub_struct,DBUS_TYPE_UINT32 ,&(wb[i]->WBMintNode.compress));

				dbus_message_iter_append_basic (&iter_sub_struct,DBUS_TYPE_UINT32 ,&(wb[i]->WBMintNode.overTheAirUpgradeEnable));

				dbus_message_iter_append_basic (&iter_sub_struct,DBUS_TYPE_UINT32 ,&(wb[i]->WBMintNode.overTheAirUpgradeSpeed));

				dbus_message_iter_append_basic (&iter_sub_struct,DBUS_TYPE_UINT32 ,&(wb[i]->WBMintNode.roaming));

				dbus_message_iter_append_basic (&iter_sub_struct,DBUS_TYPE_UINT32 ,&(wb[i]->WBMintNode.polling));

				dbus_message_iter_append_basic (&iter_sub_struct,DBUS_TYPE_UINT32 ,&(wb[i]->WBMintNode.mintBroadcastRate));

				dbus_message_iter_append_basic (&iter_sub_struct,DBUS_TYPE_UINT32 ,&(wb[i]->WBMintNode.noiseFloor));

				memset(name, 0, DEFAULT_LEN);
				strcpy(name, wb[i]->WBMintNode.secretKey);
				dbus_message_iter_append_basic (&iter_sub_struct,DBUS_TYPE_STRING ,&name);

		    	dbus_message_iter_close_container (&iter_sub_array, &iter_sub_struct);
			}
			dbus_message_iter_close_container (&iter_struct, &iter_sub_array);
			dbus_message_iter_close_container (&iter_array, &iter_struct);
		}
		dbus_message_iter_close_container (&iter, &iter_array);
		if(name)
			free(name);
	}
	
	return reply;	
}
Esempio n. 4
0
static int request_input(struct vpn_provider *provider,
			request_cb_t callback, const char *dbus_sender,
			void *user_data)
{
	DBusMessage *message;
	const char *path, *agent_sender, *agent_path;
	DBusMessageIter iter;
	DBusMessageIter dict;
	struct request_input_reply *l2tp_reply;
	int err;
	void *agent;

	agent = connman_agent_get_info(dbus_sender, &agent_sender,
							&agent_path);
	if (!provider || !agent || !agent_path || !callback)
		return -ESRCH;

	message = dbus_message_new_method_call(agent_sender, agent_path,
					VPN_AGENT_INTERFACE,
					"RequestInput");
	if (!message)
		return -ENOMEM;

	dbus_message_iter_init_append(message, &iter);

	path = vpn_provider_get_path(provider);
	dbus_message_iter_append_basic(&iter,
				DBUS_TYPE_OBJECT_PATH, &path);

	connman_dbus_dict_open(&iter, &dict);

	vpn_agent_append_user_info(&dict, provider, "L2TP.User");

	vpn_agent_append_host_and_name(&dict, provider);

	connman_dbus_dict_close(&iter, &dict);

	l2tp_reply = g_try_new0(struct request_input_reply, 1);
	if (!l2tp_reply) {
		dbus_message_unref(message);
		return -ENOMEM;
	}

	l2tp_reply->provider = provider;
	l2tp_reply->callback = callback;
	l2tp_reply->user_data = user_data;

	err = connman_agent_queue_message(provider, message,
			connman_timeout_input_request(),
			request_input_reply, l2tp_reply, agent);
	if (err < 0 && err != -EBUSY) {
		DBG("error %d sending agent request", err);
		dbus_message_unref(message);
		g_free(l2tp_reply);
		return err;
	}

	dbus_message_unref(message);

	return -EINPROGRESS;
}
Esempio n. 5
0
/**
 * 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" );

    /* 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 ) )
# if defined (WIN32) || defined (__APPLE__)
    /* Check if the user specified a custom language */
    char *lang = var_InheritString (p_libvlc, "language");
    if (lang != NULL && strcmp (lang, "auto"))
        SetLanguage (lang);
    free (lang);
# endif
    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
    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 */
            DBusMessage *p_test_msg   = NULL;
            DBusMessage *p_test_reply = NULL;

            p_test_msg =  dbus_message_new_method_call(
                    "org.mpris.MediaPlayer2.vlc", "/org/mpris/MediaPlayer2",
                    "org.freedesktop.DBus.Introspectable", "Introspect" );

            /* block until a reply arrives */
            p_test_reply = dbus_connection_send_with_reply_and_block(
                    p_conn, p_test_msg, -1, &dbus_error );
            dbus_message_unref( p_test_msg );
            if( p_test_reply == NULL )
            {
                dbus_error_free( &dbus_error );
                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;

                dbus_message_unref( p_test_reply );
                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 = make_URI( ppsz_argv[i_input], NULL );
                    const char *psz_after_track = "/";

                    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(
                        "org.mpris.MediaPlayer2.vlc", "/org/mpris/MediaPlayer2",
                        "org.mpris.MediaPlayer2.TrackList", "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 );
    }
#endif

    /*
     * 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) );
    /*
     * Choose the best memcpy module
     */
    priv->p_memcpy_module = module_need( p_libvlc, "memcpy", "$memcpy", false );
    /* Avoid being called "memcpy":*/
    vlc_object_set_name( p_libvlc, "main" );

    priv->b_stats = var_InheritBool( p_libvlc, "stats" );
    priv->i_timers = 0;
    priv->pp_timers = NULL;

    /*
     * 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" );
        if( priv->p_memcpy_module != NULL )
        {
            module_unneed( p_libvlc, priv->p_memcpy_module );
        }
        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" );

#ifdef HAVE_DBUS
    /* loads dbus control interface if in one-instance mode
     * we do it only when playlist exists, because dbus module needs it */
    if( var_InheritBool( p_libvlc, "one-instance" )
     || ( var_InheritBool( p_libvlc, "one-instance-when-started-from-file" )
       && var_InheritBool( p_libvlc, "started-from-file" ) ) )
        intf_Create( p_libvlc, "dbus,none" );

# if !defined (HAVE_MAEMO)
    /* Prevents the power management daemon from suspending the system
     * when VLC is active */
    if( var_InheritBool( p_libvlc, "inhibit" ) > 0 )
        intf_Create( p_libvlc, "inhibit,none" );
# endif
#endif

    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;
}
Esempio n. 6
0
static char *				/* O - Device path or NULL */
colord_find_device(
    const char *device_id)		/* I - Device ID string */
{
  DBusMessage	*message = NULL;	/* D-Bus request */
  DBusMessage	*reply = NULL;		/* D-Bus reply */
  DBusMessageIter args;			/* D-Bus method arguments */
  DBusError	error;			/* D-Bus error */
  const char	*device_path_tmp;	/* Device object path */
  char		*device_path = NULL;	/* Device object path */


  message = dbus_message_new_method_call(COLORD_DBUS_SERVICE,
                                         COLORD_DBUS_PATH,
                                         COLORD_DBUS_INTERFACE,
                                         "FindDeviceById");

  dbus_message_iter_init_append(message, &args);
  dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &device_id);

 /*
  * Send the FindDeviceById request synchronously...
  */

  dbus_error_init(&error);
  cupsdLogMessage(CUPSD_LOG_DEBUG, "Calling FindDeviceById(%s)", device_id);
  reply = dbus_connection_send_with_reply_and_block(colord_con, message,
                                                    COLORD_DBUS_TIMEOUT,
                                                    &error);
  if (!reply)
  {
    cupsdLogMessage(CUPSD_LOG_DEBUG, "FindDeviceById failed: %s:%s",
		    error.name, error.message);
    dbus_error_free(&error);
    goto out;
  }

 /*
  * Get reply data...
  */

  dbus_message_iter_init(reply, &args);
  if (dbus_message_iter_get_arg_type(&args) != DBUS_TYPE_OBJECT_PATH)
  {
    cupsdLogMessage(CUPSD_LOG_WARN,
                    "FindDeviceById failed: Incorrect reply type.");
    goto out;
  }

  dbus_message_iter_get_basic(&args, &device_path_tmp);
  if (device_path_tmp)
    device_path = strdup(device_path_tmp);

out:

  if (message)
    dbus_message_unref(message);

  if (reply)
    dbus_message_unref(reply);

  return (device_path);
}
Esempio n. 7
0
int sss_sudo_make_request(struct sudo_result_contents ** sudo_result_out)
{


    char ** command_array,**ui;
    int err_status,count;
    dbus_uint32_t header,command_array_out_size;
    struct sudo_result_contents * sudo_result = NULL;

    DBusConnection* conn;
    DBusError err;

    DBusMessage* dbus_msg;
    DBusMessage* dbus_reply;
    DBusMessageIter msg_iter;

    dbus_bool_t ret = -1;

    fprintf(stdout,"Sending message\n");

    if(validate_message_content() !=  SSS_SUDO_VALIDATION_SUCCESS) {
        return SSS_SUDO_VALIDATION_ERR;
    }


    err_status = create_env_hash_table(msg.user_env,&msg.env_table);
    if(err_status != HASH_SUCCESS) {
        fprintf(stderr, "ccouldn't create table: %s\n", hash_error_string(err_status));
        return SSS_SUDO_MESSAGE_ERR;
    }


    err_status = create_settings_hash_table(&msg.settings_table);
    if(err_status != HASH_SUCCESS) {
        fprintf(stderr, "ccouldn't create table: %s\n", hash_error_string(err_status));
        return SSS_SUDO_MESSAGE_ERR;
    }

    /* initialise the errors */
    dbus_error_init(&err);

    /* connect to the system bus and check for errors */
    conn = dbus_connection_open_private(SSS_SUDO_SERVICE_PIPE, &err);

    if (dbus_error_is_set(&err)) {
        fprintf(stderr, "Connection Error (%s)\n", err.message);
        dbus_error_free(&err);
        return SSS_SUDO_CONNECTION_ERR;
    }
    if (NULL == conn) {
        return SSS_SUDO_CONNECTION_ERR;
    }


    /* create a new method call and check for errors */
    dbus_msg = dbus_message_new_method_call( NULL, 		               /*    target    */
                                             SUDO_SERVER_PATH,        /*    object    */
                                             SUDO_SERVER_INTERFACE,  /*   interface  */
                                             SUDO_METHOD_QUERY);    /*  method name */
    if (NULL == dbus_msg) {
        fprintf(stderr, "Message Null\n");
        free_connection(conn,&err,msg.settings_table,(DBusMessage *)NULL,(DBusMessage *)NULL);
        return SSS_SUDO_MESSAGE_ERR;
    }

    /* append arguments */


    dbus_message_iter_init_append(dbus_msg, &msg_iter);
    if(dbus_error_is_set(&err)){
        fprintf(stderr, "Failed to initialize the iterator.\n");
        free_connection(conn,&err,msg.settings_table,dbus_msg,(DBusMessage *)NULL);
        return SSS_SUDO_MESSAGE_ERR;
    }

    ret = frame_sudo_message(conn,
                             &err,
                             dbus_msg,
                             &msg,
                             &msg_iter);
    if( ret != SSS_SUDO_MESSAGE_OK){
        sudo_log(SUDO_CONV_ERROR_MSG,"Failed to frame the message to sssd -  Fatal (Access denied)\n");
        free_connection(conn,&err,(hash_table_t *)NULL,dbus_msg,(DBusMessage *)NULL);
        return SSS_SUDO_MESSAGE_ERR;
    }

    /* send message and get a handle for a reply */
    dbus_reply = dbus_connection_send_with_reply_and_block (conn,dbus_msg,
                                                            SUDO_CLIENT_TIMEOUT,
                                                            &err);
    fprintf(stdout,"Request Sent\n");
    if (dbus_error_is_set(&err)) {
        fprintf(stderr, "Connection send-reply Error (%s)\n", err.message);
        free_connection(conn,&err,(hash_table_t *)NULL,dbus_msg,(DBusMessage *)NULL);
        return SSS_SUDO_REPLY_ERR;
    }
    if (NULL == dbus_reply) {
        fprintf(stderr, "reply failed\n");
        free_connection(conn,&err,(hash_table_t *)NULL,dbus_msg,(DBusMessage *)NULL);
        return SSS_SUDO_REPLY_ERR;
    }
    sudo_result= (struct sudo_result_contents *)malloc(sizeof(struct sudo_result_contents));

    ret = get_reply_message(conn,
                            &err,
                            dbus_msg,
                            dbus_reply,
                            sudo_result,
                            &msg_iter);
    if(ret != SSS_SUDO_REPLY_OK){

    }

    /* free connection now */
    free_connection(conn,&err,(hash_table_t *)NULL,dbus_msg,dbus_reply);
    *sudo_result_out = sudo_result;
    return SSS_SUDO_SEND_AND_RECIEVE_OK;
}
Esempio n. 8
0
static gboolean
dbus_client_query_end_session (GsmClient                *client,
                               GsmClientEndSessionFlag   flags,
                               GError                  **error)
{
        GsmDBusClient  *dbus_client = (GsmDBusClient *) client;
        DBusMessage    *message;
        DBusMessageIter iter;
        gboolean        ret;

        ret = FALSE;

        if (dbus_client->priv->bus_name == NULL) {
                g_set_error (error,
                             GSM_CLIENT_ERROR,
                             GSM_CLIENT_ERROR_NOT_REGISTERED,
                             "Client is not registered");
                return FALSE;
        }

        g_debug ("GsmDBusClient: sending QueryEndSession signal to %s", dbus_client->priv->bus_name);

        /* unicast the signal to only the registered bus name */
        message = dbus_message_new_signal (gsm_client_peek_id (client),
                                           SM_DBUS_CLIENT_PRIVATE_INTERFACE,
                                           "QueryEndSession");
        if (message == NULL) {
                g_set_error (error,
                             GSM_CLIENT_ERROR,
                             GSM_CLIENT_ERROR_NOT_REGISTERED,
                             "Unable to send QueryEndSession message");
                goto out;
        }
        if (!dbus_message_set_destination (message, dbus_client->priv->bus_name)) {
                g_set_error (error,
                             GSM_CLIENT_ERROR,
                             GSM_CLIENT_ERROR_NOT_REGISTERED,
                             "Unable to send QueryEndSession message");
                goto out;
        }

        dbus_message_iter_init_append (message, &iter);
        dbus_message_iter_append_basic (&iter, DBUS_TYPE_UINT32, &flags);

        if (!dbus_connection_send (dbus_client->priv->connection, message, NULL)) {
                g_set_error (error,
                             GSM_CLIENT_ERROR,
                             GSM_CLIENT_ERROR_NOT_REGISTERED,
                             "Unable to send QueryEndSession message");
                goto out;
        }

        ret = TRUE;

 out:
        if (message != NULL) {
                dbus_message_unref (message);
        }

        return ret;
}
Esempio n. 9
0
File: csl.c Progetto: Tayyib/uludag
//! CSL method: call(app, model, method, (arg0, arg1, ...))
static PyObject *
c_call(PyObject *self, PyObject *args)
{
    /*!
     * This method can be used in CSL scripts to call Comar methods
     * internally.
     *
     * @return Called method's reply
     */

    PyObject *ret, *tuple = NULL;
    char *app, *model, *method, *interface, *path;
    int size, i;

    if (!PyArg_ParseTuple(args, "sss|O", &app, &model, &method, &tuple))
        return NULL;


    if (!tuple) {
        tuple = PyTuple_New(0);
    }

    DBusConnection *conn;
    DBusError err;
    DBusMessage *msg, *reply;
    DBusMessageIter iter;

    dbus_error_init(&err);
    conn = dbus_bus_get_private(DBUS_BUS_SYSTEM, &err);
    if (dbus_error_is_set(&err)) {
        PyErr_SetString(PyExc_Exception, "Unable to open connection for call() method.");
        dbus_error_free(&err);
        return NULL;
    }

    size = strlen(cfg_bus_interface) + 1 + strlen(model) + 1;
    interface = malloc(size);
    snprintf(interface, size, "%s.%s", cfg_bus_interface, model);
    interface[size - 1] = '\0';

    size = strlen("/package/") + strlen(app) + 1;
    path = malloc(size);
    snprintf(path, size, "/package/%s", app);
    path[size - 1] = '\0';

    msg = dbus_message_new_method_call(cfg_bus_name, path, interface, method);
    free(interface);
    free(path);

    dbus_message_iter_init_append(msg, &iter);

    if (PyTuple_Check(tuple)) {
        if (PyTuple_Size(tuple) > 0) {
            for (i = 0; i < PyTuple_Size(tuple); i++) {
                if (dbus_py_export(&iter, PyTuple_GetItem(tuple, i)) != 0) {
                    return NULL;
                }
            }
        }
    }
    else {
        if (dbus_py_export(&iter, tuple) != 0) {
            return NULL;
        }
    }

    reply = dbus_connection_send_with_reply_and_block(conn, msg, -1, &err);
    dbus_message_unref(msg);
    dbus_connection_close(conn);
    dbus_connection_unref(conn);
    if (dbus_error_is_set(&err)) {
        PyErr_Format(PyExc_Exception, "Unable to call method: %s", err.message);
        dbus_error_free(&err);
        return NULL;
    }

    switch (dbus_message_get_type(reply)) {
        case DBUS_MESSAGE_TYPE_METHOD_RETURN:
            ret = PyList_AsTuple(dbus_py_import(reply));
            if (PyTuple_Size(ret) == 1) {
                ret = PyTuple_GetItem(ret, 0);
            }
            dbus_message_unref(reply);
            return ret;
        case DBUS_MESSAGE_TYPE_ERROR:
            PyErr_SetString(PyExc_Exception, dbus_message_get_error_name(reply));
            dbus_message_unref(reply);
            return NULL;
    }

    Py_INCREF(Py_None);
    return Py_None;
}
Esempio n. 10
0
void broadcast_and_wait_response(char* server_name) {
	DBusMessage* msg;
	DBusMessageIter args;
	DBusConnection* conn;
	DBusError err;
	DBusPendingCall* pending;
	int ret;
	char *stat;
	dbus_uint32_t level;

//	printf("broadcast_and_wait_response-----Calling remote method\n");
	// initialiset the errors

	dbus_error_init(&err);

	// connect to the system bus and check for errors
	conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
	if (dbus_error_is_set(&err)) {
		fprintf(stderr, "Connection Error (%s)\n", err.message);
		dbus_error_free(&err);
	}
	if (NULL == conn) {
		exit(1);
	}

	// request our name on the bus
	ret = dbus_bus_request_name(conn, "test.method.caller", DBUS_NAME_FLAG_REPLACE_EXISTING, &err);
	if (dbus_error_is_set(&err)) {
		fprintf(stderr, "Name Error (%s)\n", err.message);
		dbus_error_free(&err);
	}
	if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) {
		exit(1);
	}

	char name_[50];
	sprintf(name_,"test.method.%s",server_name);
	// create a new method call and check for errors
	msg = dbus_message_new_method_call(name_, // target for the method call
			"/test/method/Object", // object to call on
			"test.method.Type", // interface to call on
			"Method"); // method name
	if (NULL == msg) {
		fprintf(stderr, "Message Null\n");
		exit(1);
	}

	char *param = "hello hanmeimei..";
	// append arguments
	dbus_message_iter_init_append(msg, &args);
	if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &param)) {
		fprintf(stderr, "Out Of Memory!\n");
		exit(1);
	}

	// send message and get a handle for a reply
	if (!dbus_connection_send_with_reply(conn, msg, &pending, -1)) { // -1 is default timeout
		fprintf(stderr, "Out Of Memory!\n");
		exit(1);
	}
	if (NULL == pending) {
		fprintf(stderr, "Pending Call Null\n");
		exit(1);
	}
	dbus_connection_flush(conn);

	// free message
	dbus_message_unref(msg);

//	printf("broadcast_and_wait_response-----...............wait........\n");

	// block until we recieve a reply
	dbus_pending_call_block(pending);

//	printf("broadcast_and_wait_response-----now reply........come in..\n");

	// get the reply message
	msg = dbus_pending_call_steal_reply(pending);
	if (NULL == msg) {
		fprintf(stderr, "Reply Null\n");
		exit(1);
	}
	// free the pending message handle
	dbus_pending_call_unref(pending);

	stat = (char*)malloc(128);
	// read the parameters
	if (!dbus_message_iter_init(msg, &args))
		fprintf(stderr, "Message has no arguments!\n");
	else if (DBUS_TYPE_STRING != dbus_message_iter_get_arg_type(&args))
		fprintf(stderr, "Argument is not string!\n");
	else
		dbus_message_iter_get_basic(&args, &stat);

	if (!dbus_message_iter_next(&args))
		fprintf(stderr, "Message has too few arguments!\n");
	else if (DBUS_TYPE_UINT32 != dbus_message_iter_get_arg_type(&args))
		fprintf(stderr, "Argument is not int!\n");
	else
		dbus_message_iter_get_basic(&args, &level);

//	printf("broadcast_and_wait_response----Got Reply: %s, %d\n", stat, level);
	printf("%s, %d\n", stat, level);

	// free reply and close connection
	dbus_message_unref(msg);
//	dbus_connection_close(conn);
}
Esempio n. 11
0
VIR_MOCK_IMPL_RET_ARGS(dbus_connection_send_with_reply_and_block,
                       DBusMessage *,
                       DBusConnection *, connection,
                       DBusMessage *, message,
                       int, timeout_milliseconds,
                       DBusError *, error)
{
    DBusMessage *reply = NULL;
    const char *service = dbus_message_get_destination(message);
    const char *member = dbus_message_get_member(message);

    VIR_MOCK_IMPL_INIT_REAL(dbus_connection_send_with_reply_and_block);

    if (STREQ(service, "org.freedesktop.machine1")) {
        if (getenv("FAIL_BAD_SERVICE")) {
            dbus_set_error_const(error,
                                 "org.freedesktop.systemd.badthing",
                                 "Something went wrong creating the machine");
        } else {
            reply = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_RETURN);
        }
    } else if (STREQ(service, "org.freedesktop.login1")) {
        char *supported = getenv("RESULT_SUPPORT");
        DBusMessageIter iter;
        reply = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_RETURN);
        dbus_message_iter_init_append(reply, &iter);

        if (!dbus_message_iter_append_basic(&iter,
                                            DBUS_TYPE_STRING,
                                            &supported))
            goto error;
    } else if (STREQ(service, "org.freedesktop.DBus") &&
               STREQ(member, "ListActivatableNames")) {
        const char *svc1 = "org.foo.bar.wizz";
        const char *svc2 = "org.freedesktop.machine1";
        const char *svc3 = "org.freedesktop.login1";
        DBusMessageIter iter;
        DBusMessageIter sub;
        reply = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_RETURN);
        dbus_message_iter_init_append(reply, &iter);
        dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
                                         "s", &sub);

        if (!dbus_message_iter_append_basic(&sub,
                                            DBUS_TYPE_STRING,
                                            &svc1))
            goto error;
        if (!getenv("FAIL_NO_SERVICE") &&
            !dbus_message_iter_append_basic(&sub,
                                            DBUS_TYPE_STRING,
                                            &svc2))
            goto error;
        if (!getenv("FAIL_NO_SERVICE") &&
            !dbus_message_iter_append_basic(&sub,
                                            DBUS_TYPE_STRING,
                                            &svc3))
            goto error;
        dbus_message_iter_close_container(&iter, &sub);
    } else if (STREQ(service, "org.freedesktop.DBus") &&
               STREQ(member, "ListNames")) {
        const char *svc1 = "org.foo.bar.wizz";
        const char *svc2 = "org.freedesktop.systemd1";
        const char *svc3 = "org.freedesktop.login1";
        DBusMessageIter iter;
        DBusMessageIter sub;
        reply = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_RETURN);
        dbus_message_iter_init_append(reply, &iter);
        dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
                                         "s", &sub);

        if (!dbus_message_iter_append_basic(&sub,
                                            DBUS_TYPE_STRING,
                                            &svc1))
            goto error;
        if ((!getenv("FAIL_NO_SERVICE") && !getenv("FAIL_NOT_REGISTERED")) &&
            !dbus_message_iter_append_basic(&sub,
                                            DBUS_TYPE_STRING,
                                            &svc2))
            goto error;
        if ((!getenv("FAIL_NO_SERVICE") && !getenv("FAIL_NOT_REGISTERED")) &&
            !dbus_message_iter_append_basic(&sub,
                                            DBUS_TYPE_STRING,
                                            &svc3))
            goto error;
        dbus_message_iter_close_container(&iter, &sub);
    } else {
        reply = dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_RETURN);
    }

    return reply;

 error:
    dbus_message_unref(reply);
    return NULL;
}
Esempio n. 12
0
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);
                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);
            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) {
        operation_finalize(op);
        return TRUE;
    }
    return op->rc == PCMK_OCF_OK;
}
Esempio n. 13
0
bool CHALManager::Mount(CStorageDevice *volume, CStdString mountpath)
{
  CLog::Log(LOGNOTICE, "HAL: Mounting %s (%s) at %s with umask=%u", volume->UDI.c_str(), volume->toString().c_str(), mountpath.c_str(), umask (0));
  DBusMessage* msg;
  DBusMessageIter args;
  DBusError error;
  dbus_error_init (&error);
  DBusConnection *connection = dbus_bus_get (DBUS_BUS_SYSTEM, &error);
  const char *s;
  if (connection)
  {
    msg = dbus_message_new_method_call("org.freedesktop.Hal", volume->UDI.c_str(), "org.freedesktop.Hal.Device.Volume", "Mount");
    dbus_message_iter_init_append(msg, &args);
    s = mountpath.c_str();
    if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &s))
      CLog::Log(LOGERROR, "DBus: Failed to append arguments");
    s = ""; //FileSystem
    if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &s))
      CLog::Log(LOGERROR, "DBus: Failed to append arguments");
    DBusMessageIter sub;
    dbus_message_iter_open_container(&args, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &sub);

    CStdString temporaryString;

    if (volume->FileSystem.Equals("vfat"))
    {
      int mask = umask (0);
      temporaryString.Format("umask=%#o", mask);
      s = temporaryString.c_str();
      dbus_message_iter_append_basic(&sub, DBUS_TYPE_STRING, &s);
      temporaryString.Format("uid=%u", getuid());
      s = temporaryString.c_str();
      dbus_message_iter_append_basic(&sub, DBUS_TYPE_STRING, &s);
      s = "shortname=mixed";
      dbus_message_iter_append_basic(&sub, DBUS_TYPE_STRING, &s);
      s = "utf8";
      dbus_message_iter_append_basic(&sub, DBUS_TYPE_STRING, &s);
      // 'sync' option will slow down transfer speed significantly for FAT filesystems. We prefer 'flush' instead.
      s = "flush";
      dbus_message_iter_append_basic(&sub, DBUS_TYPE_STRING, &s);
    }
    else
    {
      s = "sync";
      dbus_message_iter_append_basic(&sub, DBUS_TYPE_STRING, &s);
    }

    dbus_message_iter_close_container(&args, &sub);

    if (msg == NULL)
        CLog::Log(LOGERROR, "DBus: Create Mount Message failed");
    else
    {
      DBusMessage *reply;
      reply = dbus_connection_send_with_reply_and_block(connection, msg, -1, &error); //The reply timout might be bad to have as -1
      if (dbus_error_is_set(&error))
      {
        CLog::Log(LOGERROR, "DBus: %s - %s", error.name, error.message);
        dbus_error_free(&error);
        return false;
      }
      // Need to create a reader for the Message
      dbus_message_unref (reply);
      dbus_message_unref(msg);
      msg = NULL;
    }

    volume->Mounted = true;
    volume->MountedByXBMC = true;
    volume->MountPoint = mountpath;
    dbus_connection_unref(connection);
    connection = NULL;
    return true;
  }
  else
  {
    CLog::Log(LOGERROR, "DBus: Failed to connect to Systembus");
    dbus_error_free(&error);
    return false;
  }
}
Esempio n. 14
0
/**
 * Creates the HealthApplication's by calling BlueZ
 *
 * @param is_sink TRUE if data type is Sink role
 * @param data_type Specialization or data type 
 */
gboolean create_health_application(gboolean is_sink, guint16 data_type)
{
	/* Create HealthApplication */

	// Need to use non-GLib code here because GLib still does not have
	// the G_TYPE_UINT16 type.

	DBusMessage *msg, *reply;
	DBusError err;
	DBusMessageIter iter, array, entry, variant;
	guint16 value;
	const char *svalue;
	const char *key;
	char *app_path;
	app_object *app;

	msg = dbus_message_new_method_call("org.bluez", "/org/bluez",
					   "org.bluez.HealthManager", "CreateApplication");

	if (!msg) {
		DEBUG(" network:dbus Can't allocate new method call");
		return FALSE;
	}

	dbus_message_iter_init_append(msg, &iter);
	dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "{sv}", &array);

	key = "DataType";
	value = data_type;
	dbus_message_iter_open_container(&array, DBUS_TYPE_DICT_ENTRY, NULL, &entry);
	dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
	dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT, "q", &variant);
	dbus_message_iter_append_basic(&variant, DBUS_TYPE_UINT16, &value);
	dbus_message_iter_close_container(&entry, &variant);
	dbus_message_iter_close_container(&array, &entry);

	key = "Role";
	svalue = (is_sink ? "Sink" : "Source");
	dbus_message_iter_open_container(&array, DBUS_TYPE_DICT_ENTRY, NULL, &entry);
	dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
	dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT, "s", &variant);
	dbus_message_iter_append_basic(&variant, DBUS_TYPE_STRING, &svalue);
	dbus_message_iter_close_container(&entry, &variant);
	dbus_message_iter_close_container(&array, &entry);

	key = "Description";
	svalue = "healthd";
	dbus_message_iter_open_container(&array, DBUS_TYPE_DICT_ENTRY, NULL, &entry);
	dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
	dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT, "s", &variant);
	dbus_message_iter_append_basic(&variant, DBUS_TYPE_STRING, &svalue);
	dbus_message_iter_close_container(&entry, &variant);
	dbus_message_iter_close_container(&array, &entry);

	dbus_message_iter_close_container(&iter, &array);

	dbus_error_init(&err);

	reply = dbus_connection_send_with_reply_and_block(
			dbus_g_connection_get_connection(conn),
			msg, -1, &err);

	dbus_message_unref(msg);

	if (!reply) {
		DEBUG(" network:dbus Can't create application");

		if (dbus_error_is_set(&err)) {
			ERROR("%s", err.message);
			dbus_error_free(&err);
		}

		return FALSE;
	}

	if (!dbus_message_get_args(reply, &err,
				   DBUS_TYPE_OBJECT_PATH, &app_path,
				   DBUS_TYPE_INVALID)) {
		DEBUG(" network:dbus Can't get reply arguments");

		if (dbus_error_is_set(&err)) {
			ERROR("%s", err.message);
			dbus_error_free(&err);
		}

		return FALSE;
	}

	app = g_new0(app_object, 1);
	app->path = g_strdup(app_path);
	app->data_type = data_type;
	app->is_sink = is_sink;

	llist_add(apps(), app);

	dbus_message_unref(reply);

	DEBUG("Created health application: %s", (char *) app->path);

	return TRUE;
}
Esempio n. 15
0
void
gconf_database_dbus_notify_listeners (GConfDatabase    *db,
				      GConfSources     *modified_sources,
				      const gchar      *key,
				      const GConfValue *value,
				      gboolean          is_default,
				      gboolean          is_writable,
				      gboolean          notify_others)
{
  char             *dir, *sep;
  GList            *l;
  NotificationData *notification;
  DBusMessage      *message;
  gboolean          last;
  
  dir = g_strdup (key);

  /* Lookup the key in the namespace hierarchy, start with the full key and then
   * remove the leaf, lookup again, remove the leaf, and so on until a match is
   * found. Notify the clients (identified by their base service) that
   * correspond to the found namespace.
   */
  last = FALSE;
  while (1)
    {
      notification = g_hash_table_lookup (db->notifications, dir);

      if (notification)
	{
	  for (l = notification->clients; l; l = l->next)
	    {
	      const char *base_service = l->data;
	      DBusMessageIter iter;
	      
	      message = dbus_message_new_method_call (base_service,
						      GCONF_DBUS_CLIENT_OBJECT,
						      GCONF_DBUS_CLIENT_INTERFACE,
						      "Notify");

	      dbus_message_append_args (message,
					DBUS_TYPE_STRING, &db->object_path,
					DBUS_TYPE_STRING, &dir,
					DBUS_TYPE_INVALID);

	      dbus_message_iter_init_append (message, &iter);
	      
	      gconf_dbus_utils_append_entry_values (&iter,
						    key,
						    value,
						    is_default,
						    is_writable,
						    NULL);
	      
	      dbus_message_set_no_reply (message, TRUE);
	      
	      dbus_connection_send (gconfd_dbus_get_connection (), message, NULL);
	      dbus_message_unref (message);
	    }
	}

      if (last)
	break;
      
      sep = strrchr (dir, '/');

      /* Special case to catch notifications on the root. */
      if (sep == dir)
	{
	  last = TRUE;
	  sep[1] = '\0';
	}
      else
	*sep = '\0';
    }

    
  g_free (dir);

  if (modified_sources)
    {
      if (notify_others)
        gconfd_notify_other_listeners (db, modified_sources, key);

      g_list_free (modified_sources->sources);
      g_free (modified_sources);
    }
}
Esempio n. 16
0
/*****************************************************
** DISCRIPTION:
**          copy file of the specific path from slotA to slotB
** INPUT:
**          
** OUTPUT:
**          
** RETURN:
**          
** CREATOR:
**          <*****@*****.**>
** DATE:
**          2011-08-11
*****************************************************/
DBusMessage * bsd_copy_files_between_boards(DBusConnection *conn, DBusMessage *msg, void *user_data){

    DBusMessage* reply;
    DBusMessageIter  iter;
    DBusError err;
    int ret = BSD_DBUS_SUCCESS;
    unsigned int slotid = 0;
    int tar_switch = 0;
    char *src_path = NULL;
    char *des_path = NULL;
    int op = 0;
    DIR *source = NULL;
    int curr_event_id = 0;
    char *tmp_md5 = NULL;
    int len = 0;
    dbus_error_init(&err);
    if (!(dbus_message_get_args ( msg, &err,
                             DBUS_TYPE_UINT32,&slotid,
                             DBUS_TYPE_STRING,&src_path,
                             DBUS_TYPE_STRING,&des_path,
                             DBUS_TYPE_UINT32,&tar_switch,   //book add, 2011-08-16
                             DBUS_TYPE_UINT32,&op,  //book add, 2011-10-26
                             DBUS_TYPE_INVALID))) {
        bsd_syslog_err("copy files between boards:Unable to get input args ");
        if (dbus_error_is_set(&err)) {
            bsd_syslog_err("copy files failed %s raised: %s",err.name,err.message);
            dbus_error_free(&err);
        }
        return NULL;
    }

    if((ret != 0) && (BSD_BOARD[slotid]->state != BSD_FILE_UNKNOWN)) {
        BSD_BOARD[slotid]->state = BSD_FILE_UNKNOWN;
    }
    else {
        source = opendir(src_path);
        if(source == NULL) {    // copy single file
            if(op == BSD_TYPE_NORMAL)
                op = BSD_TYPE_SINGLE;
            
            if(g_unEventId == MAX_EVENT_ID) 
                g_unEventId = 0;
            g_unEventId++;
            curr_event_id = g_unEventId;
            bsd_syslog_debug_debug(BSD_DEFAULT, "111 op = %d, slotid = %d, src_path = %s, des_path = %s\n",op,slotid,src_path,des_path);
            ret = BSDHandleFileOp(slotid, src_path, des_path, op, curr_event_id);
            tarFlag = 0;
            
        } else {// copy folder
            bsd_syslog_debug_debug(BSD_DEFAULT, "copy other files\n");
            tarFlag = tar_switch;
            ret = BSDCopyFile(slotid, src_path, des_path, op);
            tarFlag = 0;
            closedir(source);
        }
        if((ret != 0) && (BSD_BOARD[slotid]->state != BSD_FILE_UNKNOWN)) {
            BSD_BOARD[slotid]->state = BSD_FILE_UNKNOWN;
        }
    }
    
    /* add for AXSSZFI-1563 */
    len = strnlen(g_rePrintMd5, BSD_PATH_LEN);
    //bsd_syslog_debug_debug(BSD_DEFAULT, "g_rePrintMd5 len = %d", len);
    if(len > 0) {
        tmp_md5 = (char*)malloc(len+1);
        memset(tmp_md5, 0, len+1);
        memcpy(tmp_md5, g_rePrintMd5, len);
		memset(g_rePrintMd5, 0, BSD_PATH_LEN);
    }
    else {
        tmp_md5 = (char*)malloc(5);
        memset(tmp_md5, 0, 5);
        strcpy(tmp_md5, "none");
    }
    
    bsd_syslog_debug_debug(BSD_DEFAULT, "ret = %d\n", ret);
    reply = dbus_message_new_method_return(msg);
    
    if(NULL == reply) {
        bsd_syslog_err("vrrp set hansi profile dbus reply null!\n");
        return reply;
    }
    
    dbus_message_iter_init_append (reply, &iter);
    dbus_message_iter_append_basic (&iter,DBUS_TYPE_UINT32,&ret);
    dbus_message_iter_append_basic (&iter,DBUS_TYPE_STRING,&tmp_md5);
    
    if(tmp_md5 != NULL) {
        free(tmp_md5);
        tmp_md5 = NULL;
    }
    return reply;
    
}
Esempio n. 17
0
static void
colord_create_profile(
    cups_array_t *profiles,		/* I - Profiles array */
    const char   *printer_name,		/* I - Printer name */
    const char   *qualifier,		/* I - Profile qualifier */
    const char   *colorspace,		/* I - Profile colorspace */
    char         **format,		/* I - Profile qualifier format */
    const char   *iccfile,		/* I - ICC filename */
    const char   *scope)		/* I - The scope of the profile, e.g.
				               'normal', 'temp' or 'disk' */
{
  DBusMessage	*message = NULL;        /* D-Bus request */
  DBusMessage	*reply = NULL;          /* D-Bus reply */
  DBusMessageIter args;			/* D-Bus method arguments */
  DBusMessageIter dict;			/* D-Bus method arguments */
  DBusError	error;			/* D-Bus error */
  char		*idstr;			/* Profile ID string */
  size_t	idstrlen;		/* Profile ID allocated length */
  const char	*profile_path;		/* Device object path */
  char		format_str[1024];	/* Qualifier format as a string */


 /*
  * Create the profile...
  */

  message = dbus_message_new_method_call(COLORD_DBUS_SERVICE,
                                         COLORD_DBUS_PATH,
                                         COLORD_DBUS_INTERFACE,
                                         "CreateProfile");

  idstrlen = strlen(printer_name) + 1 + strlen(qualifier) + 1;
  if ((idstr = malloc(idstrlen)) == NULL)
    goto out;
  snprintf(idstr, idstrlen, "%s-%s", printer_name, qualifier);
  cupsdLogMessage(CUPSD_LOG_DEBUG, "Using profile ID \"%s\".", idstr);

  dbus_message_iter_init_append(message, &args);
  dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &idstr);
  dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &scope);

  snprintf(format_str, sizeof(format_str), "%s.%s.%s", format[0], format[1],
           format[2]);

  dbus_message_iter_open_container(&args, DBUS_TYPE_ARRAY, "{ss}", &dict);
  colord_dict_add_strings(&dict, "Qualifier", qualifier);
  colord_dict_add_strings(&dict, "Format", format_str);
  colord_dict_add_strings(&dict, "Colorspace", colorspace);
  if (iccfile)
    colord_dict_add_strings(&dict, "Filename", iccfile);
  dbus_message_iter_close_container(&args, &dict);

 /*
  * Send the CreateProfile request synchronously...
  */

  dbus_error_init(&error);
  cupsdLogMessage(CUPSD_LOG_DEBUG, "Calling CreateProfile(%s,%s)", idstr,
                  scope);
  reply = dbus_connection_send_with_reply_and_block(colord_con, message,
                                                    COLORD_DBUS_TIMEOUT,
                                                    &error);
  if (!reply)
  {
    cupsdLogMessage(CUPSD_LOG_WARN, "CreateProfile failed: %s:%s", error.name,
                    error.message);
    dbus_error_free(&error);
    goto out;
  }

 /*
  * Get reply data...
  */

  dbus_message_iter_init(reply, &args);
  if (dbus_message_iter_get_arg_type(&args) != DBUS_TYPE_OBJECT_PATH)
  {
    cupsdLogMessage(CUPSD_LOG_WARN,
                    "CreateProfile failed: Incorrect reply type.");
    goto out;
  }

  dbus_message_iter_get_basic(&args, &profile_path);
  cupsdLogMessage(CUPSD_LOG_DEBUG, "Created profile \"%s\".", profile_path);
  cupsArrayAdd(profiles, strdup(profile_path));

out:

  if (message)
    dbus_message_unref(message);

  if (reply)
    dbus_message_unref(reply);

  if (idstr)
    free(idstr);
}
int
my_method_sync (const void *   parent,
                NihDBusProxy * proxy,
                const int32_t *value,
                size_t         value_len)
{
	DBusMessage *   method_call;
	DBusMessageIter iter;
	DBusError       error;
	DBusMessage *   reply;
	DBusMessageIter value_iter;

	nih_assert (proxy != NULL);
	nih_assert ((value_len == 0) || (value != NULL));

	/* Construct the method call message. */
	method_call = dbus_message_new_method_call (proxy->name, proxy->path, "com.netsplit.Nih.Test", "Method");
	if (! method_call)
		nih_return_no_memory_error (-1);

	dbus_message_set_auto_start (method_call, proxy->auto_start);

	dbus_message_iter_init_append (method_call, &iter);

	/* Marshal an array onto the message */
	if (! dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, "i", &value_iter)) {
		dbus_message_unref (method_call);
		nih_return_no_memory_error (-1);
	}

	for (size_t value_i = 0; value_i < value_len; value_i++) {
		int32_t value_element;

		value_element = value[value_i];

		/* Marshal a int32_t onto the message */
		if (! dbus_message_iter_append_basic (&value_iter, DBUS_TYPE_INT32, &value_element)) {
			dbus_message_iter_abandon_container (&iter, &value_iter);
			dbus_message_unref (method_call);
			nih_return_no_memory_error (-1);
		}
	}

	if (! dbus_message_iter_close_container (&iter, &value_iter)) {
		dbus_message_unref (method_call);
		nih_return_no_memory_error (-1);
	}

	/* Send the message, and wait for the reply. */
	dbus_error_init (&error);

	reply = dbus_connection_send_with_reply_and_block (proxy->connection, method_call, -1, &error);
	if (! reply) {
		dbus_message_unref (method_call);

		if (dbus_error_has_name (&error, DBUS_ERROR_NO_MEMORY)) {
			nih_error_raise_no_memory ();
		} else {
			nih_dbus_error_raise (error.name, error.message);
		}

		dbus_error_free (&error);
		return -1;
	}

	dbus_message_unref (method_call);

	/* Iterate the arguments of the reply */
	dbus_message_iter_init (reply, &iter);

	if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_INVALID) {
		dbus_message_unref (reply);
		nih_return_error (-1, NIH_DBUS_INVALID_ARGS,
		                  _(NIH_DBUS_INVALID_ARGS_STR));
	}

	dbus_message_unref (reply);

	return 0;
}
Esempio n. 19
0
static void
colord_create_device(
    cupsd_printer_t *p,			/* I - Printer */
    ppd_file_t      *ppd,		/* I - PPD file */
    cups_array_t    *profiles,		/* I - Profiles array */
    const char      *colorspace,	/* I - Device colorspace, e.g. 'rgb' */
    char            **format,		/* I - Device qualifier format */
    const char      *relation,		/* I - Profile relation, either 'soft'
					       or 'hard' */
    const char      *scope)		/* I - The scope of the device, e.g.
					       'normal', 'temp' or 'disk' */
{
  DBusMessage	*message = NULL;	/* D-Bus request */
  DBusMessage	*reply = NULL;		/* D-Bus reply */
  DBusMessageIter args;			/* D-Bus method arguments */
  DBusMessageIter dict;			/* D-Bus method arguments */
  DBusError	error;			/* D-Bus error */
  const char	*device_path;		/* Device object path */
  const char	*profile_path;		/* Profile path */
  char		*default_profile_path = NULL;
					/* Default profile path */
  char		device_id[1024];	/* Device ID as understood by colord */
  char		format_str[1024];	/* Qualifier format as a string */


 /*
  * Create the device...
  */

  snprintf(device_id, sizeof(device_id), "cups-%s", p->name);
  device_path = device_id;

  message = dbus_message_new_method_call(COLORD_DBUS_SERVICE,
                                         COLORD_DBUS_PATH,
                                         COLORD_DBUS_INTERFACE,
                                         "CreateDevice");

  dbus_message_iter_init_append(message, &args);
  dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &device_path);
  dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &scope);

  snprintf(format_str, sizeof(format_str), "%s.%s.%s", format[0], format[1],
           format[2]);

  dbus_message_iter_open_container(&args, DBUS_TYPE_ARRAY, "{ss}", &dict);
  colord_dict_add_strings(&dict, "Colorspace", colorspace);
  colord_dict_add_strings(&dict, "Mode", COLORD_MODE_PHYSICAL);
  if (ppd->manufacturer)
    colord_dict_add_strings(&dict, "Vendor", ppd->manufacturer);
  if (ppd->modelname)
    colord_dict_add_strings(&dict, "Model", ppd->modelname);
  if (p->sanitized_device_uri)
    colord_dict_add_strings(&dict, "Serial", p->sanitized_device_uri);
  colord_dict_add_strings(&dict, "Format", format_str);
  colord_dict_add_strings(&dict, "Kind", COLORD_KIND_PRINTER);
  dbus_message_iter_close_container(&args, &dict);

 /*
  * Send the CreateDevice request synchronously...
  */

  dbus_error_init(&error);
  cupsdLogMessage(CUPSD_LOG_DEBUG, "Calling CreateDevice(%s,%s)", device_id,
                  scope);
  reply = dbus_connection_send_with_reply_and_block(colord_con, message,
                                                    COLORD_DBUS_TIMEOUT,
                                                    &error);
  if (!reply)
  {
    cupsdLogMessage(CUPSD_LOG_WARN, "CreateDevice failed: %s:%s", error.name,
                    error.message);
    dbus_error_free(&error);
    goto out;
  }

 /*
  * Get reply data...
  */

  dbus_message_iter_init(reply, &args);
  if (dbus_message_iter_get_arg_type(&args) != DBUS_TYPE_OBJECT_PATH)
  {
    cupsdLogMessage(CUPSD_LOG_WARN,
                    "CreateDevice failed: Incorrect reply type.");
    goto out;
  }

  dbus_message_iter_get_basic(&args, &device_path);
  cupsdLogMessage(CUPSD_LOG_DEBUG, "Created device \"%s\".", device_path);

 /*
  * Add profiles...
  */

  for (profile_path = cupsArrayFirst(profiles);
       profile_path;
       profile_path = cupsArrayNext(profiles))
  {
    colord_device_add_profile(device_path, profile_path, relation);
  }

out:

  if (default_profile_path)
    free(default_profile_path);

  if (message)
    dbus_message_unref(message);

  if (reply)
    dbus_message_unref(reply);
}
static dbus_bool_t
bus_driver_handle_list_services (DBusConnection *connection,
                                 BusTransaction *transaction,
                                 DBusMessage    *message,
                                 DBusError      *error)
{
  DBusMessage *reply;
  int len;
  char **services;
  BusRegistry *registry;
  int i;
  DBusMessageIter iter;
  DBusMessageIter sub;

  _DBUS_ASSERT_ERROR_IS_CLEAR (error);
  
  registry = bus_connection_get_registry (connection);
  
  reply = dbus_message_new_method_return (message);
  if (reply == NULL)
    {
      BUS_SET_OOM (error);
      return FALSE;
    }

  if (!bus_registry_list_services (registry, &services, &len))
    {
      dbus_message_unref (reply);
      BUS_SET_OOM (error);
      return FALSE;
    }

  dbus_message_iter_init_append (reply, &iter);
  
  if (!dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY,
                                         DBUS_TYPE_STRING_AS_STRING,
                                         &sub))
    {
      dbus_free_string_array (services);
      dbus_message_unref (reply);
      BUS_SET_OOM (error);
      return FALSE;
    }

  {
    /* Include the bus driver in the list */
    const char *v_STRING = DBUS_SERVICE_DBUS;
    if (!dbus_message_iter_append_basic (&sub, DBUS_TYPE_STRING,
                                         &v_STRING))
      {
        dbus_free_string_array (services);
        dbus_message_unref (reply);
        BUS_SET_OOM (error);
        return FALSE;
      }
  }
  
  i = 0;
  while (i < len)
    {
      if (!dbus_message_iter_append_basic (&sub, DBUS_TYPE_STRING,
                                           &services[i]))
        {
          dbus_free_string_array (services);
          dbus_message_unref (reply);
          BUS_SET_OOM (error);
          return FALSE;
        }
      ++i;
    }

  if (!dbus_message_iter_close_container (&iter, &sub))
    {
      dbus_free_string_array (services);
      dbus_message_unref (reply);
      BUS_SET_OOM (error);
      return FALSE;
    }
  
  dbus_free_string_array (services);
  
  if (!bus_transaction_send_from_driver (transaction, connection, reply))
    {
      dbus_message_unref (reply);
      BUS_SET_OOM (error);
      return FALSE;
    }
  else
    {
      dbus_message_unref (reply);
      return TRUE;
    }
}
Esempio n. 21
0
void
gsm_consolekit_set_session_idle (GsmConsolekit *manager,
                                 gboolean       is_idle)
{
        gboolean        res;
        GError         *error;
        char           *session_id;
        DBusMessage    *message;
        DBusMessage    *reply;
        DBusError       dbus_error;
        DBusMessageIter iter;

        error = NULL;

        if (!gsm_consolekit_ensure_ck_connection (manager, &error)) {
                g_warning ("Could not connect to ConsoleKit: %s",
                           error->message);
                g_error_free (error);
                return;
        }

        session_id = NULL;
        res = get_current_session_id (dbus_g_connection_get_connection (manager->priv->dbus_connection),
                                      &session_id);
        if (!res) {
                goto out;
        }


        g_debug ("Updating ConsoleKit idle status: %d", is_idle);
        message = dbus_message_new_method_call (CK_NAME,
                                                session_id,
                                                CK_SESSION_INTERFACE,
                                                "SetIdleHint");
        if (message == NULL) {
                g_debug ("Couldn't allocate the D-Bus message");
                return;
        }

        dbus_message_iter_init_append (message, &iter);
        dbus_message_iter_append_basic (&iter, DBUS_TYPE_BOOLEAN, &is_idle);

        /* FIXME: use async? */
        dbus_error_init (&dbus_error);
        reply = dbus_connection_send_with_reply_and_block (dbus_g_connection_get_connection (manager->priv->dbus_connection),
                                                           message,
                                                           -1,
                                                           &dbus_error);
        dbus_message_unref (message);

        if (reply != NULL) {
                dbus_message_unref (reply);
        }

        if (dbus_error_is_set (&dbus_error)) {
                g_debug ("%s raised:\n %s\n\n", dbus_error.name, dbus_error.message);
                dbus_error_free (&dbus_error);
        }

out:
        g_free (session_id);
}
static dbus_bool_t
bus_driver_handle_list_queued_owners (DBusConnection *connection,
				      BusTransaction *transaction,
				      DBusMessage    *message,
				      DBusError      *error)
{
  const char *text;
  DBusList *base_names;
  DBusList *link;
  DBusString str;
  BusRegistry *registry;
  BusService *service;
  DBusMessage *reply;
  DBusMessageIter iter, array_iter;
  char *dbus_service_name = DBUS_SERVICE_DBUS;
  
  _DBUS_ASSERT_ERROR_IS_CLEAR (error);

  registry = bus_connection_get_registry (connection);

  base_names = NULL;
  text = NULL;
  reply = NULL;

  if (! dbus_message_get_args (message, error,
			       DBUS_TYPE_STRING, &text,
			       DBUS_TYPE_INVALID))
      goto failed;

  _dbus_string_init_const (&str, text);
  service = bus_registry_lookup (registry, &str);
  if (service == NULL &&
      _dbus_string_equal_c_str (&str, DBUS_SERVICE_DBUS))
    {
      /* ORG_FREEDESKTOP_DBUS owns itself */
      if (! _dbus_list_append (&base_names, dbus_service_name))
        goto oom;
    }
  else if (service == NULL)
    {
      dbus_set_error (error, 
                      DBUS_ERROR_NAME_HAS_NO_OWNER,
                      "Could not get owners of name '%s': no such name", text);
      goto failed;
    }
  else
    {
      if (!bus_service_list_queued_owners (service, 
                                           &base_names,
                                           error))
        goto failed;
    }

  _dbus_assert (base_names != NULL);

  reply = dbus_message_new_method_return (message);
  if (reply == NULL)
    goto oom;

  dbus_message_iter_init_append (reply, &iter);
  if (!dbus_message_iter_open_container (&iter,
                                         DBUS_TYPE_ARRAY,
                                         DBUS_TYPE_STRING_AS_STRING,
                                         &array_iter))
    goto oom;
  
  link = _dbus_list_get_first_link (&base_names);
  while (link != NULL)
    {
      char *uname;

      _dbus_assert (link->data != NULL);
      uname = (char *)link->data;
    
      if (!dbus_message_iter_append_basic (&array_iter, 
                                           DBUS_TYPE_STRING,
                                           &uname))
        goto oom;

      link = _dbus_list_get_next_link (&base_names, link);
    }

  if (! dbus_message_iter_close_container (&iter, &array_iter))
    goto oom;
                                    
 
  if (! bus_transaction_send_from_driver (transaction, connection, reply))
    goto oom;

  dbus_message_unref (reply);

  return TRUE;

 oom:
  BUS_SET_OOM (error);

 failed:
  _DBUS_ASSERT_ERROR_IS_SET (error);
  if (reply)
    dbus_message_unref (reply);

  if (base_names)
    _dbus_list_clear (&base_names);

  return FALSE;
}
Esempio n. 23
0
static int showNotify(const char *pcHeader, const char *pcBody)
{
    int rc;
# ifdef VBOX_WITH_DBUS
    DBusConnection *conn;
    DBusMessage* msg = NULL;
    conn = dbus_bus_get (DBUS_BUS_SESSION, NULL);
    if (conn == NULL)
    {
        LogRelFlowFunc(("Could not retrieve D-BUS session bus!\n"));
        rc = VERR_INVALID_HANDLE;
    }
    else
    {
        msg = dbus_message_new_method_call("org.freedesktop.Notifications",
                                           "/org/freedesktop/Notifications",
                                           "org.freedesktop.Notifications",
                                           "Notify");
        if (msg == NULL)
        {
            LogRel(("Could not create D-BUS message!\n"));
            rc = VERR_INVALID_HANDLE;
        }
        else
            rc = VINF_SUCCESS;
    }
    if (RT_SUCCESS(rc))
    {
        uint32_t msg_replace_id = 0;
        const char *msg_app = "VBoxClient";
        const char *msg_icon = "";
        const char *msg_summary = pcHeader;
        const char *msg_body = pcBody;
        int32_t msg_timeout = -1;           /* Let the notification server decide */

        DBusMessageIter iter;
        DBusMessageIter array;
        DBusMessageIter dict;
        DBusMessageIter value;
        DBusMessageIter variant;
        DBusMessageIter data;

        /* Format: UINT32 org.freedesktop.Notifications.Notify
         *         (STRING app_name, UINT32 replaces_id, STRING app_icon, STRING summary, STRING body,
         *          ARRAY actions, DICT hints, INT32 expire_timeout)
         */
        dbus_message_iter_init_append(msg,&iter);
        dbus_message_iter_append_basic(&iter,DBUS_TYPE_STRING,&msg_app);
        dbus_message_iter_append_basic(&iter,DBUS_TYPE_UINT32,&msg_replace_id);
        dbus_message_iter_append_basic(&iter,DBUS_TYPE_STRING,&msg_icon);
        dbus_message_iter_append_basic(&iter,DBUS_TYPE_STRING,&msg_summary);
        dbus_message_iter_append_basic(&iter,DBUS_TYPE_STRING,&msg_body);
        dbus_message_iter_open_container(&iter,DBUS_TYPE_ARRAY,DBUS_TYPE_STRING_AS_STRING,&array);
        dbus_message_iter_close_container(&iter,&array);
        dbus_message_iter_open_container(&iter,DBUS_TYPE_ARRAY,"{sv}",&array);
        dbus_message_iter_close_container(&iter,&array);
        dbus_message_iter_append_basic(&iter,DBUS_TYPE_INT32,&msg_timeout);

        DBusError err;
        dbus_error_init(&err);

        DBusMessage *reply;
        reply = dbus_connection_send_with_reply_and_block(conn, msg,
            30 * 1000 /* 30 seconds timeout */, &err);
        if (dbus_error_is_set(&err))
        {
            LogRel(("D-BUS returned an error while sending the notification: %s", err.message));
        }
        else if (reply)
        {
            dbus_connection_flush(conn);
            dbus_message_unref(reply);
        }
        if (dbus_error_is_set(&err))
            dbus_error_free(&err);
    }
    if (msg != NULL)
        dbus_message_unref(msg);
# else
    /* TODO: Implement me */
    rc = VINF_SUCCESS;
# endif /* VBOX_WITH_DBUS */
    return rc;
}
Esempio n. 24
0
static void process_properties_from_interface(struct generic_data *data,
						struct interface_data *iface)
{
	GSList *l;
	DBusMessage *signal;
	DBusMessageIter iter, dict, array;
	GSList *invalidated;

	if (iface->pending_prop == NULL)
		return;

	signal = dbus_message_new_signal(data->path,
			DBUS_INTERFACE_PROPERTIES, "PropertiesChanged");
	if (signal == NULL) {
		error("Unable to allocate new " DBUS_INTERFACE_PROPERTIES
						".PropertiesChanged signal");
		return;
	}

	iface->pending_prop = g_slist_reverse(iface->pending_prop);

	dbus_message_iter_init_append(signal, &iter);
	dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING,	&iface->name);
	dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
			DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
			DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING
			DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict);

	invalidated = NULL;

	for (l = iface->pending_prop; l != NULL; l = l->next) {
		GDBusPropertyTable *p = l->data;

		if (p->get == NULL)
			continue;

		if (p->exists != NULL && !p->exists(p, iface->user_data)) {
			invalidated = g_slist_prepend(invalidated, p);
			continue;
		}

		append_property(iface, p, &dict);
	}

	dbus_message_iter_close_container(&iter, &dict);

	dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
				DBUS_TYPE_STRING_AS_STRING, &array);
	for (l = invalidated; l != NULL; l = g_slist_next(l)) {
		GDBusPropertyTable *p = l->data;

		dbus_message_iter_append_basic(&array, DBUS_TYPE_STRING,
								&p->name);
	}
	g_slist_free(invalidated);
	dbus_message_iter_close_container(&iter, &array);

	g_dbus_send_message(data->conn, signal);

	g_slist_free(iface->pending_prop);
	iface->pending_prop = NULL;
}
Esempio n. 25
0
int main(int argc, char *argv[])
{
	DBusConnection *conn;
	DBusError error;
	DBusMessage *msg;
	DBusMessageIter iter, dict;
	char **envp, *busname, *reason, *interface, *path;

	busname = getenv("CONNMAN_BUSNAME");
	interface = getenv("CONNMAN_INTERFACE");
	path = getenv("CONNMAN_PATH");

	reason = getenv("reason");

	if (!busname || !interface || !path || !reason) {
		fprintf(stderr, "Required environment variables not set\n");
		return 1;
	}

	if (strcmp(reason, "pre-init") == 0)
		return 0;

	dbus_error_init(&error);

	conn = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
	if (conn == NULL) {
		if (dbus_error_is_set(&error) == TRUE) {
			fprintf(stderr, "%s\n", error.message);
			dbus_error_free(&error);
		} else
			fprintf(stderr, "Failed to get on system bus\n");
		return 0;
	}

	msg = dbus_message_new_method_call(busname, path,
						interface, "notify");
	if (msg == NULL) {
		dbus_connection_unref(conn);
		fprintf(stderr, "Failed to allocate method call\n");
		return 0;
	}

	dbus_message_set_no_reply(msg, TRUE);

	dbus_message_append_args(msg,
				 DBUS_TYPE_STRING, &reason,
				 DBUS_TYPE_INVALID);

	dbus_message_iter_init_append(msg, &iter);

	dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
			DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
			DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_STRING_AS_STRING
			DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict);

	for (envp = environ; envp && *envp; envp++)
		append(&dict, *envp);

	dbus_message_iter_close_container(&iter, &dict);

	if (dbus_connection_send(conn, msg, NULL) == FALSE)
		fprintf(stderr, "Failed to send message\n");

	dbus_connection_flush(conn);

	dbus_message_unref(msg);

	dbus_connection_unref(conn);

	return 0;
}
Esempio n. 26
0
// Synchronous, should probably be fixed
uint8_t SetHUDDisplayMsgReq(
    uint32_t manueverIcon,
    uint16_t manueverDistance,
    uint8_t manueverDistanceUnit,
    uint16_t speedLimit,
    uint8_t speedLimitUnit)
{
    DBusMessage *msg = dbus_message_new_method_call("com.jci.vbs.navi", "/com/jci/vbs/navi",
                                                    "com.jci.vbs.navi","SetHUDDisplayMsgReq");
    DBusPendingCall *pending = nullptr;

    if (!msg) {
        assert(false && "failed to create message");
    }

    DBusMessageIter iter;
    dbus_message_iter_init_append(msg, &iter);

    DBusMessageIter sub;
    if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_STRUCT, nullptr, &sub)) {
       assert(false && "failed to initialize sub-iterator");
    }

    {
        dbus_bool_t result = TRUE;
        result &= dbus_message_iter_append_basic(&sub, DBUS_TYPE_UINT32, &manueverIcon);
        result &= dbus_message_iter_append_basic(&sub, DBUS_TYPE_UINT16, &manueverDistance);
        result &= dbus_message_iter_append_basic(&sub, DBUS_TYPE_BYTE, &manueverDistanceUnit);
        result &= dbus_message_iter_append_basic(&sub, DBUS_TYPE_UINT16, &speedLimit);
        result &= dbus_message_iter_append_basic(&sub, DBUS_TYPE_BYTE, &speedLimitUnit);

        if (!result) {
            assert(false && "failed to append arguments to struct");
        }
    }

    if (!dbus_message_iter_close_container(&iter, &sub)) {
        assert(false && "failed to close container");
    }

    if (!dbus_connection_send_with_reply(service_bus, msg, &pending, -1)) {
        assert(false && "failed to send message");
    }

    dbus_connection_flush(service_bus);
    dbus_message_unref(msg);

    dbus_pending_call_block(pending);
    msg = dbus_pending_call_steal_reply(pending);
    if (!msg) {
       assert(false && "received null reply");
    }

    uint8_t result;
    if (!dbus_message_get_args(msg, nullptr, DBUS_TYPE_BYTE, &result,
                                             DBUS_TYPE_INVALID)) {
        assert(false && "failed to get result");
    }

    dbus_message_unref(msg);

    return result;
}
Esempio n. 27
0
DBusMessage * wbmd_dbus_interface_show_wbridge_basic_info(DBusConnection *conn, DBusMessage *msg, void *user_data){
	
	DBusMessage* reply;	
	DBusMessageIter	 iter;
	DBusMessageIter	 iter_array;
	DBusMessageIter iter_sub_array;
	DBusMessageIter iter_sub_struct;
	unsigned int num=0;
	DBusError err;
	int ret = WBMD_DBUS_SUCCESS;
	dbus_error_init(&err);
	int i=0;
	int j = 0;
	int WBID;
	char *name = NULL;
	struct wbridge_info *wb[WBRIDGE_NUM];
	dbus_error_init(&err);
	if (!(dbus_message_get_args ( msg, &err,
								DBUS_TYPE_UINT32,&WBID,
								DBUS_TYPE_INVALID))){

		printf("Unable to get input args\n");
				
		if (dbus_error_is_set(&err)) {
			printf("%s raised: %s",err.name,err.message);
			dbus_error_free(&err);
		}
		return NULL;
	}
	if(WBID == 0){
		while(i<WBRIDGE_NUM){
			if(wBridge[i] != NULL)
			{
				wb[num] = wBridge[i];
				num++;
			}
			i++;
		}
	}else{
		if(wBridge[WBID] != NULL){
			wb[num] = wBridge[WBID];
			num++;
		}
	}
	if(num == 0)
		ret = WBMD_DBUS_ID_NO_EXIST;
	
	reply = dbus_message_new_method_return(msg);
		
	dbus_message_iter_init_append (reply, &iter);
		
	dbus_message_iter_append_basic (&iter,
										 DBUS_TYPE_UINT32,
										 &ret);
	if(ret == WBMD_DBUS_SUCCESS){
		name = (char *)malloc(16);
		memset(name, 0, 16);
		dbus_message_iter_append_basic (&iter,
											 DBUS_TYPE_UINT32,
											 &num);
			
		dbus_message_iter_open_container (&iter,
										DBUS_TYPE_ARRAY,
										DBUS_STRUCT_BEGIN_CHAR_AS_STRING
												DBUS_TYPE_UINT32_AS_STRING					
												DBUS_TYPE_UINT32_AS_STRING
												DBUS_TYPE_UINT32_AS_STRING
												DBUS_TYPE_UINT32_AS_STRING
												DBUS_TYPE_ARRAY_AS_STRING
												DBUS_STRUCT_BEGIN_CHAR_AS_STRING
													DBUS_TYPE_UINT32_AS_STRING
													DBUS_TYPE_STRING_AS_STRING
													DBUS_TYPE_UINT32_AS_STRING
													DBUS_TYPE_UINT32_AS_STRING
													DBUS_TYPE_UINT32_AS_STRING
													DBUS_TYPE_BYTE_AS_STRING
													DBUS_TYPE_BYTE_AS_STRING
													DBUS_TYPE_BYTE_AS_STRING
													DBUS_TYPE_BYTE_AS_STRING
													DBUS_TYPE_BYTE_AS_STRING
													DBUS_TYPE_BYTE_AS_STRING
													DBUS_TYPE_UINT32_AS_STRING
													DBUS_TYPE_UINT32_AS_STRING
													DBUS_TYPE_UINT32_AS_STRING
													DBUS_TYPE_UINT32_AS_STRING
													DBUS_TYPE_UINT32_AS_STRING
													DBUS_TYPE_UINT32_AS_STRING
													DBUS_TYPE_UINT32_AS_STRING
													DBUS_TYPE_UINT32_AS_STRING
													DBUS_TYPE_UINT32_AS_STRING
													DBUS_TYPE_UINT32_AS_STRING
													DBUS_TYPE_UINT32_AS_STRING
													DBUS_TYPE_UINT32_AS_STRING
													DBUS_TYPE_UINT32_AS_STRING
													DBUS_TYPE_UINT32_AS_STRING
													DBUS_TYPE_UINT32_AS_STRING
													DBUS_TYPE_UINT32_AS_STRING
												DBUS_STRUCT_END_CHAR_AS_STRING
										DBUS_STRUCT_END_CHAR_AS_STRING,
										&iter_array);

		for(i = 0; i < num; i++){			
			DBusMessageIter iter_struct;
			dbus_message_iter_open_container (&iter_array,
											DBUS_TYPE_STRUCT,
											NULL,
											&iter_struct);
			dbus_message_iter_append_basic
						(&iter_struct,
						  DBUS_TYPE_UINT32,
						  &(wb[i]->WBID));

			dbus_message_iter_append_basic
						(&iter_struct,
						  DBUS_TYPE_UINT32,
						  &(wb[i]->IP));
				
			dbus_message_iter_append_basic
						(&iter_struct,
						  DBUS_TYPE_UINT32,
						  &(wb[i]->WBState));
				
			dbus_message_iter_append_basic
						(&iter_struct,
						  DBUS_TYPE_UINT32,
						  &(wb[i]->if_num));
				
			dbus_message_iter_open_container (&iter_struct,
											DBUS_TYPE_ARRAY,
											DBUS_STRUCT_BEGIN_CHAR_AS_STRING
												DBUS_TYPE_UINT32_AS_STRING
												DBUS_TYPE_STRING_AS_STRING
												DBUS_TYPE_UINT32_AS_STRING
												DBUS_TYPE_UINT32_AS_STRING
												DBUS_TYPE_UINT32_AS_STRING
												DBUS_TYPE_BYTE_AS_STRING
												DBUS_TYPE_BYTE_AS_STRING
												DBUS_TYPE_BYTE_AS_STRING
												DBUS_TYPE_BYTE_AS_STRING
												DBUS_TYPE_BYTE_AS_STRING
												DBUS_TYPE_BYTE_AS_STRING
												DBUS_TYPE_UINT32_AS_STRING
												DBUS_TYPE_UINT32_AS_STRING
												DBUS_TYPE_UINT32_AS_STRING
												DBUS_TYPE_UINT32_AS_STRING
												DBUS_TYPE_UINT32_AS_STRING
												DBUS_TYPE_UINT32_AS_STRING
												DBUS_TYPE_UINT32_AS_STRING
												DBUS_TYPE_UINT32_AS_STRING
												DBUS_TYPE_UINT32_AS_STRING
												DBUS_TYPE_UINT32_AS_STRING
												DBUS_TYPE_UINT32_AS_STRING
												DBUS_TYPE_UINT32_AS_STRING
												DBUS_TYPE_UINT32_AS_STRING
												DBUS_TYPE_UINT32_AS_STRING
												DBUS_TYPE_UINT32_AS_STRING
												DBUS_TYPE_UINT32_AS_STRING
											DBUS_STRUCT_END_CHAR_AS_STRING,
										  &iter_sub_array);
			for(j = 0;j < wb[i]->if_num; j++)
		   	{
		       
				dbus_message_iter_open_container (&iter_sub_array,
				 									 DBUS_TYPE_STRUCT,
				 									 NULL,
													 &iter_sub_struct);
						
				dbus_message_iter_append_basic (&iter_sub_struct,DBUS_TYPE_UINT32 ,&(wb[i]->WBIF[j].ifIndex));

				memset(name, 0, 16);
				strcpy(name, wb[i]->WBIF[j].ifDescr);
				dbus_message_iter_append_basic (&iter_sub_struct,DBUS_TYPE_STRING ,&name);

				dbus_message_iter_append_basic (&iter_sub_struct,DBUS_TYPE_UINT32 ,&(wb[i]->WBIF[j].ifType));

				dbus_message_iter_append_basic (&iter_sub_struct,DBUS_TYPE_UINT32 ,&(wb[i]->WBIF[j].ifMtu));

				dbus_message_iter_append_basic (&iter_sub_struct,DBUS_TYPE_UINT32 ,&(wb[i]->WBIF[j].ifSpeed));

				dbus_message_iter_append_basic (&iter_sub_struct,DBUS_TYPE_BYTE ,&(wb[i]->WBIF[j].ifPhysAddress[0]));

				dbus_message_iter_append_basic (&iter_sub_struct,DBUS_TYPE_BYTE ,&(wb[i]->WBIF[j].ifPhysAddress[1]));

				dbus_message_iter_append_basic (&iter_sub_struct,DBUS_TYPE_BYTE ,&(wb[i]->WBIF[j].ifPhysAddress[2]));

				dbus_message_iter_append_basic (&iter_sub_struct,DBUS_TYPE_BYTE ,&(wb[i]->WBIF[j].ifPhysAddress[3]));

				dbus_message_iter_append_basic (&iter_sub_struct,DBUS_TYPE_BYTE ,&(wb[i]->WBIF[j].ifPhysAddress[4]));

				dbus_message_iter_append_basic (&iter_sub_struct,DBUS_TYPE_BYTE ,&(wb[i]->WBIF[j].ifPhysAddress[5]));

				dbus_message_iter_append_basic (&iter_sub_struct,DBUS_TYPE_UINT32 ,&(wb[i]->WBIF[j].ifAdminStatus));

				dbus_message_iter_append_basic (&iter_sub_struct,DBUS_TYPE_UINT32 ,&(wb[i]->WBIF[j].ifOperStatus));

				dbus_message_iter_append_basic (&iter_sub_struct,DBUS_TYPE_UINT32 ,&(wb[i]->WBIF[j].ifLastChange));

				dbus_message_iter_append_basic (&iter_sub_struct,DBUS_TYPE_UINT32 ,&(wb[i]->WBIF[j].ifInOctets));

				dbus_message_iter_append_basic (&iter_sub_struct,DBUS_TYPE_UINT32 ,&(wb[i]->WBIF[j].ifInUcastPkts));

				dbus_message_iter_append_basic (&iter_sub_struct,DBUS_TYPE_UINT32 ,&(wb[i]->WBIF[j].ifInNUcastPkts));

				dbus_message_iter_append_basic (&iter_sub_struct,DBUS_TYPE_UINT32 ,&(wb[i]->WBIF[j].ifInDiscards));

				dbus_message_iter_append_basic (&iter_sub_struct,DBUS_TYPE_UINT32 ,&(wb[i]->WBIF[j].ifInErrors));

				dbus_message_iter_append_basic (&iter_sub_struct,DBUS_TYPE_UINT32 ,&(wb[i]->WBIF[j].ifInUnknownProtos));

				dbus_message_iter_append_basic (&iter_sub_struct,DBUS_TYPE_UINT32 ,&(wb[i]->WBIF[j].ifOutOctets));

				dbus_message_iter_append_basic (&iter_sub_struct,DBUS_TYPE_UINT32 ,&(wb[i]->WBIF[j].ifOutUcastPkts));

				dbus_message_iter_append_basic (&iter_sub_struct,DBUS_TYPE_UINT32 ,&(wb[i]->WBIF[j].ifOutNUcastPkts));

				dbus_message_iter_append_basic (&iter_sub_struct,DBUS_TYPE_UINT32 ,&(wb[i]->WBIF[j].ifOutDiscards));

				dbus_message_iter_append_basic (&iter_sub_struct,DBUS_TYPE_UINT32 ,&(wb[i]->WBIF[j].ifOutErrors));

				dbus_message_iter_append_basic (&iter_sub_struct,DBUS_TYPE_UINT32 ,&(wb[i]->WBIF[j].ifOutQLen));

				dbus_message_iter_append_basic (&iter_sub_struct,DBUS_TYPE_UINT32 ,&(wb[i]->WBIF[j].ifSpecific));

		    	dbus_message_iter_close_container (&iter_sub_array, &iter_sub_struct);
			}
			dbus_message_iter_close_container (&iter_struct, &iter_sub_array);
			dbus_message_iter_close_container (&iter_array, &iter_struct);
		}
		dbus_message_iter_close_container (&iter, &iter_array);
		if(name)
			free(name);
	}
	
	return reply;	
}
Esempio n. 28
0
void FcitxXkbDBusGetLayouts(FcitxXkbDBus* xkbdbus, DBusMessage* message)
{
    DBusMessageIter iter, sub;
    dbus_message_iter_init_append(message, &iter);

    dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "(ssss)", &sub);

    FcitxXkbRules* rules = xkbdbus->rules;
    FcitxIsoCodes* isocodes = xkbdbus->isocodes;
    char* lang = NULL;
#define GET_LANG \
    do { \
        char** plang = NULL; \
        plang = (char**) utarray_front(layoutInfo->languages); \
        lang = NULL; \
        if (plang) { \
            FcitxIsoCodes639Entry* entry = FcitxIsoCodesGetEntry(isocodes, *plang); \
            if (entry) { \
                lang = entry->iso_639_1_code; \
            } \
        } \
    } while (0)

    if (rules) {
        FcitxXkbLayoutInfo* layoutInfo;
        for (layoutInfo = (FcitxXkbLayoutInfo*) utarray_front(rules->layoutInfos);
            layoutInfo != NULL;
            layoutInfo = (FcitxXkbLayoutInfo*) utarray_next(rules->layoutInfos, layoutInfo))
        {
            char* description;
            asprintf(&description, "%s",
                     dgettext("xkeyboard-config", layoutInfo->description));

            GET_LANG;
            FcitxXkbDBusAppendLayout(&sub, layoutInfo->name, "", description, lang);
            free(description);
            FcitxXkbVariantInfo* variantInfo;
            for (variantInfo = (FcitxXkbVariantInfo*) utarray_front(layoutInfo->variantInfos);
                variantInfo != NULL;
                variantInfo = (FcitxXkbVariantInfo*) utarray_next(layoutInfo->variantInfos, variantInfo))
            {
                char* description;
                asprintf(&description, "%s - %s",
                        dgettext("xkeyboard-config", layoutInfo->description),
                        dgettext("xkeyboard-config", variantInfo->description));

                GET_LANG;
                FcitxXkbDBusAppendLayout(&sub, layoutInfo->name, variantInfo->name, description, lang);
                free(description);
            }
        }
    }
    else {
        char* description;
        asprintf(&description, "%s",
                dgettext("xkeyboard-config", "English (US)"));

        FcitxXkbDBusAppendLayout(&sub, "us", "", description, "en");
        free(description);
    }
    dbus_message_iter_close_container(&iter, &sub);
}
Esempio n. 29
0
DBusMessage * wbmd_dbus_interface_show_wbridge_list(DBusConnection *conn, DBusMessage *msg, void *user_data){
	
	DBusMessage* reply;	
	DBusMessageIter	 iter;
	DBusMessageIter	 iter_array;
	unsigned int num=0;
	DBusError err;
	int ret = WBMD_DBUS_SUCCESS;
	dbus_error_init(&err);
	int i=0;
	struct wbridge_info *wb[WBRIDGE_NUM];
	int WBID;
	dbus_error_init(&err);
	if (!(dbus_message_get_args ( msg, &err,
								DBUS_TYPE_UINT32,&WBID,
								DBUS_TYPE_INVALID))){

		printf("Unable to get input args\n");
				
		if (dbus_error_is_set(&err)) {
			printf("%s raised: %s",err.name,err.message);
			dbus_error_free(&err);
		}
		return NULL;
	}
	if(WBID == 0){
		while(i<WBRIDGE_NUM){
			if(wBridge[i] != NULL)
			{
				wb[num] = wBridge[i];
				num++;
			}
			i++;
		}
	}else{
		if(wBridge[WBID] != NULL){
			wb[num] = wBridge[WBID];
			num++;
		}
	}
	if(num == 0)
		ret = WBMD_DBUS_ID_NO_EXIST;
	
	reply = dbus_message_new_method_return(msg);
		
	dbus_message_iter_init_append (reply, &iter);
		
	dbus_message_iter_append_basic (&iter,
										 DBUS_TYPE_UINT32,
										 &ret);
	if(ret == WBMD_DBUS_SUCCESS){
		dbus_message_iter_append_basic (&iter,
											 DBUS_TYPE_UINT32,
											 &num);
			
		dbus_message_iter_open_container (&iter,
										DBUS_TYPE_ARRAY,
										DBUS_STRUCT_BEGIN_CHAR_AS_STRING
											DBUS_TYPE_UINT32_AS_STRING
											DBUS_TYPE_UINT32_AS_STRING
											DBUS_TYPE_UINT32_AS_STRING
											DBUS_TYPE_UINT32_AS_STRING
											DBUS_TYPE_UINT32_AS_STRING
											DBUS_TYPE_UINT32_AS_STRING
										DBUS_STRUCT_END_CHAR_AS_STRING,
										&iter_array);

		for(i = 0; i < num; i++){			
			DBusMessageIter iter_struct;
			dbus_message_iter_open_container (&iter_array,
											DBUS_TYPE_STRUCT,
											NULL,
											&iter_struct);
			dbus_message_iter_append_basic
						(&iter_struct,
						  DBUS_TYPE_UINT32,
						  &(wb[i]->WBID));
				
			dbus_message_iter_append_basic
						(&iter_struct,
						  DBUS_TYPE_UINT32,
						  &(wb[i]->IP));
				
			dbus_message_iter_append_basic
						(&iter_struct,
						  DBUS_TYPE_UINT32,
						  &(wb[i]->WBState));

			dbus_message_iter_append_basic
						(&iter_struct,
						  DBUS_TYPE_UINT32,
						  &(wb[i]->access_time));
				
			dbus_message_iter_append_basic
						(&iter_struct,
						  DBUS_TYPE_UINT32,
						  &(wb[i]->last_access_time));
				
			dbus_message_iter_append_basic
						(&iter_struct,
						  DBUS_TYPE_UINT32,
						  &(wb[i]->leave_time));
					
			dbus_message_iter_close_container (&iter_array, &iter_struct);


		}
					
		dbus_message_iter_close_container (&iter, &iter_array);
	}
	
	return reply;	
}
/**
 * @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;
  DBusInitialFDs *initial_fds;

  initial_fds = _dbus_check_fdleaks_enter ();

  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 (&copy->header.data));

  _dbus_assert (_dbus_string_get_length (&message->body) ==
                _dbus_string_get_length (&copy->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_leave (initial_fds);
  initial_fds = _dbus_check_fdleaks_enter ();

  /* 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_leave (initial_fds);

  /* Now load every message in test_data_dir if we have one */
  if (test_data_dir == NULL)
    return TRUE;

  initial_fds = _dbus_check_fdleaks_enter ();

  if (!dbus_internal_do_not_use_foreach_message_file (test_data_dir,
                                                        (DBusForeachMessageFileFunc)
                                                        dbus_internal_do_not_use_try_message_file,
                                                        NULL))
    _dbus_assert_not_reached ("foreach_message_file test failed");

  _dbus_check_fdleaks_leave (initial_fds);

  return TRUE;
}