예제 #1
0
    def handle(self):
        self.server.logger.debug("Handling message from {0}".format(
            self.client_address))

        string = StringIO.StringIO(self.rfile.read())
        message = MobileOriginatedMessage.parse(string)
        time_of_session = datetime.datetime(1970, 1, 1, 0, 0, 0) + \
                datetime.timedelta(seconds=message.time_of_session)

        directory = os.path.join(self.server.directory, message.imei,
                                 str(time_of_session.year),
                                 "%02d" % time_of_session.month)
        mkdir_p(directory)
        basename = time_of_session.strftime("%y%m%d_%H%M%S")
        payload_file = os.path.join(directory, basename + ".payload")
        sbd_file = os.path.join(directory, basename + ".sbd")

        if os.path.isfile(payload_file) or os.path.isfile(sbd_file):
            self.server.logger.warn(
                "Message recieved at {0} has already been stored, skipping".
                format(time_of_session))
            return

        with open(payload_file, "wb") as f:
            f.write(message.payload)
        with open(sbd_file, "wb") as f:
            f.write(string.getvalue())

        self.server.logger.info(
            "Message recieved at {0} stored OK".format(time_of_session))
예제 #2
0
def read_test():
    message = MobileOriginatedMessage.read("data/test.sbd")
    assert message.protocol_revision_number == 1
    assert message.overall_message_length == 56

    header = message.get_information_element(0)
    assert header.id_ == 1
    assert header.length == 28
    assert header.cdr_reference == 1894516585, header.cdr_reference
    assert header.imei == "300234063904190", header.imei
    assert header.session_status == 0, header.session_status
    assert header.momsn == 75, header.momsn
    assert header.mtmsn == 0, header.mtmsn
    assert header.time_of_session == 1436465708, header.time_of_session

    assert message.payload == "test message from pete"