Xnamespace: add basic namespace config structures
Adding data structure and initial data for namespace configuration. Built-in namespaces are ROOT and ANONYMOUS. Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
This commit is contained in:
parent
4379f7cc87
commit
9f8ef921ad
|
@ -0,0 +1,39 @@
|
|||
#include <dix-config.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <X11/Xdefs.h>
|
||||
|
||||
#include "namespace.h"
|
||||
|
||||
struct Xnamespace ns_root = {
|
||||
.builtin = TRUE,
|
||||
.name = NS_NAME_ROOT,
|
||||
.refcnt = 1,
|
||||
.superPower = TRUE,
|
||||
};
|
||||
|
||||
struct Xnamespace ns_anon = {
|
||||
.builtin = TRUE,
|
||||
.name = NS_NAME_ANONYMOUS,
|
||||
.refcnt = 1,
|
||||
};
|
||||
|
||||
struct xorg_list ns_list = { 0 };
|
||||
|
||||
Bool XnsLoadConfig(void)
|
||||
{
|
||||
xorg_list_init(&ns_list);
|
||||
xorg_list_add(&ns_root.entry, &ns_list);
|
||||
xorg_list_add(&ns_anon.entry, &ns_list);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
struct Xnamespace *XnsFindByName(const char* name) {
|
||||
struct Xnamespace *walk;
|
||||
xorg_list_for_each_entry(walk, &ns_list, entry) {
|
||||
if (strcmp(walk->name, name)==0)
|
||||
return walk;
|
||||
}
|
||||
return NULL;
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
libxserver_namespace = static_library(
|
||||
'libxserver_namespace',
|
||||
[
|
||||
'config.c',
|
||||
'namespace.c',
|
||||
],
|
||||
include_directories: inc,
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
#include <dix-config.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <X11/Xmd.h>
|
||||
|
||||
#include "dix/dix_priv.h"
|
||||
#include "include/os.h"
|
||||
#include "miext/extinit_priv.h"
|
||||
|
||||
|
@ -9,8 +11,46 @@
|
|||
|
||||
Bool noNamespaceExtension = TRUE;
|
||||
|
||||
DevPrivateKeyRec namespaceClientPrivKeyRec = { 0 };
|
||||
|
||||
void
|
||||
NamespaceExtensionInit(void)
|
||||
{
|
||||
XNS_LOG("initializing namespace extension ...\n");
|
||||
|
||||
/* load configuration */
|
||||
if (!XnsLoadConfig()) {
|
||||
XNS_LOG("No config file. disabling Xns extension\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!dixRegisterPrivateKey
|
||||
(&namespaceClientPrivKeyRec, PRIVATE_CLIENT, sizeof(struct XnamespaceClientPriv)))
|
||||
FatalError("NamespaceExtensionInit: allocation failure\n");
|
||||
|
||||
/* Do the serverClient */
|
||||
struct XnamespaceClientPriv *srv = XnsClientPriv(serverClient);
|
||||
*srv = (struct XnamespaceClientPriv) { .isServer = TRUE };
|
||||
XnamespaceAssignClient(srv, &ns_root);
|
||||
}
|
||||
|
||||
void XnamespaceAssignClient(struct XnamespaceClientPriv *priv, struct Xnamespace *newns)
|
||||
{
|
||||
if (priv->ns != NULL)
|
||||
priv->ns->refcnt--;
|
||||
|
||||
priv->ns = newns;
|
||||
|
||||
if (newns != NULL)
|
||||
newns->refcnt++;
|
||||
}
|
||||
|
||||
void XnamespaceAssignClientByName(struct XnamespaceClientPriv *priv, const char *name)
|
||||
{
|
||||
struct Xnamespace *newns = XnsFindByName(name);
|
||||
|
||||
if (newns == NULL)
|
||||
newns = &ns_anon;
|
||||
|
||||
XnamespaceAssignClient(priv, newns);
|
||||
}
|
||||
|
|
|
@ -4,6 +4,53 @@
|
|||
#include <stdio.h>
|
||||
#include <X11/Xmd.h>
|
||||
|
||||
#include "include/dixstruct.h"
|
||||
#include "include/list.h"
|
||||
#include "include/privates.h"
|
||||
#include "include/window.h"
|
||||
|
||||
struct Xnamespace {
|
||||
struct xorg_list entry;
|
||||
const char *name;
|
||||
Bool builtin;
|
||||
Bool superPower;
|
||||
size_t refcnt;
|
||||
};
|
||||
|
||||
extern struct xorg_list ns_list;
|
||||
extern struct Xnamespace ns_root;
|
||||
extern struct Xnamespace ns_anon;
|
||||
|
||||
struct XnamespaceClientPriv {
|
||||
Bool isServer;
|
||||
XID authId;
|
||||
struct Xnamespace* ns;
|
||||
};
|
||||
|
||||
#define NS_NAME_ROOT "root"
|
||||
#define NS_NAME_ANONYMOUS "anon"
|
||||
|
||||
extern DevPrivateKeyRec namespaceClientPrivKeyRec;
|
||||
|
||||
Bool XnsLoadConfig(void);
|
||||
struct Xnamespace *XnsFindByName(const char* name);
|
||||
void XnamespaceAssignClient(struct XnamespaceClientPriv *priv, struct Xnamespace *ns);
|
||||
void XnamespaceAssignClientByName(struct XnamespaceClientPriv *priv, const char *name);
|
||||
|
||||
static inline struct XnamespaceClientPriv *XnsClientPriv(ClientPtr client) {
|
||||
if (client == NULL) return NULL;
|
||||
return dixLookupPrivate(&client->devPrivates, &namespaceClientPrivKeyRec);
|
||||
}
|
||||
|
||||
static inline Bool XnsClientSameNS(struct XnamespaceClientPriv *p1, struct XnamespaceClientPriv *p2)
|
||||
{
|
||||
if (!p1 && !p2)
|
||||
return TRUE;
|
||||
if (!p1 || !p2)
|
||||
return FALSE;
|
||||
return (p1->ns == p2->ns);
|
||||
}
|
||||
|
||||
#define XNS_LOG(...) do { printf("XNS "); printf(__VA_ARGS__); } while (0)
|
||||
|
||||
static inline Bool streq(const char *a, const char *b)
|
||||
|
|
|
@ -109,6 +109,7 @@ static const char *key_names[PRIVATE_LAST] = {
|
|||
[PRIVATE_GLYPHSET] = "GLYPHSET",
|
||||
[PRIVATE_PICTURE] = "PICTURE",
|
||||
[PRIVATE_SYNC_FENCE] = "SYNC_FENCE",
|
||||
[PRIVATE_NAMESPACE] = "NAMESPACE",
|
||||
};
|
||||
|
||||
static const Bool screen_specific_private[PRIVATE_LAST] = {
|
||||
|
|
|
@ -51,6 +51,7 @@ typedef enum {
|
|||
PRIVATE_GLYPHSET,
|
||||
PRIVATE_PICTURE,
|
||||
PRIVATE_SYNC_FENCE,
|
||||
PRIVATE_NAMESPACE,
|
||||
|
||||
/* last private type */
|
||||
PRIVATE_LAST,
|
||||
|
|
Loading…
Reference in New Issue