// Helper function to read the X11 cut buffer // FIXME: What about multiple screens? Currently, this reads the first // CUT_BUFFER0 from the first screen where the buffer content is a string. // Returns a string on the heap that the caller must free. // Returns NULL if there is no cut text or there is not enough memory. static char * QuartzReadCutBuffer(void) { int i; char *text = NULL; for (i = 0; i < screenInfo.numScreens; i++) { ScreenPtr pScreen = screenInfo.screens[i]; PropertyPtr pProp; pProp = wUserProps (WindowTable[pScreen->myNum]); while (pProp && pProp->propertyName != XA_CUT_BUFFER0) { pProp = pProp->next; } if (! pProp) continue; if (pProp->type != XA_STRING) continue; if (pProp->format != 8) continue; text = xalloc(1 + pProp->size); if (! text) continue; memcpy(text, pProp->data, pProp->size); text[pProp->size] = '\0'; return text; } // didn't find any text return NULL; }
static int ProcSELinuxListProperties(ClientPtr client) { WindowPtr pWin; PropertyPtr pProp; SELinuxListItemRec *items; int rc, count, size, i; CARD32 id; REQUEST(SELinuxGetContextReq); REQUEST_SIZE_MATCH(SELinuxGetContextReq); rc = dixLookupWindow(&pWin, stuff->id, client, DixListPropAccess); if (rc != Success) return rc; /* Count the number of properties and allocate items */ count = 0; for (pProp = wUserProps(pWin); pProp; pProp = pProp->next) count++; items = calloc(count, sizeof(SELinuxListItemRec)); if (count && !items) return BadAlloc; /* Fill in the items and calculate size */ i = 0; size = 0; for (pProp = wUserProps(pWin); pProp; pProp = pProp->next) { id = pProp->propertyName; rc = SELinuxPopulateItem(items + i, &pProp->devPrivates, id, &size); if (rc != Success) { SELinuxFreeItems(items, count); return rc; } i++; } return SELinuxSendItemsToClient(client, items, size, count); }
/* * GetPropString searches the window heirarchy from pWin up looking for * a property by the name of propName. If found, returns the property's * value. If not, it returns NULL. */ char * GetPropString( WindowPtr pWin, char *propName) { Atom atom; PropertyPtr pProp = (PropertyPtr)NULL; char *retVal; atom = MakeAtom(propName, strlen(propName), FALSE); if(atom != BAD_RESOURCE) { WindowPtr pPropWin; int n; /* * The atom has been defined, but it might only exist as a * property on an unrelated window. */ for(pPropWin = pWin; pPropWin != (WindowPtr)NULL; pPropWin = pPropWin->parent) { for(pProp = (PropertyPtr)(wUserProps(pPropWin)); pProp != (PropertyPtr)NULL; pProp = pProp->next) { if (pProp->propertyName == atom) break; } if(pProp != (PropertyPtr)NULL) break; } if(pProp == (PropertyPtr)NULL) return (char *)NULL; n = (pProp->format/8) * pProp->size; /* size (bytes) of prop */ retVal = (char *)xalloc(n + 1); (void)memcpy((void *)retVal, (void *)pProp->data, n); retVal[n] = '\0'; return retVal; } return (char *)NULL; }
int dixLookupProperty(PropertyPtr *result, WindowPtr pWin, Atom propertyName, ClientPtr client, Mask access_mode) { PropertyPtr pProp; int rc = BadMatch; client->errorValue = propertyName; for (pProp = wUserProps(pWin); pProp; pProp = pProp->next) if (pProp->propertyName == propertyName) break; if (pProp) rc = XaceHookPropertyAccess(client, pWin, &pProp, access_mode); *result = pProp; return rc; }