def kXR_open(self, streamid=None, status=None, dlen=None, fhandle=None, cpsize=None , cptype=None, data=None): """Return a packed representation of a kXR_open response.""" responseStruct = getMessageStruct('ServerResponseHeader') + \ getMessageStruct('ServerResponseBody_Open') params = { 'streamid': streamid if streamid else 0, 'status': status if status else getResponseId('kXR_ok'), 'dlen': 0, 'fhandle': fhandle if fhandle else (4 * '\0') } toBeRemoved = [] if cpsize != None: params['cpsize'] = cpsize else: toBeRemoved.append('cpsize') if cptype != None: params['cptype'] = cptype else: toBeRemoved.append('cptype') if data != None: params['data'] = data self.mh.setFieldAttribute( responseStruct, 'data', 'size', len( data ) ) else: toBeRemoved.append('data') responseStruct = self.mh.removeFields( responseStruct, toBeRemoved ) msg = self.mh.buildMessageFormat( responseStruct, params ) msg[1][2] = msg[2] - 8 return self.mh.pack( msg[0], msg[1] )
def kXR_login(self, streamid=None, status=None, dlen=None, sessid=None, sec=None, verifyAuth=False): """Return a packed representation of a kXR_login response. Pass verify_auth=True to enable authentication.""" responseStruct = getMessageStruct('ServerResponseHeader') + \ getMessageStruct('ServerResponseBody_Login') # Check if client needs to authenticate if verifyAuth and not sec: auth = AuthHelper.AuthHelper(self.context) sec = auth.getsectoken() params = { 'streamid': streamid if streamid else 0, 'status' : status if status else getResponseId('kXR_ok'), 'dlen' : dlen if dlen else 0, 'sessid' : sessid if sessid else genSessId() } toBeRemoved = [] if sec != None: params['sec'] = sec self.mh.setFieldAttribute( responseStruct, 'sec', 'size', len( sec ) ) else: responseStruct = self.mh.removeFields( responseStruct, ['sec'] ) msg = self.mh.buildMessageFormat( responseStruct, params ) msg[1][2] = msg[2] - 8 return self.mh.pack( msg[0], msg[1] )
def kXR_waitresp(self, streamid=None, status=None, dlen=None, seconds=None): """Return a packed representation of a kXR_waitresp response.""" responseStruct = getMessageStruct('ServerResponseHeader') + \ getMessageStruct('ServerResponseBody_Waitresp') params = { 'streamid': streamid if streamid else 0, 'status' : status if status else getResponseId('kXR_waitresp'), 'dlen' : dlen if dlen else 4, 'seconds' : seconds if seconds else 0} return self.mh.buildMessage(responseStruct, params)
def kXR_bind( self, streamid=None, status=None, dlen=None, pathid=None ): """Return a packed representation of a kXR_bind response.""" responseStruct = getMessageStruct('ServerResponseHeader') + \ getMessageStruct('ServerResponseBody_Bind') params = { 'streamid': streamid if streamid else 0, 'status' : status if status else getResponseId('kXR_ok'), 'dlen' : dlen if dlen else 1, 'pathid' : pathid if pathid else '\0'} return self.mh.buildMessage(responseStruct, params)
def kXR_attn_asyncwt(self, streamid=None, status=None, dlen=None, actnum=None, wsec=None): """Return a packed representation of a kXR_attn_asyncwt response.""" responseStruct = getMessageStruct('ServerResponseHeader') + \ getMessageStruct('ServerResponseBody_Attn_asyncwt') params = { 'streamid': streamid if streamid else 0, 'status' : status if status else getResponseId('kXR_attn'), 'dlen' : dlen if dlen else 8, 'actnum' : actnum if actnum else get_attncode('kXR_asyncwt'), 'wsec' : wsec if wsec else 0} return self.mh.buildMessage(responseStruct, params)
def kXR_attn_asynresp(self, payloadLength): """Return a packed representation of a kXR_attn_asynresp response.""" responseStruct = getMessageStruct('ServerResponseHeader') + \ getMessageStruct('ServerResponseBody_Attn') + \ getMessageStruct('ServerResponseBody_Attn_asynresp') params = { 'streamid': 0, 'status' : getResponseId('kXR_attn'), 'dlen' : payloadLength + 8, 'actnum' : getAttnCode('kXR_asynresp'), 'reserved': 4 * '\0' } return self.mh.buildMessage(responseStruct, params)
def kXR_attn_asyncab(self, streamid=None, status=None, dlen=None, actnum=None, msg=None): """Return a packed representation of a kXR_attn_asyncab response.""" responseStruct = getMessageStruct('ServerResponseHeader') + \ getMessageStruct('ServerResponseBody_Attn') if not msg: msg = '' params = { 'streamid': streamid if streamid else 0, 'status' : status if status else getResponseId('kXR_attn'), 'dlen' : dlen if dlen else len(msg) + 4, 'actnum' : actnum if actnum else get_attncode('kXR_asyncab'), 'parms' : msg} return self.mh.buildMessage(responseStruct, params)
def kXR_protocol(self, streamid=None, status=None, dlen=None, pval=None, flags=None): """Return a packed representation of a kXR_protocol response.""" responseStruct = getMessageStruct('ServerResponseHeader') + \ getMessageStruct('ServerResponseBody_Protocol') params = { 'streamid': streamid if streamid else 0, 'status' : status if status else getResponseId('kXR_ok'), 'dlen' : dlen if dlen else 8, 'pval' : pval if pval else XProtocol.kXR_PROTOCOLVERSION, 'flags' : flags if flags else XProtocol.kXR_isServer} return self.mh.buildMessage(responseStruct, params)
def kXR_attn_asyncrd(self, streamid=None, status=None, dlen=None, actnum=None, port=None, host=None, token=None): """Return a packed representation of a kXR_attn_asyncrd response.""" responseStruct = getMessageStruct('ServerResponseHeader') + \ getMessageStruct('ServerResponseBody_Attn_asyncrd') if not host: host = '' else: host += (token if token else '') params = { 'streamid': streamid if streamid else 0, 'status' : status if status else getResponseId('kXR_attn'), 'dlen' : dlen if dlen else len(host), 'actnum' : actnum if actnum else get_attncode('kXR_asyncrd'), 'port' : port if port else 0, 'host' : host} return self.mh.buildMessage(responseStruct, params)
def kXR_wait(self, streamid=None, status=None, dlen=None, seconds=None, infomsg=None): """Return a packed representation of a kXR_wait response.""" responseStruct = getMessageStruct('ServerResponseHeader') + \ getMessageStruct('ServerResponseBody_Wait') if not infomsg: infomsg = '' params = { 'streamid': streamid if streamid else 0, 'status' : status if status else getResponseId('kXR_wait'), 'dlen' : dlen if dlen else len(infomsg) + 4, 'seconds' : seconds if seconds else 0, 'infomsg' : infomsg} self.mh.setFieldAttribute( responseStruct, 'infomsg', 'size', len( infomsg ) ) return self.mh.buildMessage(responseStruct, params)
def kXR_ok(self, streamid=None, status=None, dlen=None, data=None): """Return a packed representation of a kXR_ok response.""" responseStruct = getMessageStruct('ServerResponseHeader') + \ getMessageStruct('ServerResponseBody_Buffer') if not data: data = '' params = { 'streamid': streamid if streamid else 0, 'status' : status if status else getResponseId('kXR_ok'), 'dlen' : dlen if dlen else len(data), 'data' : data } self.mh.setFieldAttribute( responseStruct, 'data', 'size', len( data ) ) return self.mh.buildMessage(responseStruct, params)
def kXR_error(self, streamid=None, status=None, dlen=None, errnum=None, errmsg=None): """Return a packed representation of a kXR_error response.""" responseStruct = getMessageStruct('ServerResponseHeader') + \ getMessageStruct('ServerResponseBody_Error') if not errmsg: errmsg = '' if not errnum: errnum = XProtocol.XErrorCode.kXR_ArgInvalid params = { 'streamid': streamid if streamid else 0, 'status' : status if status else getResponseId('kXR_error'), 'dlen' : dlen if dlen else len(errmsg + str(errnum)), 'errnum' : errnum, 'errmsg' : errmsg} self.mh.setFieldAttribute( responseStruct, 'errmsg', 'size', len(errmsg) ) return self.mh.buildMessage(responseStruct, params)
def kXR_redirect(self, streamid=None, status=None, dlen=None, port=None, host=None, opaque=None, token=None): """Return a packed representation of a kXR_redirect response.""" responseStruct = getMessageStruct('ServerResponseHeader') + \ getMessageStruct('ServerResponseBody_Redirect') if not host: host = '' else: host += (opaque if opaque else '') + (token if token else '') params = { 'streamid': streamid if streamid else 0, 'status' : status if status else getResponseId('kXR_redirect'), 'dlen' : dlen if dlen else len(host) + 4, 'port' : port if port else 0, 'host' : host if host else r''} self.mh.setFieldAttribute( responseStruct, 'host', 'size', len(host) ) return self.mh.buildMessage(responseStruct, params)
def kXR_oksofar(self, streamid=None, status=None, dlen=None, data=None): """Return a packed representation of a kXR_oksofar response.""" status = getResponseId('kXR_oksofar') return self.kXR_ok(streamid, status, dlen, data)
def kXR_authmore(self, streamid=None, status=None, dlen=None, data=None): """Return a packed representation of a kXR_authmore response.""" if not status: status = getResponseId('kXR_authmore') return self.kXR_ok(streamid, status, dlen, data)