csfindNX.c revision 824
/*
* csfindNX.c -- DPSCAP client Xlib extension hookup
*
* (c) Copyright 1992-1994 Adobe Systems Incorporated.
* All rights reserved.
*
* Permission to use, copy, modify, distribute, and sublicense this software
* and its documentation for any purpose and without fee is hereby granted,
* provided that the above copyright notices appear in all copies and that
* both those copyright notices and this permission notice appear in
* supporting documentation and that the name of Adobe Systems Incorporated
* not be used in advertising or publicity pertaining to distribution of the
* software without specific, written prior permission. No trademark license
* to use the Adobe trademarks is hereby granted. If the Adobe trademark
* "Display PostScript"(tm) is used to describe this software, its
* functionality or for any other purpose, such use shall be limited to a
* statement that this software works in conjunction with the Display
* PostScript system. Proper trademark attribution to reflect Adobe's
* ownership of the trademark shall be given whenever any such reference to
* the Display PostScript system is made.
*
* ADOBE MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF THE SOFTWARE FOR
* ANY PURPOSE. IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
* ADOBE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
* IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NON- INFRINGEMENT OF THIRD PARTY RIGHTS. IN NO EVENT SHALL ADOBE BE LIABLE
* TO YOU OR ANY OTHER PARTY FOR ANY SPECIAL, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER WHETHER IN AN ACTION OF CONTRACT,
* NEGLIGENCE, STRICT LIABILITY OR ANY OTHER ACTION ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ADOBE WILL NOT
* PROVIDE ANY TRAINING OR OTHER SUPPORT FOR THE SOFTWARE.
*
* Adobe, PostScript, and Display PostScript are trademarks of Adobe Systems
* Incorporated which may be registered in certain jurisdictions
*
* Author: Adobe Systems Incorporated
*/
/* $XFree86: xc/lib/dps/csfindNX.c,v 1.7tsi Exp $ */
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h> /* getuid() */
#include <string.h>
#include <pwd.h>
#include <X11/Xresource.h>
#include "csfindNX.h"
#include "dpsNXprops.h"
#include "Xlibnet.h"
#include "DPS/dpsXclient.h"
#include "DPS/dpsNXargs.h"
#include "dpsassert.h"
#include "cslibint.h"
/* ---Defines--- */
#define CANTSTARTAGENT "Unable to start agent.\n"
/* ---Types--- */
typedef struct {
int willingness;
} Agent, *AgentIdList;
/* ---Globals--- */
static char *XDPSLNXHost = NULL;
static int XDPSLNXPort = 0; /* default port to be used */
static int XDPSLNXTrans = XDPSNX_TRANS_UNIX;
static int gXDPSNXLaunchedAgentTrans = XDPSNX_USE_BEST;
static int gXDPSNXLaunchedAgentPort = XDPSNX_USE_BEST;
unsigned char gXDPSNXErrorCode;
extern int gNXSndBufSize; /* Output buffer size, zero means default */
static char *getHomeDir(char *);
/* ---Private Functions--- */
static int
{
return 0;
}
static int
Window w,
unsigned long *nitems, /* IN: if non-null then RETURN val */
char **data) /* RETURN */
{
int actual_format;
unsigned long actual_number;
unsigned long remaining;
&& (actual_type == type)) {
return(Success);
} else {
if (*nitems != 0) { /* if data returned, clean up */
*nitems = 0;
}
return(!Success);
}
}
/*
GetAgentIdList returns a list of agents advertising on the passed display (dpy),
and it returns the number of agents in the list in the parameter nAgents.
The returned list is sorted in most to least willing order.
GetAgentIdList assumes that it has exclusive access to the server associated with
dpy (ie. it assumes that the caller has done an XGrabServer).
*/
static AgentIdList
unsigned long *nAgents) /* RETURN: number of agents in list */
{
unsigned long i, current;
goto failed;
}
goto failed;
}
if ((agentList = (AgentIdList)
goto failed;
/* let's go through the list and figure out which servers are okay */
current = 0;
for (i=0; i < *nAgents; i++) {
unsigned long len;
int *agentWillingness;
unsigned long k;
for (k=0; k < i; k++) /* Search for duplicate ids */
break;
}
if (k == i) { /* No duplicate ids */
!= Success) {
/* Assume that Agent i is dead... */
/* reap the agent */
} else {
unsigned long j = 0;
/* insert the agents into agentList in "most to least willing" order */
j++;
if (j < current)
}
}
}
(void) XSetErrorHandler(oldErrorHandler);
if (current > 0) { /* are there living ones? */
/* write the list back out onto the root window */
} else {
goto failed;
}
}
return(agentList);
*nAgents = 0;
return(NULL);
}
static int
char *licenseMethod,
char **host,
int *transport,
int *port)
{
unsigned long nAgents = 0;
unsigned long i = 0;
#ifdef DPSLNKL
extern unsigned ANXKFunc();
#endif /* DPSLNKL */
goto cleanup;
/* NOTE: agentList was sorted most to least willing by GetAgentIdList */
goto cleanup;
}
#ifdef DPSLNKL
/* Masterkey bypass code */
if (ANXKFunc() != 0) {
/* We have a willing agent and the client has masterkeys so... */
} else /* Search for appropriate agent */
#endif /* DPSLNKL */
{
/* need to get licensing info from dpy */
char openLicenseString[256];
if (licenseMethod != NULL)
else
for (i=0;
i++) {
unsigned long nMethods;
unsigned long j;
goto cleanup;
/*
Check to see if the agent supports either our desired license method or
if it is an open service.
*/
j = 0;
while((j < nMethods)
&& (licenseMethods[j] != desiredLicenseMethod)
&& (licenseMethods[j] != openLicenseMethod)) j++;
if (j < nMethods) { /* We found one */
break;
}
(void) XFree(licenseMethods);
}
}
}
if (match) { /* We had a match on license method */
goto cleanup;
} else { /* We got one! */
}
/*
* If transport is TCP, but we are on the same host as the agent then
* trade-up to the more efficient UNIX transport...
*/
if (*transport == XDPSNX_TRANS_TCP) {
char hostname[MAXHOSTNAMELEN];
}
}
}
/*
* Exit Clauses: status inited to FAILURE. Therefore cleanup "assumes"
* a failure unless noted otherwise.
*/
(void) XUngrabServer(dpy);
return(status);
}
static int
char *string,
char **hostname, /* RETURN */
int *transport, /* RETURN */
int *port) /* RETURN */
{
int dnet = 0;
char namebuf[255];
char *p;
p = &namebuf[0];
/*
* Step 1, find the hostname. This is delimited by a required colon.
*/
for (; *p && *p != ':'; p++);
if (!*p) return(!Success); /* There must be a colon */
if (*(p+1) == ':') {
dnet++;
*(p++) = '\0';
}
*(p++) = '\0';
/*
* Step 2, get the port number. It follows the colon(s)
*/
if (*p == '\0') /* No port number specified... */
return(!Success);
/*
* Step 3, transport?
*/
if (dnet)
else { /* no hostname, so must be UNIX */
return(Success);
}
} else {
/* find the delimiting '/' */
for (p = &namebuf[0]; *p && *p != '/'; p++);
if (*p == '/') {
*p = '\0';
p++;
} else /* no transport specified */
p = &namebuf[0];
return(!Success); /* can't alloc space for hostname */
/* identify protocol */
if (dnet)
else if (transportSpecified) {
else /* assume tcp */
} else
}
return(Success);
}
static int
char **host,
int *transport,
int *port)
{
char filenamebuf[1024];
char *filename = &filenamebuf[0];
char name[255];
/* try to get application defaults file, if there is any */
/* try to merge the server defaults. if not defined then use .Xdefaults */
} else { /* use the .Xdefaults */
(void) getHomeDir(filename);
}
/* try the XENVIRONMENT file, or if not defined, then .Xdefaults */
int len;
}
/* Now that the database is built, try to extract the values we want. */
}
(void) XrmDestroyDatabase(rDB);
return(retVal);
}
static char *
getHomeDir(char *dest)
{
register char *ptr;
} else {
} else {
}
if (pw) {
} else {
*dest = ' ';
}
}
return (dest);
}
/* ---Public Functions--- */
int gForceLaunchHack = 0; /* Undocumented way to force autolaunch */
char *licenseMethod,
char **host,
int *transport,
int *port)
{
char *agentenv;
if (gForceLaunchHack)
return(findnx_not_found);
if (gWasAgentSet) { /* check if client set up host */
*host = XDPSLNXHost;
*port = XDPSLNXPort;
return(findnx_found);
/* check DPSNXHOST environment variable */
return(findnx_error);
} else return(findnx_found);
/* check advertisements... */
Success) {
return(findnx_found);
/* check XrmDatabase */
return(findnx_found);
}
/* Nada */
return(findnx_not_found);
}
{
if (arg == XDPSNX_AGENT) {
gWasAgentSet = True;
return(ParseAgentString(value,
}
else if (arg == XDPSNX_EXEC_FILE) {
return(!Success);
}
} else if (arg == XDPSNX_EXEC_ARGS) {
int i;
gXDPSNXExecArgs = (char **) Xcalloc(i, sizeof(char *));
/* copy each entry */
return(!Success);
}
} else if (arg == XDPSNX_AUTO_LAUNCH) {
} else if (arg == XDPSNX_LAUNCHED_AGENT_TRANS) {
gXDPSNXLaunchedAgentTrans = (long) value;
} else if (arg == XDPSNX_LAUNCHED_AGENT_PORT) {
gXDPSNXLaunchedAgentPort = (long) value;
} else if (arg == XDPSNX_REQUEST_XSYNC) {
return(Success);
} else if (arg == XDPSNX_REQUEST_RECONCILE) {
return(Success);
} else if (arg == XDPSNX_REQUEST_BUFFER) {
return(Success);
} else if (arg == XDPSNX_GC_UPDATES_SLOW) {
return(Success);
} else if (arg == XDPSNX_GC_UPDATES_FAST) {
return(Success);
} else if (arg == XDPSNX_SEND_BUF_SIZE) {
int i = (long)value;
}
return(Success);
}
void
{
static char agentBuffer[255];
if (arg == XDPSNX_AGENT) {
switch(XDPSLNXTrans) {
case XDPSNX_TRANS_UNIX:
break;
case XDPSNX_TRANS_TCP:
break;
case XDPSNX_TRANS_DECNET:
break;
default:
agentBuffer[0] = '\0';
break;
}
(void) strcat(agentBuffer,
*value = (void *) agentBuffer;
}
else if (arg == XDPSNX_EXEC_FILE) {
*value = (void *) gXDPSNXExecObj;
} else if (arg == XDPSNX_EXEC_ARGS) {
*value = (void *) gXDPSNXExecArgs;
} else if (arg == XDPSNX_AUTO_LAUNCH) {
*value = (void *) (long)gXDPSNXAutoLaunch;
} else if (arg == XDPSNX_LAUNCHED_AGENT_TRANS) {
*value = (void *) (long)gXDPSNXLaunchedAgentTrans;
} else if (arg == XDPSNX_LAUNCHED_AGENT_PORT) {
*value = (void *) (long)gXDPSNXLaunchedAgentPort;
}
}