⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 appgroup.c

📁 远程桌面连接工具
💻 C
📖 第 1 页 / 共 2 页
字号:
/*Copyright (c) 1996  X ConsortiumPermission is hereby granted, free of charge, to any person obtaininga copy of this software and associated documentation files (the"Software"), to deal in the Software without restriction, includingwithout limitation the rights to use, copy, modify, merge, publish,distribute, sublicense, and sell copies of the Software, and topermit persons to whom the Software is furnished to do so, subject tothe following conditions:The above copyright notice and this permission notice shall be includedin all copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESSOR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OFMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OROTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OROTHER DEALINGS IN THE SOFTWARE.Except as contained in this notice, the name of the X Consortium shallnot be used in advertising or otherwise to promote the sale, use orother dealings in this Software without prior written authorizationfrom the X Consortium.*//* $XConsortium: appgroup.c /main/20 1996/12/08 16:14:27 kaleb $ */#define NEED_REPLIES#define NEED_EVENTS#include "X.h"#include "Xproto.h"#include "misc.h"#include "dixstruct.h"#include "extnsionst.h"#include "scrnintstr.h"#include "windowstr.h"#include "colormapst.h"#include "servermd.h"#define _XAG_SERVER_#include "Xagstr.h"#define _SECURITY_SERVER#include "security.h"#include "Xfuncproto.h"#define XSERV_t#include <X11/Xtrans.h>#include "../os/osdep.h"#include <stdio.h>typedef struct _AppGroupRec {    struct _AppGroupRec* next;    XID			appgroupId;    ClientPtr*		clients;    int			nclients;    ClientPtr		leader;    Bool		single_screen;    Window		default_root;    VisualID		root_visual;    Colormap		default_colormap;        Pixel		black_pixel;    Pixel		white_pixel;    xConnSetupPrefix	connSetupPrefix;    char*		ConnectionInfo;} AppGroupRec, *AppGroupPtr;static int		ProcXagDispatch (), SProcXagDispatch ();static void		XagResetProc ();static unsigned char	XagReqCode = 0;static int		XagErrorBase;static int		XagCallbackRefCount = 0;static RESTYPE		RT_APPGROUP;static AppGroupPtr	appGrpList = NULL;extern WindowPtr* WindowTable;extern xConnSetupPrefix connSetupPrefix;extern char* ConnectionInfo;static int XagAppGroupFree (what, id)    pointer what;    XID id; /* unused */{    int i;    AppGroupPtr pAppGrp = (AppGroupPtr) what;    if (pAppGrp->leader)	for (i = 0; i < pAppGrp->nclients; i++) {	    pAppGrp->clients[i]->appgroup = NULL;	    CloseDownClient (pAppGrp->clients[i]);	}    if (pAppGrp == appGrpList)	appGrpList = appGrpList->next;    else {	AppGroupPtr tpAppGrp;	for (tpAppGrp = appGrpList; 	    tpAppGrp->next != NULL; 	    tpAppGrp = tpAppGrp->next) {	    if (tpAppGrp->next == pAppGrp) {		tpAppGrp->next = tpAppGrp->next->next;		break;	    }	}    }    (void) xfree (pAppGrp->clients);    (void) xfree (pAppGrp->ConnectionInfo);    (void) xfree (what);    return Success;}/* static */void XagClientStateChange (pcbl, nulldata, calldata)    CallbackListPtr* pcbl;    pointer nulldata;    pointer calldata;{    SecurityAuthorizationPtr pAuth;    NewClientInfoRec* pci = (NewClientInfoRec*) calldata;    ClientPtr pClient = pci->client;    AppGroupPtr pAppGrp;    XID authId;    if (!pClient->appgroup) {	switch (pClient->clientState) {	case ClientStateAuthenticating:	case ClientStateRunning: 	case ClientStateCheckingSecurity:	    return;	case ClientStateInitial: 	case ClientStateCheckedSecurity:	    /* 	     * If the client is connecting via a firewall proxy (which	     * uses XC-QUERY-SECURITY-1, then the authId is available	     * during ClientStateCheckedSecurity, otherwise it's	     * available during ClientStateInitial.	     *	     * Don't get it from pClient because can't guarantee the order	     * of the callbacks and the security extension might not have	     * plugged it in yet.	     */	    authId = AuthorizationIDOfClient(pClient);	    break;	case ClientStateGone:	case ClientStateRetained:	    /*	     * Don't get if from AuthorizationIDOfClient because can't	     * guarantee the order of the callbacks and the security	     * extension may have torn down the client's private data	     */	    authId = pClient->authId;	    break;	}	if (authId == None)	    return;	pAuth = (SecurityAuthorizationPtr)SecurityLookupIDByType(pClient,		authId, SecurityAuthorizationResType, SecurityReadAccess);	if (pAuth == NULL)	    return;	for (pAppGrp = appGrpList; pAppGrp != NULL; pAppGrp = pAppGrp->next)	    if (pAppGrp->appgroupId == pAuth->group) break;    } else {	pAppGrp = pClient->appgroup;    }    if (!pAppGrp)	return;    switch (pClient->clientState) {    case ClientStateAuthenticating:    case ClientStateRunning:     case ClientStateCheckingSecurity:	break;    case ClientStateInitial:     case ClientStateCheckedSecurity:	/* see the comment above about Initial vs. CheckedSecurity */	{	    /* if this client already in AppGroup, don't add it again */	    int i;	    for (i = 0; i < pAppGrp->nclients; i++)		if (pClient == pAppGrp->clients[i]) return;	}	pAppGrp->clients = (ClientPtr*) xrealloc (pAppGrp->clients, 				++pAppGrp->nclients * sizeof (ClientPtr));	pAppGrp->clients[pAppGrp->nclients - 1] = pClient;	pClient->appgroup = pAppGrp;	break;    case ClientStateGone:    case ClientStateRetained: /* client disconnected, dump it */	{	    int i;	    for (i = 0; i < pAppGrp->nclients; i++)		if (pAppGrp->clients[i] == pClient) {		    pAppGrp->clients[i] = NULL;		    break;		}	    for (i = 0; i < pAppGrp->nclients; i++)		if (pAppGrp->clients[i] == NULL && i + 1 < pAppGrp->nclients)		    pAppGrp->clients[i] = pAppGrp->clients[i + 1];	    pAppGrp->nclients--;	}	pClient->appgroup = NULL; /* redundant, pClient will be freed */	break;    }}voidXagExtensionInit (){    ExtensionEntry* extEntry;    if (extEntry = AddExtension (XAGNAME,				0,				XagNumberErrors,				ProcXagDispatch,				SProcXagDispatch,				XagResetProc,				StandardMinorOpcode)) {	XagReqCode = (unsigned char)extEntry->base;	XagErrorBase = extEntry->errorBase;	RT_APPGROUP = CreateNewResourceType (XagAppGroupFree);    }}/*ARGSUSED*/static void XagResetProc (extEntry)    ExtensionEntry* extEntry;{    DeleteCallback (&ClientStateCallback, XagClientStateChange, NULL);    XagCallbackRefCount = 0;    while (appGrpList) XagAppGroupFree ((pointer) appGrpList, 0);}static int ProcXagQueryVersion (client)    register ClientPtr client;{    REQUEST (xXagQueryVersionReq);    xXagQueryVersionReply rep;    register int n;    REQUEST_SIZE_MATCH (xXagQueryVersionReq);    rep.type = X_Reply;    rep.length = 0;    rep.sequence_number = client->sequence;    rep.server_major_version = XAG_MAJOR_VERSION;    rep.server_minor_version = XAG_MINOR_VERSION;    if (client->swapped) {    	swaps (&rep.sequence_number, n);    	swapl (&rep.length, n);    	swaps (&rep.server_major_version, n);    	swaps (&rep.server_minor_version, n);    }    WriteToClient (client, sizeof (xXagQueryVersionReply), (char *)&rep);    return client->noClientException;}static void ProcessAttr (pAppGrp, client, attrib_mask, attribs)    AppGroupPtr pAppGrp;    ClientPtr client;    unsigned int attrib_mask;    CARD32* attribs;{    int i;    for (i = XagNsingleScreen; i <= XagNappGroupLeader; i++) {	switch (attrib_mask & (1 << i)) {	case XagSingleScreenMask:	    pAppGrp->single_screen = *attribs;	    break;	case XagDefaultRootMask:	    pAppGrp->default_root = *attribs;	    break;	case XagRootVisualMask:	    pAppGrp->root_visual = *attribs;	    break;	case XagDefaultColormapMask:	    pAppGrp->default_colormap = *attribs;	    break;	case XagBlackPixelMask:	    pAppGrp->black_pixel = *attribs;	    break;	case XagWhitePixelMask:	    pAppGrp->white_pixel = *attribs;	    break;	case XagAppGroupLeaderMask:	    pAppGrp->leader = client;	    break;	default: continue;	}	attribs++;    }}static void CreateConnectionInfo (pAppGrp)    AppGroupPtr pAppGrp;{    extern int connBlockScreenStart;    xConnSetup *setup = (xConnSetup*) ConnectionInfo;    xWindowRoot* rootp;    xWindowRoot* roots[MAXSCREENS];    unsigned int rootlens[MAXSCREENS];    xDepth* depth;    int olen;    int snum, i;    rootp = (xWindowRoot*) (ConnectionInfo + connBlockScreenStart);    for (snum = 0; snum < screenInfo.numScreens; snum++) {	rootlens[snum] = sizeof (xWindowRoot);	roots[snum] = rootp;	depth = (xDepth*) (rootp + 1);	for (i = 0; i < rootp->nDepths; i++) {	    rootlens[snum] += sizeof (xDepth) + 			      depth->nVisuals * sizeof (xVisualType);	    depth = (xDepth *)(((char*)(depth + 1)) +		depth->nVisuals * sizeof (xVisualType));	}	rootp = (xWindowRoot*) depth;    }    snum = 0;    if (pAppGrp->default_root) {	for (; snum < screenInfo.numVideoScreens; snum++) {	    if (roots[snum]->windowId == pAppGrp->default_root)		break;        }    }    olen = connBlockScreenStart + rootlens[snum];    for (i = screenInfo.numVideoScreens; i < screenInfo.numScreens; i++)	olen += rootlens[i];    pAppGrp->ConnectionInfo = (char*) xalloc (olen);    if (!pAppGrp->ConnectionInfo)	return;    memmove (pAppGrp->ConnectionInfo, ConnectionInfo, connBlockScreenStart);    ((xConnSetup*) (pAppGrp->ConnectionInfo))->numRoots = 	1 + screenInfo.numScreens - screenInfo.numVideoScreens;    memmove (pAppGrp->ConnectionInfo + connBlockScreenStart,	     (void*) roots[snum], rootlens[snum]);    rootp = (xWindowRoot*) (pAppGrp->ConnectionInfo + connBlockScreenStart);    if (pAppGrp->default_colormap) {	rootp->defaultColormap = pAppGrp->default_colormap;	rootp->whitePixel = pAppGrp->white_pixel;	rootp->blackPixel = pAppGrp->black_pixel;    }    if (pAppGrp->root_visual)	rootp->rootVisualID = pAppGrp->root_visual;    rootp = (xWindowRoot*) (((char*)rootp) + rootlens[snum]);    for (i = screenInfo.numVideoScreens; i < screenInfo.numScreens; i++) {	memmove ((void*) rootp, (void*) roots[i], rootlens[i]);	rootp = (xWindowRoot*) (((char*) rootp) + rootlens[i]);    }    pAppGrp->connSetupPrefix = connSetupPrefix;    pAppGrp->connSetupPrefix.length = olen >> 2;}static AppGroupPtr CreateAppGroup (client, appgroupId, attrib_mask, attribs)    ClientPtr client;    XID appgroupId;    unsigned int attrib_mask;    CARD32* attribs;{    AppGroupPtr pAppGrp;    int i;    pAppGrp = (AppGroupPtr) xalloc (sizeof(AppGroupRec));    if (pAppGrp) {	pAppGrp->next = appGrpList;	appGrpList = pAppGrp;	pAppGrp->appgroupId = appgroupId;	pAppGrp->clients = (ClientPtr*) xalloc (0);	pAppGrp->nclients = 0;	pAppGrp->leader = NULL;	pAppGrp->default_root = 0;	pAppGrp->root_visual = 0;	pAppGrp->default_colormap = 0;	pAppGrp->black_pixel = -1;	pAppGrp->white_pixel = -1;	pAppGrp->ConnectionInfo = NULL;	ProcessAttr (pAppGrp, client, attrib_mask, attribs);    }    return pAppGrp;}static int AttrValidate (client, attrib_mask, pAppGrp)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -