2009-09-02 20:47:44 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim:expandtab:shiftwidth=2:tabstop=8:
|
2004-04-08 14:01:17 +00:00
|
|
|
*/
|
2003-11-21 00:09:50 +00:00
|
|
|
/* vim:set ts=8 sw=2 et cindent: */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2000-10-20 05:10:43 +00:00
|
|
|
|
|
|
|
#include "XRemoteClient.h"
|
|
|
|
#include "prmem.h"
|
|
|
|
#include "prprf.h"
|
|
|
|
#include "plstr.h"
|
|
|
|
#include "prsystem.h"
|
|
|
|
#include "prlog.h"
|
2001-09-18 21:45:43 +00:00
|
|
|
#include "prenv.h"
|
2005-04-04 19:08:55 +00:00
|
|
|
#include "prdtoa.h"
|
2000-10-20 05:10:43 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
2005-04-04 19:08:55 +00:00
|
|
|
#include <string.h>
|
2001-01-16 21:47:04 +00:00
|
|
|
#include <strings.h>
|
2000-10-20 05:10:43 +00:00
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <unistd.h>
|
2009-02-23 18:28:12 +00:00
|
|
|
#include <limits.h>
|
2000-10-20 05:10:43 +00:00
|
|
|
#include <X11/Xatom.h>
|
|
|
|
|
|
|
|
#define MOZILLA_VERSION_PROP "_MOZILLA_VERSION"
|
|
|
|
#define MOZILLA_LOCK_PROP "_MOZILLA_LOCK"
|
|
|
|
#define MOZILLA_COMMAND_PROP "_MOZILLA_COMMAND"
|
2005-04-04 19:08:55 +00:00
|
|
|
#define MOZILLA_COMMANDLINE_PROP "_MOZILLA_COMMANDLINE"
|
2000-10-20 05:10:43 +00:00
|
|
|
#define MOZILLA_RESPONSE_PROP "_MOZILLA_RESPONSE"
|
2001-09-18 21:45:43 +00:00
|
|
|
#define MOZILLA_USER_PROP "_MOZILLA_USER"
|
2004-04-08 14:01:17 +00:00
|
|
|
#define MOZILLA_PROFILE_PROP "_MOZILLA_PROFILE"
|
|
|
|
#define MOZILLA_PROGRAM_PROP "_MOZILLA_PROGRAM"
|
2000-10-20 05:10:43 +00:00
|
|
|
|
2005-12-26 03:10:35 +00:00
|
|
|
#ifdef IS_BIG_ENDIAN
|
|
|
|
#define TO_LITTLE_ENDIAN32(x) \
|
|
|
|
((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \
|
|
|
|
(((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24))
|
|
|
|
#else
|
|
|
|
#define TO_LITTLE_ENDIAN32(x) (x)
|
|
|
|
#endif
|
|
|
|
|
2005-04-04 19:08:55 +00:00
|
|
|
#ifndef MAX_PATH
|
2009-02-23 18:28:12 +00:00
|
|
|
#ifdef PATH_MAX
|
|
|
|
#define MAX_PATH PATH_MAX
|
|
|
|
#else
|
2005-04-04 19:08:55 +00:00
|
|
|
#define MAX_PATH 1024
|
|
|
|
#endif
|
2009-02-23 18:28:12 +00:00
|
|
|
#endif
|
2005-04-04 19:08:55 +00:00
|
|
|
|
2005-02-19 16:11:58 +00:00
|
|
|
#define ARRAY_LENGTH(array_) (sizeof(array_)/sizeof(array_[0]))
|
|
|
|
|
2013-10-28 14:05:51 +00:00
|
|
|
static PRLogModuleInfo *sRemoteLm = nullptr;
|
2000-10-20 05:10:43 +00:00
|
|
|
|
2009-09-02 20:47:44 +00:00
|
|
|
static int (*sOldHandler)(Display *, XErrorEvent *);
|
2011-09-29 06:19:26 +00:00
|
|
|
static bool sGotBadWindow;
|
2009-09-02 20:47:44 +00:00
|
|
|
|
2000-10-20 05:10:43 +00:00
|
|
|
XRemoteClient::XRemoteClient()
|
|
|
|
{
|
|
|
|
mDisplay = 0;
|
2011-10-17 14:59:28 +00:00
|
|
|
mInitialized = false;
|
2000-10-20 05:10:43 +00:00
|
|
|
mMozVersionAtom = 0;
|
|
|
|
mMozLockAtom = 0;
|
|
|
|
mMozCommandAtom = 0;
|
|
|
|
mMozResponseAtom = 0;
|
2001-09-11 01:36:19 +00:00
|
|
|
mMozWMStateAtom = 0;
|
2001-09-18 21:45:43 +00:00
|
|
|
mMozUserAtom = 0;
|
2001-12-28 22:17:20 +00:00
|
|
|
mLockData = 0;
|
2000-10-20 05:10:43 +00:00
|
|
|
if (!sRemoteLm)
|
|
|
|
sRemoteLm = PR_NewLogModule("XRemoteClient");
|
|
|
|
PR_LOG(sRemoteLm, PR_LOG_DEBUG, ("XRemoteClient::XRemoteClient"));
|
|
|
|
}
|
|
|
|
|
|
|
|
XRemoteClient::~XRemoteClient()
|
|
|
|
{
|
|
|
|
PR_LOG(sRemoteLm, PR_LOG_DEBUG, ("XRemoteClient::~XRemoteClient"));
|
|
|
|
if (mInitialized)
|
|
|
|
Shutdown();
|
|
|
|
}
|
|
|
|
|
2005-02-19 16:11:58 +00:00
|
|
|
// Minimize the roundtrips to the X-server
|
2012-12-27 05:57:57 +00:00
|
|
|
static const char *XAtomNames[] = {
|
2005-02-19 16:11:58 +00:00
|
|
|
MOZILLA_VERSION_PROP,
|
|
|
|
MOZILLA_LOCK_PROP,
|
|
|
|
MOZILLA_COMMAND_PROP,
|
|
|
|
MOZILLA_RESPONSE_PROP,
|
|
|
|
"WM_STATE",
|
|
|
|
MOZILLA_USER_PROP,
|
|
|
|
MOZILLA_PROFILE_PROP,
|
2005-04-04 19:08:55 +00:00
|
|
|
MOZILLA_PROGRAM_PROP,
|
|
|
|
MOZILLA_COMMANDLINE_PROP
|
2005-02-19 16:11:58 +00:00
|
|
|
};
|
|
|
|
static Atom XAtoms[ARRAY_LENGTH(XAtomNames)];
|
|
|
|
|
2005-04-04 19:08:55 +00:00
|
|
|
nsresult
|
|
|
|
XRemoteClient::Init()
|
2000-10-20 05:10:43 +00:00
|
|
|
{
|
|
|
|
PR_LOG(sRemoteLm, PR_LOG_DEBUG, ("XRemoteClient::Init"));
|
|
|
|
|
|
|
|
if (mInitialized)
|
|
|
|
return NS_OK;
|
2005-04-04 19:08:55 +00:00
|
|
|
|
2000-10-20 05:10:43 +00:00
|
|
|
// try to open the display
|
|
|
|
mDisplay = XOpenDisplay(0);
|
|
|
|
if (!mDisplay)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
// get our atoms
|
2012-12-27 05:57:57 +00:00
|
|
|
XInternAtoms(mDisplay, const_cast<char**>(XAtomNames),
|
|
|
|
ARRAY_LENGTH(XAtomNames), False, XAtoms);
|
2005-02-19 16:11:58 +00:00
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
mMozVersionAtom = XAtoms[i++];
|
|
|
|
mMozLockAtom = XAtoms[i++];
|
|
|
|
mMozCommandAtom = XAtoms[i++];
|
|
|
|
mMozResponseAtom = XAtoms[i++];
|
|
|
|
mMozWMStateAtom = XAtoms[i++];
|
|
|
|
mMozUserAtom = XAtoms[i++];
|
|
|
|
mMozProfileAtom = XAtoms[i++];
|
|
|
|
mMozProgramAtom = XAtoms[i++];
|
2005-04-04 19:08:55 +00:00
|
|
|
mMozCommandLineAtom = XAtoms[i++];
|
2000-10-20 05:10:43 +00:00
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
mInitialized = true;
|
2000-10-20 05:10:43 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-04-04 19:08:55 +00:00
|
|
|
void
|
2000-10-20 05:10:43 +00:00
|
|
|
XRemoteClient::Shutdown (void)
|
|
|
|
{
|
|
|
|
PR_LOG(sRemoteLm, PR_LOG_DEBUG, ("XRemoteClient::Shutdown"));
|
|
|
|
|
|
|
|
if (!mInitialized)
|
2005-04-04 19:08:55 +00:00
|
|
|
return;
|
|
|
|
|
2000-10-20 05:10:43 +00:00
|
|
|
// shut everything down
|
|
|
|
XCloseDisplay(mDisplay);
|
|
|
|
mDisplay = 0;
|
2011-10-17 14:59:28 +00:00
|
|
|
mInitialized = false;
|
2001-12-28 22:17:20 +00:00
|
|
|
if (mLockData) {
|
|
|
|
free(mLockData);
|
|
|
|
mLockData = 0;
|
|
|
|
}
|
2000-10-20 05:10:43 +00:00
|
|
|
}
|
|
|
|
|
2005-04-04 19:08:55 +00:00
|
|
|
nsresult
|
2004-04-08 14:01:17 +00:00
|
|
|
XRemoteClient::SendCommand (const char *aProgram, const char *aUsername,
|
|
|
|
const char *aProfile, const char *aCommand,
|
2007-02-09 01:33:26 +00:00
|
|
|
const char* aDesktopStartupID,
|
2011-09-29 06:19:26 +00:00
|
|
|
char **aResponse, bool *aWindowFound)
|
2000-10-20 05:10:43 +00:00
|
|
|
{
|
2003-11-21 00:09:50 +00:00
|
|
|
PR_LOG(sRemoteLm, PR_LOG_DEBUG, ("XRemoteClient::SendCommand"));
|
|
|
|
|
2009-09-02 20:47:44 +00:00
|
|
|
return SendCommandInternal(aProgram, aUsername, aProfile,
|
2012-07-30 14:20:58 +00:00
|
|
|
aCommand, 0, nullptr,
|
2009-09-02 20:47:44 +00:00
|
|
|
aDesktopStartupID,
|
|
|
|
aResponse, aWindowFound);
|
2000-10-20 05:10:43 +00:00
|
|
|
}
|
|
|
|
|
2005-04-04 19:08:55 +00:00
|
|
|
nsresult
|
|
|
|
XRemoteClient::SendCommandLine (const char *aProgram, const char *aUsername,
|
|
|
|
const char *aProfile,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t argc, char **argv,
|
2007-02-09 01:33:26 +00:00
|
|
|
const char* aDesktopStartupID,
|
2011-09-29 06:19:26 +00:00
|
|
|
char **aResponse, bool *aWindowFound)
|
2005-04-04 19:08:55 +00:00
|
|
|
{
|
|
|
|
PR_LOG(sRemoteLm, PR_LOG_DEBUG, ("XRemoteClient::SendCommandLine"));
|
|
|
|
|
2009-09-02 20:47:44 +00:00
|
|
|
return SendCommandInternal(aProgram, aUsername, aProfile,
|
2012-07-30 14:20:58 +00:00
|
|
|
nullptr, argc, argv,
|
2009-09-02 20:47:44 +00:00
|
|
|
aDesktopStartupID,
|
|
|
|
aResponse, aWindowFound);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
HandleBadWindow(Display *display, XErrorEvent *event)
|
|
|
|
{
|
|
|
|
if (event->error_code == BadWindow) {
|
2011-10-17 14:59:28 +00:00
|
|
|
sGotBadWindow = true;
|
2009-09-02 20:47:44 +00:00
|
|
|
return 0; // ignored
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return (*sOldHandler)(display, event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
XRemoteClient::SendCommandInternal(const char *aProgram, const char *aUsername,
|
|
|
|
const char *aProfile, const char *aCommand,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t argc, char **argv,
|
2009-09-02 20:47:44 +00:00
|
|
|
const char* aDesktopStartupID,
|
2011-09-29 06:19:26 +00:00
|
|
|
char **aResponse, bool *aWindowFound)
|
2009-09-02 20:47:44 +00:00
|
|
|
{
|
2011-10-17 14:59:28 +00:00
|
|
|
*aWindowFound = false;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool isCommandLine = !aCommand;
|
2009-09-02 20:47:44 +00:00
|
|
|
|
|
|
|
// FindBestWindow() iterates down the window hierarchy, so catch X errors
|
|
|
|
// when windows get destroyed before being accessed.
|
|
|
|
sOldHandler = XSetErrorHandler(HandleBadWindow);
|
2005-04-04 19:08:55 +00:00
|
|
|
|
2009-09-02 20:47:44 +00:00
|
|
|
Window w = FindBestWindow(aProgram, aUsername, aProfile, isCommandLine);
|
2005-04-04 19:08:55 +00:00
|
|
|
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
if (w) {
|
|
|
|
// ok, let the caller know that we at least found a window.
|
2011-10-17 14:59:28 +00:00
|
|
|
*aWindowFound = true;
|
2005-04-04 19:08:55 +00:00
|
|
|
|
2009-09-02 20:47:44 +00:00
|
|
|
// Ignore BadWindow errors up to this point. The last request from
|
|
|
|
// FindBestWindow() was a synchronous XGetWindowProperty(), so no need to
|
|
|
|
// Sync. Leave the error handler installed to detect if w gets destroyed.
|
2011-10-17 14:59:28 +00:00
|
|
|
sGotBadWindow = false;
|
2009-09-02 20:47:44 +00:00
|
|
|
|
2005-04-04 19:08:55 +00:00
|
|
|
// make sure we get the right events on that window
|
|
|
|
XSelectInput(mDisplay, w,
|
|
|
|
(PropertyChangeMask|StructureNotifyMask));
|
2009-09-02 20:47:44 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool destroyed = false;
|
2005-04-04 19:08:55 +00:00
|
|
|
|
|
|
|
// get the lock on the window
|
|
|
|
rv = GetLock(w, &destroyed);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
// send our command
|
2009-09-02 20:47:44 +00:00
|
|
|
if (isCommandLine) {
|
|
|
|
rv = DoSendCommandLine(w, argc, argv, aDesktopStartupID, aResponse,
|
|
|
|
&destroyed);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rv = DoSendCommand(w, aCommand, aDesktopStartupID, aResponse,
|
|
|
|
&destroyed);
|
|
|
|
}
|
2005-04-04 19:08:55 +00:00
|
|
|
|
|
|
|
// if the window was destroyed, don't bother trying to free the
|
|
|
|
// lock.
|
|
|
|
if (!destroyed)
|
|
|
|
FreeLock(w); // doesn't really matter what this returns
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-02 20:47:44 +00:00
|
|
|
XSetErrorHandler(sOldHandler);
|
|
|
|
|
|
|
|
PR_LOG(sRemoteLm, PR_LOG_DEBUG, ("SendCommandInternal returning 0x%x\n", rv));
|
2005-04-04 19:08:55 +00:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2001-09-11 01:36:19 +00:00
|
|
|
Window
|
|
|
|
XRemoteClient::CheckWindow(Window aWindow)
|
|
|
|
{
|
|
|
|
Atom type = None;
|
|
|
|
int format;
|
|
|
|
unsigned long nitems, bytesafter;
|
|
|
|
unsigned char *data;
|
|
|
|
Window innerWindow;
|
|
|
|
|
|
|
|
XGetWindowProperty(mDisplay, aWindow, mMozWMStateAtom,
|
|
|
|
0, 0, False, AnyPropertyType,
|
|
|
|
&type, &format, &nitems, &bytesafter, &data);
|
|
|
|
|
2005-08-19 15:15:34 +00:00
|
|
|
if (type) {
|
|
|
|
XFree(data);
|
2001-09-11 01:36:19 +00:00
|
|
|
return aWindow;
|
2005-08-19 15:15:34 +00:00
|
|
|
}
|
2001-09-11 01:36:19 +00:00
|
|
|
|
|
|
|
// didn't find it here so check the children of this window
|
|
|
|
innerWindow = CheckChildren(aWindow);
|
|
|
|
|
|
|
|
if (innerWindow)
|
|
|
|
return innerWindow;
|
|
|
|
|
|
|
|
return aWindow;
|
|
|
|
}
|
|
|
|
|
|
|
|
Window
|
|
|
|
XRemoteClient::CheckChildren(Window aWindow)
|
|
|
|
{
|
|
|
|
Window root, parent;
|
|
|
|
Window *children;
|
|
|
|
unsigned int nchildren;
|
|
|
|
unsigned int i;
|
|
|
|
Atom type = None;
|
|
|
|
int format;
|
|
|
|
unsigned long nitems, after;
|
|
|
|
unsigned char *data;
|
|
|
|
Window retval = None;
|
|
|
|
|
|
|
|
if (!XQueryTree(mDisplay, aWindow, &root, &parent, &children,
|
|
|
|
&nchildren))
|
|
|
|
return None;
|
|
|
|
|
|
|
|
// scan the list first before recursing into the list of windows
|
|
|
|
// which can get quite deep.
|
|
|
|
for (i=0; !retval && (i < nchildren); i++) {
|
|
|
|
XGetWindowProperty(mDisplay, children[i], mMozWMStateAtom,
|
|
|
|
0, 0, False, AnyPropertyType, &type, &format,
|
|
|
|
&nitems, &after, &data);
|
2005-08-19 15:15:34 +00:00
|
|
|
if (type) {
|
|
|
|
XFree(data);
|
2001-09-11 01:36:19 +00:00
|
|
|
retval = children[i];
|
2005-08-19 15:15:34 +00:00
|
|
|
}
|
2001-09-11 01:36:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// otherwise recurse into the list
|
|
|
|
for (i=0; !retval && (i < nchildren); i++) {
|
|
|
|
retval = CheckChildren(children[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (children)
|
|
|
|
XFree((char *)children);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2000-10-20 05:10:43 +00:00
|
|
|
nsresult
|
2011-09-29 06:19:26 +00:00
|
|
|
XRemoteClient::GetLock(Window aWindow, bool *aDestroyed)
|
2000-10-20 05:10:43 +00:00
|
|
|
{
|
2011-09-29 06:19:26 +00:00
|
|
|
bool locked = false;
|
|
|
|
bool waited = false;
|
2011-10-17 14:59:28 +00:00
|
|
|
*aDestroyed = false;
|
2000-10-20 05:10:43 +00:00
|
|
|
|
2009-09-02 20:47:44 +00:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
2001-12-28 22:17:20 +00:00
|
|
|
if (!mLockData) {
|
2000-10-20 05:10:43 +00:00
|
|
|
|
2001-12-28 22:17:20 +00:00
|
|
|
char pidstr[32];
|
|
|
|
char sysinfobuf[SYS_INFO_BUFFER_LENGTH];
|
|
|
|
PR_snprintf(pidstr, sizeof(pidstr), "pid%d@", getpid());
|
2000-10-20 05:10:43 +00:00
|
|
|
PRStatus status;
|
|
|
|
status = PR_GetSystemInfo(PR_SI_HOSTNAME, sysinfobuf,
|
|
|
|
SYS_INFO_BUFFER_LENGTH);
|
|
|
|
if (status != PR_SUCCESS) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2001-12-28 22:17:20 +00:00
|
|
|
|
|
|
|
// allocate enough space for the string plus the terminating
|
|
|
|
// char
|
|
|
|
mLockData = (char *)malloc(strlen(pidstr) + strlen(sysinfobuf) + 1);
|
|
|
|
if (!mLockData)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
strcpy(mLockData, pidstr);
|
|
|
|
if (!strcat(mLockData, sysinfobuf))
|
|
|
|
return NS_ERROR_FAILURE;
|
2000-10-20 05:10:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
do {
|
|
|
|
int result;
|
|
|
|
Atom actual_type;
|
|
|
|
int actual_format;
|
|
|
|
unsigned long nitems, bytes_after;
|
|
|
|
unsigned char *data = 0;
|
|
|
|
|
|
|
|
XGrabServer(mDisplay);
|
|
|
|
|
|
|
|
result = XGetWindowProperty (mDisplay, aWindow, mMozLockAtom,
|
|
|
|
0, (65536 / sizeof (long)),
|
|
|
|
False, /* don't delete */
|
|
|
|
XA_STRING,
|
|
|
|
&actual_type, &actual_format,
|
|
|
|
&nitems, &bytes_after,
|
|
|
|
&data);
|
2009-09-02 20:47:44 +00:00
|
|
|
|
|
|
|
// aWindow may have been destroyed before XSelectInput was processed, in
|
|
|
|
// which case there may not be any DestroyNotify event in the queue to
|
|
|
|
// tell us. XGetWindowProperty() was synchronous so error responses have
|
|
|
|
// now been processed, setting sGotBadWindow.
|
|
|
|
if (sGotBadWindow) {
|
2011-10-17 14:59:28 +00:00
|
|
|
*aDestroyed = true;
|
2009-09-02 20:47:44 +00:00
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
else if (result != Success || actual_type == None) {
|
2000-10-20 05:10:43 +00:00
|
|
|
/* It's not now locked - lock it. */
|
|
|
|
XChangeProperty (mDisplay, aWindow, mMozLockAtom, XA_STRING, 8,
|
|
|
|
PropModeReplace,
|
2001-12-28 22:17:20 +00:00
|
|
|
(unsigned char *)mLockData,
|
|
|
|
strlen(mLockData));
|
2000-10-20 05:10:43 +00:00
|
|
|
locked = True;
|
|
|
|
}
|
|
|
|
|
|
|
|
XUngrabServer(mDisplay);
|
2009-09-02 20:47:44 +00:00
|
|
|
XFlush(mDisplay); // ungrab now!
|
2000-10-20 05:10:43 +00:00
|
|
|
|
2009-09-02 20:47:44 +00:00
|
|
|
if (!locked && !NS_FAILED(rv)) {
|
2000-10-20 05:10:43 +00:00
|
|
|
/* We tried to grab the lock this time, and failed because someone
|
|
|
|
else is holding it already. So, wait for a PropertyDelete event
|
|
|
|
to come in, and try again. */
|
|
|
|
PR_LOG(sRemoteLm, PR_LOG_DEBUG,
|
|
|
|
("window 0x%x is locked by %s; waiting...\n",
|
|
|
|
(unsigned int) aWindow, data));
|
|
|
|
waited = True;
|
|
|
|
while (1) {
|
|
|
|
XEvent event;
|
|
|
|
int select_retval;
|
2001-07-16 11:36:06 +00:00
|
|
|
fd_set select_set;
|
2000-10-20 05:10:43 +00:00
|
|
|
struct timeval delay;
|
|
|
|
delay.tv_sec = 10;
|
|
|
|
delay.tv_usec = 0;
|
|
|
|
|
|
|
|
FD_ZERO(&select_set);
|
|
|
|
// add the x event queue to the select set
|
|
|
|
FD_SET(ConnectionNumber(mDisplay), &select_set);
|
|
|
|
select_retval = select(ConnectionNumber(mDisplay) + 1,
|
2013-10-28 14:05:51 +00:00
|
|
|
&select_set, nullptr, nullptr, &delay);
|
2000-10-20 05:10:43 +00:00
|
|
|
// did we time out?
|
|
|
|
if (select_retval == 0) {
|
|
|
|
PR_LOG(sRemoteLm, PR_LOG_DEBUG, ("timed out waiting for window\n"));
|
2009-09-02 20:47:44 +00:00
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
break;
|
2000-10-20 05:10:43 +00:00
|
|
|
}
|
|
|
|
PR_LOG(sRemoteLm, PR_LOG_DEBUG, ("xevent...\n"));
|
|
|
|
XNextEvent (mDisplay, &event);
|
|
|
|
if (event.xany.type == DestroyNotify &&
|
|
|
|
event.xdestroywindow.window == aWindow) {
|
2011-10-17 14:59:28 +00:00
|
|
|
*aDestroyed = true;
|
2009-09-02 20:47:44 +00:00
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
break;
|
2000-10-20 05:10:43 +00:00
|
|
|
}
|
|
|
|
else if (event.xany.type == PropertyNotify &&
|
|
|
|
event.xproperty.state == PropertyDelete &&
|
|
|
|
event.xproperty.window == aWindow &&
|
|
|
|
event.xproperty.atom == mMozLockAtom) {
|
|
|
|
/* Ok! Someone deleted their lock, so now we can try
|
|
|
|
again. */
|
|
|
|
PR_LOG(sRemoteLm, PR_LOG_DEBUG,
|
|
|
|
("(0x%x unlocked, trying again...)\n",
|
|
|
|
(unsigned int) aWindow));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (data)
|
|
|
|
XFree(data);
|
2009-09-02 20:47:44 +00:00
|
|
|
} while (!locked && !NS_FAILED(rv));
|
2000-10-20 05:10:43 +00:00
|
|
|
|
2009-09-02 20:47:44 +00:00
|
|
|
if (waited && locked) {
|
2000-10-20 05:10:43 +00:00
|
|
|
PR_LOG(sRemoteLm, PR_LOG_DEBUG, ("obtained lock.\n"));
|
2009-09-02 20:47:44 +00:00
|
|
|
} else if (*aDestroyed) {
|
|
|
|
PR_LOG(sRemoteLm, PR_LOG_DEBUG,
|
|
|
|
("window 0x%x unexpectedly destroyed.\n",
|
|
|
|
(unsigned int) aWindow));
|
2000-10-20 05:10:43 +00:00
|
|
|
}
|
|
|
|
|
2009-09-02 20:47:44 +00:00
|
|
|
return rv;
|
2000-10-20 05:10:43 +00:00
|
|
|
}
|
|
|
|
|
2004-04-08 14:01:17 +00:00
|
|
|
Window
|
|
|
|
XRemoteClient::FindBestWindow(const char *aProgram, const char *aUsername,
|
2005-04-04 19:08:55 +00:00
|
|
|
const char *aProfile,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool aSupportsCommandLine)
|
2004-04-08 14:01:17 +00:00
|
|
|
{
|
|
|
|
Window root = RootWindowOfScreen(DefaultScreenOfDisplay(mDisplay));
|
|
|
|
Window bestWindow = 0;
|
|
|
|
Window root2, parent, *kids;
|
|
|
|
unsigned int nkids;
|
|
|
|
|
|
|
|
// Get a list of the children of the root window, walk the list
|
|
|
|
// looking for the best window that fits the criteria.
|
|
|
|
if (!XQueryTree(mDisplay, root, &root2, &parent, &kids, &nkids)) {
|
|
|
|
PR_LOG(sRemoteLm, PR_LOG_DEBUG,
|
|
|
|
("XQueryTree failed in XRemoteClient::FindBestWindow"));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(kids && nkids)) {
|
|
|
|
PR_LOG(sRemoteLm, PR_LOG_DEBUG, ("root window has no children"));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We'll walk the list of windows looking for a window that best
|
|
|
|
// fits the criteria here.
|
|
|
|
|
2008-12-04 16:09:53 +00:00
|
|
|
for (unsigned int i = 0; i < nkids; i++) {
|
2004-04-08 14:01:17 +00:00
|
|
|
Atom type;
|
|
|
|
int format;
|
|
|
|
unsigned long nitems, bytesafter;
|
|
|
|
unsigned char *data_return = 0;
|
|
|
|
Window w;
|
|
|
|
w = kids[i];
|
|
|
|
// find the inner window with WM_STATE on it
|
|
|
|
w = CheckWindow(w);
|
|
|
|
|
|
|
|
int status = XGetWindowProperty(mDisplay, w, mMozVersionAtom,
|
|
|
|
0, (65536 / sizeof (long)),
|
|
|
|
False, XA_STRING,
|
|
|
|
&type, &format, &nitems, &bytesafter,
|
|
|
|
&data_return);
|
|
|
|
|
|
|
|
if (!data_return)
|
|
|
|
continue;
|
|
|
|
|
2012-08-09 07:09:42 +00:00
|
|
|
double version = PR_strtod((char*) data_return, nullptr);
|
2004-04-08 14:01:17 +00:00
|
|
|
XFree(data_return);
|
2005-04-04 19:08:55 +00:00
|
|
|
|
|
|
|
if (aSupportsCommandLine && !(version >= 5.1 && version < 6))
|
|
|
|
continue;
|
|
|
|
|
2004-04-08 14:01:17 +00:00
|
|
|
data_return = 0;
|
|
|
|
|
|
|
|
if (status != Success || type == None)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// If someone passed in a program name, check it against this one
|
|
|
|
// unless it's "any" in which case, we don't care. If someone did
|
|
|
|
// pass in a program name and this window doesn't support that
|
|
|
|
// protocol, we don't include it in our list.
|
|
|
|
if (aProgram && strcmp(aProgram, "any")) {
|
|
|
|
status = XGetWindowProperty(mDisplay, w, mMozProgramAtom,
|
|
|
|
0, (65536 / sizeof(long)),
|
|
|
|
False, XA_STRING,
|
|
|
|
&type, &format, &nitems, &bytesafter,
|
|
|
|
&data_return);
|
|
|
|
|
|
|
|
// If the return name is not the same as what someone passed in,
|
|
|
|
// we don't want this window.
|
|
|
|
if (data_return) {
|
|
|
|
if (strcmp(aProgram, (const char *)data_return)) {
|
|
|
|
XFree(data_return);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is actually the success condition.
|
|
|
|
XFree(data_return);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Doesn't support the protocol, even though the user
|
|
|
|
// requested it. So we're not going to use this window.
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check to see if it has the user atom on that window. If there
|
|
|
|
// is then we need to make sure that it matches what we have.
|
|
|
|
const char *username;
|
|
|
|
if (aUsername) {
|
|
|
|
username = aUsername;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
username = PR_GetEnv("LOGNAME");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (username) {
|
|
|
|
status = XGetWindowProperty(mDisplay, w, mMozUserAtom,
|
|
|
|
0, (65536 / sizeof(long)),
|
|
|
|
False, XA_STRING,
|
|
|
|
&type, &format, &nitems, &bytesafter,
|
|
|
|
&data_return);
|
|
|
|
|
|
|
|
// if there's a username compare it with what we have
|
|
|
|
if (data_return) {
|
|
|
|
// If the IDs aren't equal, we don't want this window.
|
|
|
|
if (strcmp(username, (const char *)data_return)) {
|
|
|
|
XFree(data_return);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
XFree(data_return);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check to see if there's a profile name on this window. If
|
|
|
|
// there is, then we need to make sure it matches what someone
|
|
|
|
// passed in.
|
|
|
|
if (aProfile) {
|
|
|
|
status = XGetWindowProperty(mDisplay, w, mMozProfileAtom,
|
|
|
|
0, (65536 / sizeof(long)),
|
|
|
|
False, XA_STRING,
|
|
|
|
&type, &format, &nitems, &bytesafter,
|
|
|
|
&data_return);
|
|
|
|
|
|
|
|
// If there's a profile compare it with what we have
|
|
|
|
if (data_return) {
|
|
|
|
// If the profiles aren't equal, we don't want this window.
|
|
|
|
if (strcmp(aProfile, (const char *)data_return)) {
|
|
|
|
XFree(data_return);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
XFree(data_return);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-04 19:08:55 +00:00
|
|
|
// Check to see if the window supports the new command-line passing
|
|
|
|
// protocol, if that is requested.
|
|
|
|
|
2008-12-04 16:09:53 +00:00
|
|
|
// If we got this far, this is the best window. It passed
|
2004-04-08 14:01:17 +00:00
|
|
|
// all the tests.
|
|
|
|
bestWindow = w;
|
2008-12-04 16:09:53 +00:00
|
|
|
break;
|
2004-04-08 14:01:17 +00:00
|
|
|
}
|
|
|
|
|
2005-08-19 15:15:34 +00:00
|
|
|
if (kids)
|
|
|
|
XFree((char *) kids);
|
|
|
|
|
2004-04-08 14:01:17 +00:00
|
|
|
return bestWindow;
|
|
|
|
}
|
|
|
|
|
2000-10-20 05:10:43 +00:00
|
|
|
nsresult
|
|
|
|
XRemoteClient::FreeLock(Window aWindow)
|
|
|
|
{
|
|
|
|
int result;
|
|
|
|
Atom actual_type;
|
|
|
|
int actual_format;
|
|
|
|
unsigned long nitems, bytes_after;
|
|
|
|
unsigned char *data = 0;
|
|
|
|
|
|
|
|
result = XGetWindowProperty(mDisplay, aWindow, mMozLockAtom,
|
2004-04-08 14:01:17 +00:00
|
|
|
0, (65536 / sizeof(long)),
|
|
|
|
True, /* atomic delete after */
|
|
|
|
XA_STRING,
|
|
|
|
&actual_type, &actual_format,
|
|
|
|
&nitems, &bytes_after,
|
|
|
|
&data);
|
2000-10-20 05:10:43 +00:00
|
|
|
if (result != Success) {
|
2004-04-08 14:01:17 +00:00
|
|
|
PR_LOG(sRemoteLm, PR_LOG_DEBUG,
|
|
|
|
("unable to read and delete " MOZILLA_LOCK_PROP
|
|
|
|
" property\n"));
|
|
|
|
return NS_ERROR_FAILURE;
|
2000-10-20 05:10:43 +00:00
|
|
|
}
|
|
|
|
else if (!data || !*data){
|
2004-04-08 14:01:17 +00:00
|
|
|
PR_LOG(sRemoteLm, PR_LOG_DEBUG,
|
|
|
|
("invalid data on " MOZILLA_LOCK_PROP
|
|
|
|
" of window 0x%x.\n",
|
|
|
|
(unsigned int) aWindow));
|
|
|
|
return NS_ERROR_FAILURE;
|
2000-10-20 05:10:43 +00:00
|
|
|
}
|
2001-12-28 22:17:20 +00:00
|
|
|
else if (strcmp((char *)data, mLockData)) {
|
2004-04-08 14:01:17 +00:00
|
|
|
PR_LOG(sRemoteLm, PR_LOG_DEBUG,
|
|
|
|
(MOZILLA_LOCK_PROP " was stolen! Expected \"%s\", saw \"%s\"!\n",
|
|
|
|
mLockData, data));
|
|
|
|
return NS_ERROR_FAILURE;
|
2000-10-20 05:10:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (data)
|
2004-04-08 14:01:17 +00:00
|
|
|
XFree(data);
|
2000-10-20 05:10:43 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
XRemoteClient::DoSendCommand(Window aWindow, const char *aCommand,
|
2007-02-09 01:33:26 +00:00
|
|
|
const char* aDesktopStartupID,
|
2011-09-29 06:19:26 +00:00
|
|
|
char **aResponse, bool *aDestroyed)
|
2000-10-20 05:10:43 +00:00
|
|
|
{
|
2011-10-17 14:59:28 +00:00
|
|
|
*aDestroyed = false;
|
2000-10-20 05:10:43 +00:00
|
|
|
|
|
|
|
PR_LOG(sRemoteLm, PR_LOG_DEBUG,
|
2005-04-04 19:08:55 +00:00
|
|
|
("(writing " MOZILLA_COMMAND_PROP " \"%s\" to 0x%x)\n",
|
|
|
|
aCommand, (unsigned int) aWindow));
|
2000-10-20 05:10:43 +00:00
|
|
|
|
2007-02-09 01:33:26 +00:00
|
|
|
// We add the DESKTOP_STARTUP_ID setting as an extra line of
|
|
|
|
// the command string. Firefox ignores all lines but the first.
|
|
|
|
static char desktopStartupPrefix[] = "\nDESKTOP_STARTUP_ID=";
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t len = strlen(aCommand);
|
2007-02-09 01:33:26 +00:00
|
|
|
if (aDesktopStartupID) {
|
|
|
|
len += sizeof(desktopStartupPrefix) - 1 + strlen(aDesktopStartupID);
|
|
|
|
}
|
|
|
|
char* buffer = (char*)malloc(len + 1);
|
|
|
|
if (!buffer)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
strcpy(buffer, aCommand);
|
|
|
|
if (aDesktopStartupID) {
|
|
|
|
strcat(buffer, desktopStartupPrefix);
|
|
|
|
strcat(buffer, aDesktopStartupID);
|
|
|
|
}
|
|
|
|
|
2000-10-20 05:10:43 +00:00
|
|
|
XChangeProperty (mDisplay, aWindow, mMozCommandAtom, XA_STRING, 8,
|
2007-02-09 01:33:26 +00:00
|
|
|
PropModeReplace, (unsigned char *)buffer, len);
|
|
|
|
|
|
|
|
free(buffer);
|
2005-04-04 19:08:55 +00:00
|
|
|
|
|
|
|
if (!WaitForResponse(aWindow, aResponse, aDestroyed, mMozCommandAtom))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* like strcpy, but return the char after the final null */
|
|
|
|
static char*
|
2007-02-09 01:33:26 +00:00
|
|
|
estrcpy(const char* s, char* d)
|
2005-04-04 19:08:55 +00:00
|
|
|
{
|
|
|
|
while (*s)
|
|
|
|
*d++ = *s++;
|
|
|
|
|
|
|
|
*d++ = '\0';
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-08-22 15:56:38 +00:00
|
|
|
XRemoteClient::DoSendCommandLine(Window aWindow, int32_t argc, char **argv,
|
2007-02-09 01:33:26 +00:00
|
|
|
const char* aDesktopStartupID,
|
2011-09-29 06:19:26 +00:00
|
|
|
char **aResponse, bool *aDestroyed)
|
2005-04-04 19:08:55 +00:00
|
|
|
{
|
2011-10-17 14:59:28 +00:00
|
|
|
*aDestroyed = false;
|
2005-04-04 19:08:55 +00:00
|
|
|
|
|
|
|
char cwdbuf[MAX_PATH];
|
|
|
|
if (!getcwd(cwdbuf, MAX_PATH))
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
// the commandline property is constructed as an array of int32_t
|
2005-04-04 19:08:55 +00:00
|
|
|
// followed by a series of null-terminated strings:
|
|
|
|
//
|
|
|
|
// [argc][offsetargv0][offsetargv1...]<workingdir>\0<argv[0]>\0argv[1]...\0
|
|
|
|
// (offset is from the beginning of the buffer)
|
|
|
|
|
2007-02-09 01:33:26 +00:00
|
|
|
static char desktopStartupPrefix[] = " DESKTOP_STARTUP_ID=";
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t argvlen = strlen(cwdbuf);
|
2008-12-04 16:09:53 +00:00
|
|
|
for (int i = 0; i < argc; ++i) {
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t len = strlen(argv[i]);
|
2007-02-09 01:33:26 +00:00
|
|
|
if (i == 0 && aDesktopStartupID) {
|
|
|
|
len += sizeof(desktopStartupPrefix) - 1 + strlen(aDesktopStartupID);
|
|
|
|
}
|
|
|
|
argvlen += len;
|
|
|
|
}
|
2005-04-04 19:08:55 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t* buffer = (int32_t*) malloc(argvlen + argc + 1 +
|
|
|
|
sizeof(int32_t) * (argc + 1));
|
2005-04-04 19:08:55 +00:00
|
|
|
if (!buffer)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
2005-12-26 03:10:35 +00:00
|
|
|
buffer[0] = TO_LITTLE_ENDIAN32(argc);
|
2005-04-04 19:08:55 +00:00
|
|
|
|
|
|
|
char *bufend = (char*) (buffer + argc + 1);
|
|
|
|
|
|
|
|
bufend = estrcpy(cwdbuf, bufend);
|
|
|
|
|
|
|
|
for (int i = 0; i < argc; ++i) {
|
2005-12-26 03:10:35 +00:00
|
|
|
buffer[i + 1] = TO_LITTLE_ENDIAN32(bufend - ((char*) buffer));
|
2005-04-04 19:08:55 +00:00
|
|
|
bufend = estrcpy(argv[i], bufend);
|
2007-02-09 01:33:26 +00:00
|
|
|
if (i == 0 && aDesktopStartupID) {
|
|
|
|
bufend = estrcpy(desktopStartupPrefix, bufend - 1);
|
|
|
|
bufend = estrcpy(aDesktopStartupID, bufend - 1);
|
|
|
|
}
|
2005-04-04 19:08:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG_bsmedberg
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t debug_argc = TO_LITTLE_ENDIAN32(*buffer);
|
2005-04-04 19:08:55 +00:00
|
|
|
char *debug_workingdir = (char*) (buffer + argc + 1);
|
|
|
|
|
|
|
|
printf("Sending command line:\n"
|
|
|
|
" working dir: %s\n"
|
|
|
|
" argc:\t%i",
|
|
|
|
debug_workingdir,
|
|
|
|
debug_argc);
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t *debug_offset = buffer + 1;
|
2005-04-04 19:08:55 +00:00
|
|
|
for (int debug_i = 0; debug_i < debug_argc; ++debug_i)
|
|
|
|
printf(" argv[%i]:\t%s\n", debug_i,
|
2005-12-26 03:10:35 +00:00
|
|
|
((char*) buffer) + TO_LITTLE_ENDIAN32(debug_offset[debug_i]));
|
2005-04-04 19:08:55 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
XChangeProperty (mDisplay, aWindow, mMozCommandLineAtom, XA_STRING, 8,
|
|
|
|
PropModeReplace, (unsigned char *) buffer,
|
|
|
|
bufend - ((char*) buffer));
|
2007-09-04 04:13:24 +00:00
|
|
|
free(buffer);
|
2005-04-04 19:08:55 +00:00
|
|
|
|
|
|
|
if (!WaitForResponse(aWindow, aResponse, aDestroyed, mMozCommandLineAtom))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2005-04-04 19:08:55 +00:00
|
|
|
XRemoteClient::WaitForResponse(Window aWindow, char **aResponse,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool *aDestroyed, Atom aCommandAtom)
|
2005-04-04 19:08:55 +00:00
|
|
|
{
|
2011-09-29 06:19:26 +00:00
|
|
|
bool done = false;
|
|
|
|
bool accepted = false;
|
2000-10-20 05:10:43 +00:00
|
|
|
|
|
|
|
while (!done) {
|
|
|
|
XEvent event;
|
|
|
|
XNextEvent (mDisplay, &event);
|
|
|
|
if (event.xany.type == DestroyNotify &&
|
2005-04-04 19:08:55 +00:00
|
|
|
event.xdestroywindow.window == aWindow) {
|
2000-10-20 05:10:43 +00:00
|
|
|
/* Print to warn user...*/
|
|
|
|
PR_LOG(sRemoteLm, PR_LOG_DEBUG,
|
2005-04-04 19:08:55 +00:00
|
|
|
("window 0x%x was destroyed.\n",
|
|
|
|
(unsigned int) aWindow));
|
2004-04-08 14:01:17 +00:00
|
|
|
*aResponse = strdup("Window was destroyed while reading response.");
|
2011-10-17 14:59:28 +00:00
|
|
|
*aDestroyed = true;
|
|
|
|
return false;
|
2000-10-20 05:10:43 +00:00
|
|
|
}
|
|
|
|
else if (event.xany.type == PropertyNotify &&
|
2005-04-04 19:08:55 +00:00
|
|
|
event.xproperty.state == PropertyNewValue &&
|
|
|
|
event.xproperty.window == aWindow &&
|
|
|
|
event.xproperty.atom == mMozResponseAtom) {
|
2000-10-20 05:10:43 +00:00
|
|
|
Atom actual_type;
|
|
|
|
int actual_format;
|
|
|
|
unsigned long nitems, bytes_after;
|
|
|
|
unsigned char *data = 0;
|
|
|
|
Bool result;
|
|
|
|
result = XGetWindowProperty (mDisplay, aWindow, mMozResponseAtom,
|
2005-04-04 19:08:55 +00:00
|
|
|
0, (65536 / sizeof (long)),
|
|
|
|
True, /* atomic delete after */
|
|
|
|
XA_STRING,
|
|
|
|
&actual_type, &actual_format,
|
|
|
|
&nitems, &bytes_after,
|
|
|
|
&data);
|
2000-10-20 05:10:43 +00:00
|
|
|
if (result != Success) {
|
2005-04-04 19:08:55 +00:00
|
|
|
PR_LOG(sRemoteLm, PR_LOG_DEBUG,
|
|
|
|
("failed reading " MOZILLA_RESPONSE_PROP
|
|
|
|
" from window 0x%0x.\n",
|
|
|
|
(unsigned int) aWindow));
|
|
|
|
*aResponse = strdup("Internal error reading response from window.");
|
2011-10-17 14:59:28 +00:00
|
|
|
done = true;
|
2000-10-20 05:10:43 +00:00
|
|
|
}
|
|
|
|
else if (!data || strlen((char *) data) < 5) {
|
2005-04-04 19:08:55 +00:00
|
|
|
PR_LOG(sRemoteLm, PR_LOG_DEBUG,
|
|
|
|
("invalid data on " MOZILLA_RESPONSE_PROP
|
|
|
|
" property of window 0x%0x.\n",
|
|
|
|
(unsigned int) aWindow));
|
|
|
|
*aResponse = strdup("Server returned invalid data in response.");
|
2011-10-17 14:59:28 +00:00
|
|
|
done = true;
|
2000-10-20 05:10:43 +00:00
|
|
|
}
|
2005-04-04 19:08:55 +00:00
|
|
|
else if (*data == '1') { /* positive preliminary reply */
|
|
|
|
PR_LOG(sRemoteLm, PR_LOG_DEBUG, ("%s\n", data + 4));
|
|
|
|
/* keep going */
|
2011-10-17 14:59:28 +00:00
|
|
|
done = false;
|
2000-10-20 05:10:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else if (!strncmp ((char *)data, "200", 3)) { /* positive completion */
|
2005-04-04 19:08:55 +00:00
|
|
|
*aResponse = strdup((char *)data);
|
2011-10-17 14:59:28 +00:00
|
|
|
accepted = true;
|
|
|
|
done = true;
|
2000-10-20 05:10:43 +00:00
|
|
|
}
|
|
|
|
|
2005-04-04 19:08:55 +00:00
|
|
|
else if (*data == '2') { /* positive completion */
|
|
|
|
PR_LOG(sRemoteLm, PR_LOG_DEBUG, ("%s\n", data + 4));
|
|
|
|
*aResponse = strdup((char *)data);
|
2011-10-17 14:59:28 +00:00
|
|
|
accepted = true;
|
|
|
|
done = true;
|
2000-10-20 05:10:43 +00:00
|
|
|
}
|
|
|
|
|
2005-04-04 19:08:55 +00:00
|
|
|
else if (*data == '3') { /* positive intermediate reply */
|
|
|
|
PR_LOG(sRemoteLm, PR_LOG_DEBUG,
|
|
|
|
("internal error: "
|
|
|
|
"server wants more information? (%s)\n",
|
|
|
|
data));
|
|
|
|
*aResponse = strdup((char *)data);
|
2011-10-17 14:59:28 +00:00
|
|
|
done = true;
|
2000-10-20 05:10:43 +00:00
|
|
|
}
|
|
|
|
|
2005-04-04 19:08:55 +00:00
|
|
|
else if (*data == '4' || /* transient negative completion */
|
|
|
|
*data == '5') { /* permanent negative completion */
|
|
|
|
PR_LOG(sRemoteLm, PR_LOG_DEBUG, ("%s\n", data + 4));
|
|
|
|
*aResponse = strdup((char *)data);
|
2011-10-17 14:59:28 +00:00
|
|
|
done = true;
|
2000-10-20 05:10:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
2005-04-04 19:08:55 +00:00
|
|
|
PR_LOG(sRemoteLm, PR_LOG_DEBUG,
|
|
|
|
("unrecognised " MOZILLA_RESPONSE_PROP
|
|
|
|
" from window 0x%x: %s\n",
|
|
|
|
(unsigned int) aWindow, data));
|
|
|
|
*aResponse = strdup((char *)data);
|
2011-10-17 14:59:28 +00:00
|
|
|
done = true;
|
2000-10-20 05:10:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (data)
|
2005-04-04 19:08:55 +00:00
|
|
|
XFree(data);
|
2000-10-20 05:10:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else if (event.xany.type == PropertyNotify &&
|
2005-04-04 19:08:55 +00:00
|
|
|
event.xproperty.window == aWindow &&
|
|
|
|
event.xproperty.state == PropertyDelete &&
|
|
|
|
event.xproperty.atom == aCommandAtom) {
|
2000-10-20 05:10:43 +00:00
|
|
|
PR_LOG(sRemoteLm, PR_LOG_DEBUG,
|
2005-04-04 19:08:55 +00:00
|
|
|
("(server 0x%x has accepted "
|
|
|
|
MOZILLA_COMMAND_PROP ".)\n",
|
|
|
|
(unsigned int) aWindow));
|
2000-10-20 05:10:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2005-04-04 19:08:55 +00:00
|
|
|
return accepted;
|
2000-10-20 05:10:43 +00:00
|
|
|
}
|