+ char path[MAX_PATH*2];
+ int path_size = sizeof(path);
+
+ if (!_dbus_get_install_root(path,path_size))
+ return FALSE;
+
+ _dbus_string_init(&install_path);
+ _dbus_string_append(&install_path,path);
+
+ _dbus_string_init(out);
+ _dbus_string_tolower_ascii(&install_path,0,_dbus_string_get_length(&install_path));
+
+ if (!_dbus_sha_compute (&install_path, out))
+ return FALSE;
+
+ return TRUE;
+}
+
+static dbus_bool_t
+_dbus_get_address_string (DBusString *out, const char *basestring, const char *scope)
+{
+ _dbus_string_init(out);
+ _dbus_string_append(out,basestring);
+
+ if (!scope)
+ {
+ return TRUE;
+ }
+ else if (strcmp(scope,"*install-path") == 0
+ // for 1.3 compatibility
+ || strcmp(scope,"install-path") == 0)
+ {
+ DBusString temp;
+ if (!_dbus_get_install_root_as_hash(&temp))
+ {
+ _dbus_string_free(out);
+ return FALSE;
+ }
+ _dbus_string_append(out,"-");
+ _dbus_string_append(out,_dbus_string_get_const_data(&temp));
+ _dbus_string_free(&temp);
+ }
+ else if (strcmp(scope,"*user") == 0)
+ {
+ _dbus_string_append(out,"-");
+ if (!_dbus_append_user_from_current_process(out))
+ {
+ _dbus_string_free(out);
+ return FALSE;
+ }
+ }
+ else if (strlen(scope) > 0)
+ {
+ _dbus_string_append(out,"-");
+ _dbus_string_append(out,scope);
+ return TRUE;
+ }
+ return TRUE;
+}
+
+static dbus_bool_t
+_dbus_get_shm_name (DBusString *out,const char *scope)
+{
+ return _dbus_get_address_string (out,cDBusDaemonAddressInfo,scope);
+}
+
+static dbus_bool_t
+_dbus_get_mutex_name (DBusString *out,const char *scope)
+{
+ return _dbus_get_address_string (out,cDBusDaemonMutex,scope);
+}
+
+dbus_bool_t
+_dbus_daemon_is_session_bus_address_published (const char *scope)
+{
+ HANDLE lock;
+ DBusString mutex_name;
+
+ if (!_dbus_get_mutex_name(&mutex_name,scope))
+ {
+ _dbus_string_free( &mutex_name );
+ return FALSE;
+ }
+
+ if (hDBusDaemonMutex)
+ return TRUE;
+
+ // sync _dbus_daemon_publish_session_bus_address, _dbus_daemon_unpublish_session_bus_address and _dbus_daemon_already_runs
+ lock = _dbus_global_lock( cUniqueDBusInitMutex );
+
+ // we use CreateMutex instead of OpenMutex because of possible race conditions,
+ // see http://msdn.microsoft.com/en-us/library/ms684315%28VS.85%29.aspx
+ hDBusDaemonMutex = CreateMutexA( NULL, FALSE, _dbus_string_get_const_data(&mutex_name) );
+
+ /* The client uses mutex ownership to detect a running server, so the server should do so too.
+ Fortunally the client deletes the mutex in the lock protected area, so checking presence
+ will work too. */
+
+ _dbus_global_unlock( lock );
+
+ _dbus_string_free( &mutex_name );
+
+ if (hDBusDaemonMutex == NULL)
+ return FALSE;
+ if (GetLastError() == ERROR_ALREADY_EXISTS)
+ {
+ CloseHandle(hDBusDaemonMutex);
+ hDBusDaemonMutex = NULL;
+ return TRUE;
+ }
+ // mutex wasn't created before, so return false.
+ // We leave the mutex name allocated for later reusage
+ // in _dbus_daemon_publish_session_bus_address.
+ return FALSE;
+}
+
+dbus_bool_t
+_dbus_daemon_publish_session_bus_address (const char* address, const char *scope)