int XdmcpReadCARD16 (XdmcpBufferPtr buffer, CARD16Ptr valuep) { CARD8 high, low; if (XdmcpReadCARD8 (buffer, &high) && XdmcpReadCARD8 (buffer, &low)) { *valuep = (((CARD16) high) << 8) | ((CARD16) low); return TRUE; } return FALSE; }
static void recv_alive_msg (unsigned length) { CARD8 SessionRunning; CARD32 AliveSessionID; if (state != XDM_AWAIT_ALIVE_RESPONSE) return; if (length != 5) return; if (XdmcpReadCARD8 (&buffer, &SessionRunning) && XdmcpReadCARD32 (&buffer, &AliveSessionID)) { if (SessionRunning && AliveSessionID == SessionID) { /* backoff dormancy period */ state = XDM_RUN_SESSION; if ((GetTimeInMillis() - lastDeviceEventTime.milliseconds) > keepaliveDormancy * 1000) { keepaliveDormancy <<= 1; if (keepaliveDormancy > XDM_MAX_DORMANCY) keepaliveDormancy = XDM_MAX_DORMANCY; } timeOutTime = GetTimeInMillis() + keepaliveDormancy * 1000; } else { XdmcpDeadSession ("Alive respose indicates session dead"); } } }
int XdmcpReadCARD32 (XdmcpBufferPtr buffer, CARD32Ptr valuep) { CARD8 byte0, byte1, byte2, byte3; if (XdmcpReadCARD8 (buffer, &byte0) && XdmcpReadCARD8 (buffer, &byte1) && XdmcpReadCARD8 (buffer, &byte2) && XdmcpReadCARD8 (buffer, &byte3)) { *valuep = (((CARD32) byte0) << 24) | (((CARD32) byte1) << 16) | (((CARD32) byte2) << 8) | (((CARD32) byte3)); return TRUE; } return FALSE; }
int XdmcpReadARRAYofARRAY8 (XdmcpBufferPtr buffer, ARRAYofARRAY8Ptr array) { CARD8 i; /* * When returning FALSE, guarantee that array->data = 0. * This allows the user to safely call XdmcpDisposeARRAYofARRAY8(array) * regardless of the return value below. * Note that XdmcpDisposeARRAY*(array) will call free(array->data), * so we must guarantee that array->data is NULL or a malloced pointer. */ if (!XdmcpReadCARD8 (buffer, &array->length)) { array->data = NULL; return FALSE; } if (!array->length) { array->data = NULL; return TRUE; } array->data = (ARRAY8 *) malloc(array->length * sizeof (ARRAY8)); if (!array->data) return FALSE; for (i = 0; i < array->length; i++) { if (!XdmcpReadARRAY8 (buffer, &array->data[i])) { /* * We must free all of the arrays allocated thus far in the loop * and free array->data and finally set array->data = 0; * The easiest way to do this is to reset the length and call * XdmcpDisposeARRAYofARRAY8(array). */ array->length = i; XdmcpDisposeARRAYofARRAY8(array); return FALSE; } } return TRUE; }
static void recv_alive_msg(unsigned length) { CARD8 SessionRunning; CARD32 AliveSessionID; if (state != XDM_AWAIT_ALIVE_RESPONSE) return; if (length != 5) return; if (XdmcpReadCARD8(&buffer, &SessionRunning) && XdmcpReadCARD32(&buffer, &AliveSessionID)) { if (SessionRunning && AliveSessionID == SessionID) { state = XDM_RUN_SESSION; timeOutTime = GetTimeInMillis() + XDM_DEF_DORMANCY * 1000; } else { XdmcpDeadSession("Alive response indicates session dead"); } } }
int XdmcpReadARRAY16 (XdmcpBufferPtr buffer, ARRAY16Ptr array) { int i; /* * When returning FALSE, guarantee that array->data = 0. * This allows the user to safely call XdmcpDisposeARRAY16(array) * regardless of the return value below. * Note that XdmcpDisposeARRAY*(array) will call free(array->data), * so we must guarantee that array->data is NULL or a malloced pointer. */ if (!XdmcpReadCARD8 (buffer, &array->length)) { array->data = NULL; return FALSE; } if (!array->length) { array->data = NULL; return TRUE; } array->data = (CARD16 *) malloc(array->length * sizeof (CARD16)); if (!array->data) return FALSE; for (i = 0; i < (int)array->length; i++) { if (!XdmcpReadCARD16 (buffer, &array->data[i])) { free(array->data); array->data = NULL; array->length = 0; return FALSE; } } return TRUE; }