def post(self): 
        minlen = 4 + 4 + 20                
        STR_VERSERVER = '01060000'
        INT_VERCLIENT = 0x01060000
        STR_VERCLIENT = '1.6'
 
        # must be able to query for https
        if not os.environ.has_key('HTTPS'):
            self.resp_simple(0, 'HTTPS environment variable not found')
            return

        # must be able to query for server version
        if not os.environ.has_key('CURRENT_VERSION_ID'):
            self.resp_simple(0, 'CURRENT_VERSION_ID environment variable not found')
            return

        HTTPS = os.environ.get('HTTPS', 'off')
        CURRENT_VERSION_ID = os.environ.get('CURRENT_VERSION_ID', STR_VERSERVER)

        # SSL must be enabled
        if HTTPS.__str__() != 'on':
            self.resp_simple(0, 'Secure socket required.')
            return

        # get the data from the post
        self.response.headers['Content-Type'] = 'application/octet-stream'
        data = self.request.body        
        size = str.__len__(data)

        # size check
        if size < minlen:
            logging.debug("in body '%s'" % data)
            logging.debug("in size %d" % size)
            self.resp_simple(0, 'Request was formatted incorrectly.')
            return

        # unpack all incoming data
        client = (struct.unpack("!i", data[0:4]))[0]
        data = data[4:]

        # client version check
        if client < INT_VERCLIENT:
            self.resp_simple(0, ('Client version mismatch; %s required.  Download latest client release first.' % STR_VERCLIENT))
            return

        server = int(CURRENT_VERSION_ID[0:8], 16)

        # unpack all incoming data
        pos = 0
        
        lenrtok = (struct.unpack("!i", data[pos:(pos + 4)]))[0]
        pos = pos + 4
        recipientToken = str(data[pos:(pos + lenrtok)])
        pos = pos + lenrtok
        
        # number of recent message nonces the user needs to query
        numquery = (struct.unpack("!i", data[pos:(pos + 4)]))[0]
        pos = pos + 4
        
        # query for file in database
        query = filestorage.FileStorage.all()
        downloaded = False
        query.filter('sender_token =', recipientToken).filter('downloaded = ', downloaded)
        num = query.count()
        items = query.fetch(num)

        # if found package up file and return it
        lenArray = []
        nonceArray = []
        num = 0
        for item in items:
            msgId = item.id
            lenid = str.__len__(msgId)
            lenArray.append(lenid)
            nonceArray.append(msgId)
            num = num + 1

        # not found, send back error message
        if num == 0:            
            self.response.out.write('%s' % struct.pack('!i', server))
            self.response.out.write('%s' % (struct.pack('!i', 1)))
            self.response.out.write('%s' % struct.pack('!i', num))
            return
        else:
            # send out nonce arrays
            self.response.out.write('%s' % struct.pack('!i', server))
            self.response.out.write('%s' % (struct.pack('!i', 1)))
            self.response.out.write('%s' % struct.pack('!i', num))
            idx = 0
            for nonce in nonceArray:
                # logging.debug("nonce: " + nonce)
                self.response.out.write('%s%s' % (struct.pack('!i', lenArray[idx]), nonce))
                idx = idx + 1
dataset/ETHPy150Open SafeSlingerProject/SafeSlinger-AppEngine/safeslinger-messenger/python/getMessageNoncesByToken.py/GetMessageNoncesByToken.post/original