Esempio n. 1
0
    def handle_bind(self, P):
        """
        Used by the server to handle the incoming bind request
        """

        print("Received PDU: " + P.__class__.__name__)

        pdu = dict(
            BindTransmitter=dict(state=SessionState.BOUND_TX, response=BindTransmitterResp),
            BindReceiver=dict(state=SessionState.BOUND_RX, response=BindReceiverResp),
            BindTransceiver=dict(state=SessionState.BOUND_TRX, response=BindTransceiverResp)
        )
        #Validating the Credentials and sending response
        if(P.__class__.__name__ == BindTransmitter or BindReceiver or BindTransceiver):
            validate = self.server_validate_method(P.system_id.value, P.password.value, P.system_type.value)
            if(validate == 'True'):
                self.validation_status = 'success'
                self.user_id = P.system_id.value.decode(encoding='ascii')
                print("  Logged in Client is :   " + self.user_id)
                self.state = pdu[P.__class__.__name__]['state']
                R = pdu[P.__class__.__name__]['response']()
                R.sequence_number = Integer(P.sequence_number.value, 4)
                R.system_id = CString(P.system_id.value)
                data = R.encode()
                self.socket.send(data)
            else:
                self.validation_status = 'fail'
                R = GenericNack()
                R.sequence_number = Integer(P.sequence_number.value, 4)
                R.command_status = Integer(command_status.ESME_RBINDFAIL, 4)
                data = R.encode()
                self.socket.send(data)
Esempio n. 2
0
    def handle_pdu(self):
        """
        This method check for client request and calls appropriate methods to handle it.
        """

        isempty = (self.pdus and True) or False
        if isempty is not False:
            seq_no, pdu = self.pdus.popitem()
            if pdu['resp'] == '':
                P = pdu['req']
                if(command_ids.bind_transmitter == P.command_id.value):
                    self.handle_bind(P)
                elif(command_ids.bind_receiver == P.command_id.value):
                    self.handle_bind(P)
                elif(command_ids.bind_transceiver == P.command_id.value):
                    self.handle_bind(P)
                elif command_ids.submit_sm == P.command_id.value:
                    self.process_sms(P)
                elif command_ids.submit_multi == P.command_id.value:
                    self.process_multiple_sms(P)
                elif(command_ids.query_sm == P.command_id.value):
                    self.process_query(P)
                elif(command_ids.cancel_sm == P.command_id.value):
                    self.process_sms_cancelling(P)
                elif(command_ids.replace_sm == P.command_id.value):
                    self.process_replace_sms(P)
                elif(command_ids.enquire_link == P.command_id.value):
                    self.enquire_link_response(P)
                elif(command_ids.unbind == P.command_id.value):
                    self.handle_unbind(P)
                else:
                    R = GenericNack()
                    R.sequence_number = Integer(P.sequence_number.value, 4)
                    R.command_status = Integer(command_status.ESME_RINVCMDID, 4)
                    self.socket.send(R.encode())
Esempio n. 3
0
 def handle_pdu(self, P):
     """
     Given a PDU P, calls appropriate methods to handle it.
     """
     if command_ids.submit_sm == P.command_id.value:
         self.process_sms(P)
     elif(command_ids.query_sm == P.command_id.value):
         self.process_query(P)
     elif(command_ids.cancel_sm == P.command_id.value):
         self.process_sms_cancelling(P)
     elif(command_ids.replace_sm == P.command_id.value):
         self.process_replace_sms(P)
     elif(command_ids.enquire_link == P.command_id.value):
         self.enquire_link_response(P)
     else:
         R = GenericNack()
         R.sequence_number = Integer(P.sequence_number.value, 4)
         R.command_status = Integer(command_status.ESME_RINVCMDID, 4)
         self.socket.send(R.encode())
Esempio n. 4
0
def test_02_generic_nack_decode():
    "Test Generic_Nack decoding"
    
    data = b'\x00\x00\x00\x10\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01'
    P = GenericNack.decode(data)
    assert '00 00 00 10 80 00 00 00 00 00 00 00 00 00 00 01 ' == hex_convert(P.encode(), 150)
Esempio n. 5
0
def test_01_generic_nack_encode():
    "Test Generic_Nack encoding"
    P = GenericNack()
    
    assert '00 00 00 10 80 00 00 00 00 00 00 00 00 00 00 01 '  == hex_convert(P.encode(), 150)