Exemple #1
0
 def on_message(self, client, userdata, msg):
     log.info('='*5 + 'RESPONSE' + '='*5 + '\r\n'+ str(bert.decode(bytes(msg.payload))) + '\r\n')
     for node in (bert.decode(bytes(msg.payload))):
         if node == (Atom('ok'), Atom('sms_sent')):
             client.publish(topic="events/1//api/anon//", payload=bytearray(sms(self.my_number)), qos=2,
                            retain=False)
         if re.findall(r"\(Atom\('ok2'\), Atom\('login'\)", str(node)):
             self.clien = str(node[2][0].decode("utf-8"))
             self.pswd = str(node[2][1].decode("utf-8"))
             log.info('Got client {} and password {}'.format(self.clien, self.pswd))
             client.disconnect()
Exemple #2
0
def parser(client, payload, number, friend_phone):
    data = bert.decode(bytes(payload))

    for node in data:

        if node == Atom('Profile') and data[8] == 'init':
            roas = (bert.decode(bytes(payload))[3])
            user_id = roas[0][1]
            client.publish(topic="events/1//api/anon//",
                           payload=bytearray(search(user_id, friend_phone)),
                           qos=2,
                           retain=False)
Exemple #3
0
def parser(client, payload, first_name, last_name, user_name=None):
    data = bert.decode(bytes(payload))
    global userid

    if data[0] == Atom('Profile') and (data[-1]) == Atom('init'):
        roaster = (bert.decode(bytes(payload))[3])
        global user_id
        user_id = roaster[0][1]
        rost = roster(user_id=user_id,
                      first_name=first_name,
                      last_name=last_name,
                      status=Atom('patch'))
        client.publish(topic="events/1//api/anon//",
                       payload=bytearray(rost),
                       qos=2,
                       retain=False)

    elif data[0] == Atom('Roster') and (data[-1]) == Atom('patch'):
        log.debug(user_id)
        log.debug(user_name)
        rost = roster(user_id=user_id,
                      my_username=user_name,
                      status=Atom('nick'))
        log.debug(rost)
        client.publish(topic="events/1//api/anon//",
                       payload=bytearray(rost),
                       qos=2,
                       retain=False)

    elif user_name and data[0] == Atom('Roster') and (
            data[-1]) == Atom('nick'):
        log.info("Verify roster/nick updated")
        Verify.true(data[5] == string_to_bytes(user_name),
                    'Username does not set')
        client.disconnect()

    elif data[0] == Atom('Roster') and (
            data[-1]) == Atom('patch') and user_name is None:
        log.info("Verify user register")
        Verify.true(data[2] == string_to_bytes(first_name),
                    'First Name doesnt update')
        client.disconnect()

    elif data == (Atom('io'), (Atom('error'), Atom('invalid_data')), b''):
        log.error("Something going wrong")
        client.disconnect()
        raise InvalidData("Invalid data response")

    elif data == (Atom('io'), (Atom('error'), Atom('permission_denied')), b''):
        log.error("Something going wrong")
        client.disconnect()
        raise PermissionDenied("No permission")
Exemple #4
0
def parser(client, payload, main_number):
    data = bert.decode(bytes(payload))

    if data[0] == Atom("Profile"):
        contacts = data[3][0][6]
        for field in contacts:
            if field[0] == Atom('Contact') and field[1].split(
                    b'_')[0] == string_to_bytes(main_number):
                log.debug('Main profile found')
                global user_id
                user_id = field[1]
                print(user_id)
        for field in data:
            if field and list == type(field):
                for room in field[0]:
                    if room and list == type(room) and room[0][0] == Atom(
                            'Room'):
                        global room_id
                        room_id = room[-1][1]
                        print(room_id)
        client.publish(topic="events/1//api/anon//",
                       payload=bytearray(history_group(user_id, room_id)),
                       qos=2,
                       retain=False)

    if data[0] == Atom('Message') and data[-1] == Atom('clear'):
        log.debug("Verify history removed")
        for field in data:
            if field and list == type(field) and tuple == type(field[0]):
                Verify.equals(b'History was removed', field[0][3],
                              'No history removed')
        client.disconnect()
Exemple #5
0
    def on_message(self, client, userdata, msg):
        print(msg.topic)
        print(bert.decode(bytes(msg.payload)))
        for node in (bert.decode(bytes(msg.payload))):
            if node == (Atom('ok'), Atom('sms_sent')):
                client.publish(topic="events/1//api/anon//",
                               payload=bytearray(sms),
                               qos=2,
                               retain=False)
            elif re.findall(r"\(Atom\('ok2'\), Atom\('login'\)", str(node)):
                global psw
                global clie
                clie = str(node[2][0].decode("utf-8"))
                psw = str(node[2][1].decode("utf-8"))

                client.disconnect()
Exemple #6
0
def parser(client, payload, main_number, friend_number, status):
    data = bert.decode(bytes(payload))
    global main_id
    global friend_id

    if status == mime_enums.FRIEND_BAN:
        if data[0] == Atom("Profile"):
            for field in data[3][0][6]:
                if field[-1] == Atom('friend'):
                    if field[1].split(b'_')[0] == string_to_bytes(main_number):
                        log.debug('Main profile found')
                        main_id = field[1]
                    if field[0] == Atom('Contact') and field[1].split(
                            b'_')[0] == string_to_bytes(friend_number):
                        friend_id = field[1]

            client.publish(topic="events/1//api/anon//",
                           payload=bytearray(
                               friend(my_id=main_id,
                                      friend_id=friend_id,
                                      status=Atom(status))),
                           qos=2,
                           retain=False)

        if data[0] == Atom("Contact") and data[-1] == Atom('banned'):
            log.debug('Contact banned')
            client.disconnect()

    if status == mime_enums.FRIEND_UNBAN:
        if data[0] == Atom("Profile"):
            for field in data[3][0][6]:
                if field[-1] == Atom('friend'):
                    if field[1].split(b'_')[0] == string_to_bytes(main_number):
                        log.debug('Main profile found')
                        main_id = field[1]
                if field[-1] == Atom('banned'):
                    friend_id = field[1]

            client.publish(topic="events/1//api/anon//",
                           payload=bytearray(
                               friend(my_id=main_id,
                                      friend_id=friend_id,
                                      status=Atom(status))),
                           qos=2,
                           retain=False)

        if data[0] == Atom("Contact") and data[-1] == Atom('friend'):
            log.debug('Contact Unbanned')
            client.disconnect()

    if data == (Atom('io'), (Atom('error'), Atom('invalid_data')), b''):
        log.error("Something going wrong")
        client.disconnect()

    if data == (Atom('io'), (Atom('error'), Atom('permission_denied')), b''):
        log.error("Something going wrong")
        client.disconnect()
Exemple #7
0
 def stringReceived(self,data):
     data = bert.decode(data)
     command = str(data[0])
     params = data[1:]
     try:
         attribut=getattr(self, command)
     except AttributeError:
         attribut=getattr(self, "unknown")
         params=data
     attribut(params)
def decode(message_data):
    t = bert.decode(message_data)
    (instrument, bid_price, bid_quantity, offer_price, offer_quantity) = t
    return {
        'instrument': bert.codec.list_to_str(instrument),
        'bid_price': bid_price,
        'bid_quantity': bid_quantity,
        'offer_price': offer_price,
        'offer_quantity': offer_quantity,
    }
Exemple #9
0
 def decode(self, bert_response):
     python_response = bert.decode(bert_response)
     if python_response[0] == bert.Atom('reply'):
         return python_response[1]
     elif python_response[0] == bert.Atom('noreply'):
         return None
     elif python_response[0] == bert.Atom('error'):
         return self._error(python_response[1])
     else:
         raise error.BERTRPCError('invalid response received from server')
Exemple #10
0
def decode(message_data):
	t = bert.decode(message_data)
	(instrument, bid_price, bid_quantity, offer_price, offer_quantity) = t
	return {
		'instrument':bert.codec.list_to_str(instrument),
		'bid_price':bid_price,
		'bid_quantity':bid_quantity,
		'offer_price':offer_price,
		'offer_quantity':offer_quantity,
		}
Exemple #11
0
 def decode(self, bert_response):
     python_response = bert.decode(bert_response)
     if python_response[0] == bert.Atom('reply'):
         return python_response[1]
     elif python_response[0] == bert.Atom('noreply'):
         return None
     elif python_response[0] == bert.Atom('error'):
         return self._error(python_response[1])
     else:
         raise error.BERTRPCError('invalid response received from server')
Exemple #12
0
def parser(client, payload, main_number, mime, message_type=None):
    data = bert.decode(bytes(payload))
    global main_id
    global friend_id
    global chat
    global message_id

    if data[0] == Atom("Profile"):
        for field in data[3][0][6]:
            if field[-1] == Atom('friend'):
                if field[1].split(b'_')[0] == string_to_bytes(main_number):
                    log.debug('Main profile found')
                    main_id = field[1]
                    friend_id = field[1]
                    chat = p2p(from_user=main_id, to=main_id)

        client.publish(topic="events/1//api/anon//",
                       payload=bytearray(
                           message_model(mime,
                                         container=Atom('chain'),
                                         feed_id=chat,
                                         from_user=main_id,
                                         to=main_id)),
                       qos=2,
                       retain=False)

    if data[0] == Atom(
            'Message') and message_type == 'delete for me' and data[-1] == []:
        message_id = data[1]
        client.publish(topic="events/1//api/anon//",
                       payload=bytearray(
                           send_message(main_id, friend_id, chat, mime,
                                        message_id, message_type, main_id)),
                       qos=2,
                       retain=False)

    elif data[0] == Atom('Message') and data[-1] == Atom('delete'):
        log.debug('Verify group patched')
        Verify.true(data[1], "No message ID")
        client.disconnect()

    elif data[0] == Atom('Message'):
        log.debug('Verify group patched')
        Verify.true(data[1], "No message ID")
        client.disconnect()

    elif data == (Atom('io'), (Atom('error'), Atom('invalid_data')), b''):
        log.error("Something going wrong")
        client.disconnect()
        raise InvalidData("Invalid data response")

    if data == (Atom('io'), (Atom('error'), Atom('permission_denied')), b''):
        log.error("Something going wrong")
        client.disconnect()
        raise PermissionDenied("No permission")
Exemple #13
0
def parser(client, payload, main_number, friend_phone):
    data = bert.decode(bytes(payload))

    if data[0] == Atom('Profile') and data[8] == 'init':
        roas = (bert.decode(bytes(payload))[3])
        global user_id
        user_id = roas[0][1]
        client.publish(topic="events/1//api/anon//",
                       payload=bytearray(
                           search(user_id=user_id,
                                  ref='phone',
                                  field='phone',
                                  type_r=Atom('=='),
                                  value=[friend_phone],
                                  status=Atom('contact'))),
                       qos=2,
                       retain=False)

    if data[0] == Atom('io') and data[1] == (Atom('ok'), b'phone'):
        if data[2][6]:
            friend_id = data[2][6][0][1]
            my = main_number + '_' + str(user_id)
            log.debug("Add user {} \r\n".format(str(friend_id)))
            client.publish(topic="events/1//api/anon//",
                           payload=bytearray(
                               friend(my_id=my,
                                      friend_id=friend_id,
                                      status=Atom('request'))),
                           qos=2,
                           retain=False)
        if not data[2][6]:
            log.debug('Contact not found')
            log.debug(data)
            client.disconnect()

    if data == (Atom('io'), (Atom('error'), Atom('invalid_data')), b''):
        log.error("Something going wrong")
        client.disconnect()

    if data == (Atom('io'), (Atom('error'), Atom('permission_denied')), b''):
        log.error("Something going wrong")
        client.disconnect()
Exemple #14
0
def parser(client, payload, main_number):
    data = bert.decode(bytes(payload))

    for node in data:
        if node == Atom('Profile') and data[8] == 'init':
            roster = (bert.decode(bytes(payload))[3])
            user_id = roster[0][1]
            my = main_number + '_' + str(user_id)
            contacts = data[3][0][6]
            for field in contacts:
                if field[0] == Atom('Contact') and field[-1] == Atom('authorization'):
                    client.publish(topic="events/1//api/anon//", payload=bytearray(
                        friend(my_id=my, friend_id=field[1], status=Atom('confirm'))), qos=2, retain=False)

    if data == (Atom('io'), (Atom('error'), Atom('invalid_data')), b''):
        log.error("Something going wrong")
        client.disconnect()
        raise InvalidData("Invalid data response")

    if data == (Atom('io'), (Atom('error'), Atom('permission_denied')), b''):
        log.error("Something going wrong")
        client.disconnect()
        raise PermissionDenied("No permission")
Exemple #15
0
def parser(client, payload, threadNumber):
    data = bert.decode(bytes(payload))

    for node in data:
        if node == (Atom('ok'), Atom('sms_sent')):
            client.publish(topic="events/1//api/anon//",
                           payload=bytearray(sms(threadNumber)),
                           qos=2,
                           retain=False)

        if node == Atom('Profile') and data[8] == 'remove':
            print('User {} deleted'.format(str(threadNumber)))
            client.disconnect()

        if node == Atom('Profile') and data[8] == 'init':
            client.publish(topic="events/1//api/anon//",
                           payload=bytearray(delete_user(threadNumber)),
                           qos=2,
                           retain=False)
Exemple #16
0
    def run(self):
        bc_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        bc_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        bc_socket.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
        bc_socket.bind(('',self.bcport))

        while not self.terminate:
            i,o,r = select.select([bc_socket], [], [], 1)
            for sock in i:
                message , address = sock.recvfrom(8192)
                if self.verbose: print "\tReceived broadcast from %s" % (str(address))

                msg = bert.decode(message)
                #print "msg= %s" % (str(msg))

                msg = bert.encode(('reply', (socket.getfqdn(), self.port)))

                try:
                    sock.sendto(msg, address)
                except:
                    pass
Exemple #17
0
def parser(client, payload, new_alias):
    data = bert.decode(bytes(payload))
    global room_id
    global member_id

    if data[0] == Atom("Profile"):
        for field in data:
            if field and list == type(field):
                for room in field[0]:
                    if room and list == type(room) and room[0][0] == Atom(
                            'Room'):
                        for member_field in room[-1]:
                            if member_field and list == type(member_field) and tuple == type(member_field[0]) \
                                    and member_field[0][0] == Atom('Member'):
                                global member_id
                                member_id = member_field[0][1]

        client.publish(topic="events/1//api/anon//",
                       payload=bytearray(
                           member(member_id=member_id,
                                  container=Atom('chain'),
                                  alias=new_alias,
                                  status=Atom('patch'))),
                       qos=2,
                       retain=False)

    if data[0] == Atom('Member'):
        log.debug('Verify member patched')
        Verify.equals(string_to_bytes(new_alias), data[11], 'Not new alias')
        client.disconnect()

    if data == (Atom('io'), (Atom('error'), Atom('invalid_data')), b''):
        log.error("Something going wrong")
        client.disconnect()
        raise InvalidData("Invalid data response")

    if data == (Atom('io'), (Atom('error'), Atom('permission_denied')), b''):
        log.error("Something going wrong")
        client.disconnect()
        raise PermissionDenied("No permission")
Exemple #18
0
def parser(client, payload, room_name):
    data = bert.decode(bytes(payload))
    global room_id
    global my_alias

    if data[0] == Atom("Profile"):
        for field in data:
            if field and list == type(field):
                for room in field[0]:
                    if room and list == type(room) and room[0][0] == Atom('Room'):
                        global room_id
                        room_id = room[-1][1]

        global my_alias
        my_alias = data[3][0][4] if data[3][0][4] else data[3][0][2]+data[3][0][3]
        client.publish(topic="events/1//api/anon//", payload=bytearray(
            patch_group(room_id, room_name)), qos=2,
                       retain=False)

    if data[0] == Atom('Message'):
        log.debug('Verify group patched')
        for field in data:
            if field and list == type(field) and tuple == type(field[0]):
                print(field[0][3])
                Verify.equals(b'Group is renamed to "'+string_to_bytes(room_name)+b'"', field[0][3], 'No message about patch')
        client.disconnect()

    if data == (Atom('io'), (Atom('error'), Atom('invalid_data')), b''):
        log.error("Something going wrong")
        client.disconnect()
        raise InvalidData("Invalid data response")

    if data == (Atom('io'), (Atom('error'), Atom('permission_denied')), b''):
        log.error("Something going wrong")
        client.disconnect()
        raise PermissionDenied("No permission")
Exemple #19
0
def parser(chat_type,
           client,
           payload,
           main_number,
           friend_number,
           mime,
           message_type=None):
    data = bert.decode(bytes(payload))
    global main_id
    global friend_id
    global p2p_chat
    global group_chat
    global message_id
    global member_id
    global group_friend_id

    if data[0] == Atom("Profile"):
        for field in data[3][0][6]:
            if field[-1] == Atom('friend'):
                if field[8]:
                    p2p_chat = field[8][3]

        group_chat = data[3][0][7][-1][7][0][3]
        group_friend_id = data[3][0][7][-1][1]

        if chat_type == 'p2p' or chat_type == 'myself':
            for field in data[3][0][6]:
                if field[-1] == Atom('friend'):
                    if field[1].split(b'_')[0] == string_to_bytes(main_number):
                        log.debug('Main profile found')
                        main_id = field[1]
                        if chat_type == 'myself':
                            friend_id = main_id
                            message_id = field[8][1]
                            p2p_chat = field[8][3]
                        if chat_type == 'p2p':
                            if field[0] == Atom('Contact') and field[-1] == Atom('friend') and \
                                    field[1].split(b'_')[0] == string_to_bytes(friend_number):
                                friend_id = field[1]
                                if field[8]:
                                    message_id = field[8][1]
                                    p2p_chat = field[8][3]

            feature_model = feature(id='Autotest_feature_id' +
                                    str(time.time()).split('.')[0],
                                    key='TimeZone',
                                    value='Europe/Kiev',
                                    group='JOB_TIMEZONE')
            message_model = bert.decode(
                send_message(main_id, friend_id, p2p_chat, mime, data[1],
                             message_type))
            act_model = act(name='publish', data=main_id)
            time_plus_ten_min = (int(str(time.time()).split('.')[0]) +
                                 6000) * 1000
            client.publish(topic="events/1//api/anon//",
                           payload=bytearray(
                               job(feed_id=act_model,
                                   time=time_plus_ten_min,
                                   data=[message_model],
                                   settings=feature_model,
                                   status=Atom('init'))),
                           qos=2,
                           retain=False)

        if chat_type == 'group':
            for field in data[3][0][6]:
                if field[-1] == Atom('friend'):
                    if field[1].split(b'_')[0] == string_to_bytes(main_number):
                        log.debug('Main profile found')
                        main_id = field[1]

            message_id = data[3][0][7][-1][15][1]
            friend_id = data[3][0][7][-1][1]
            member_id = data[3][0][7][-1][7][0][1]

            log.debug('Send job')
            feature_model = feature(id='Autotest_feature_id' +
                                    str(time.time()).split('.')[0],
                                    key='TimeZone',
                                    value='Europe/Kiev',
                                    group='JOB_TIMEZONE')
            message_model = bert.decode(
                send_message(main_id, group_friend_id, group_chat, mime,
                             data[1], message_type))

            act_model = act(name='publish', data=main_id)
            time_plus_ten_min = (int(str(time.time()).split('.')[0]) +
                                 600) * 1000
            client.publish(topic="events/1//api/anon//",
                           payload=bytearray(
                               job(feed_id=act_model,
                                   time=time_plus_ten_min,
                                   data=[message_model],
                                   settings=feature_model,
                                   status=Atom('init'))),
                           qos=2,
                           retain=False)

    elif data[0] == Atom('Job') and data[-1] == Atom('pending'):
        log.debug('Verify job go to pending')
        Verify.true(data[0] == Atom('Job') and data[-1] == Atom('pending'),
                    'Job not in pending')
        client.disconnect()

    elif data == (Atom('io'), (Atom('error'), Atom('invalid_data')), b''):
        log.error("Something going wrong")
        client.disconnect()
        raise InvalidData("Invalid data response")

    if data == (Atom('io'), (Atom('error'), Atom('permission_denied')), b''):
        log.error("Something going wrong")
        client.disconnect()
        raise PermissionDenied("No permission")
Exemple #20
0
 def on_message(self, client, userdata, msg):
     data = bert.decode(bytes(msg.payload))
     log.info('=' * 5 + 'RESPONSE' + '=' * 5 + '\r\n' + str(data) + '\r\n')
     send_message_parser.parser(self.chat_type, client, msg.payload,
                                MAIN_NUMBER, FRIEND_NUMBER, self.mime,
                                self.message_type, self.message_text)
Exemple #21
0
def decodePayload(payload):
    return bert.decode(payload)
Exemple #22
0
def parser(chat_type,
           client,
           payload,
           main_number,
           friend_number,
           mime,
           message_type=None):
    data = bert.decode(bytes(payload))
    global main_id
    global friend_id
    global p2p_chat
    global group_chat
    global message_id
    global member_id
    global group_friend_id

    if data[0] == Atom("Profile"):
        for field in data[3][0][6]:
            if field[-1] == Atom('friend'):
                if field[8]:
                    p2p_chat = field[8][3]

        group_chat = data[3][0][7][-1][7][0][3]
        group_friend_id = data[3][0][7][-1][1]
        for field in data[3][0][6]:
            if field[0] == Atom('Contact') and field[-1] == Atom('friend') and \
                    field[1].split(b'_')[0] == string_to_bytes(friend_number):
                friend_id = field[1]

        if chat_type == 'p2p':
            for field in data[3][0][6]:
                if field[-1] == Atom('friend'):
                    if field[1].split(b'_')[0] == string_to_bytes(main_number):
                        log.debug('Main profile found')
                        main_id = field[1]
                    if field[0] == Atom('Contact') and field[-1] == Atom('friend') and \
                            field[1].split(b'_')[0] == string_to_bytes(friend_number):
                        friend_id = field[1]
                    if field[8]:
                        message_id = field[8][1]
            d = send_message(main_id,
                             friend_id,
                             p2p_chat,
                             mime,
                             message_id,
                             message_type,
                             message_text=message_text)
            log.info('=' * 5 + 'REQUEST' + '=' * 5 + '\r\n' +
                     str(bert.decode(d)) + '\r\n')
            client.publish(topic="events/1//api/anon//",
                           payload=bytearray(d),
                           qos=2,
                           retain=False)

        if chat_type == 'group':
            for field in data[3][0][6]:
                if field[-1] == Atom('friend'):
                    if field[1].split(b'_')[0] == string_to_bytes(main_number):
                        log.debug('Main profile found')
                        main_id = field[1]

            message_id = data[3][0][7][-1][15][1]
            member_id = data[3][0][7][-1][7][0][1]

            d = send_message(main_id,
                             group_friend_id,
                             group_chat,
                             mime,
                             message_id,
                             message_type,
                             message_text=message_text)
            log.info('=' * 5 + 'REQUEST' + '=' * 5 + '\r\n' +
                     str(bert.decode(d)) + '\r\n')
            client.publish(topic="events/1//api/anon//",
                           payload=bytearray(d),
                           qos=2,
                           retain=False)

    elif data[0] == Atom('Message') and data[11] == [Atom('forward')]:
        log.debug('Verify')
        log.debug(data)
        client.disconnect()

    elif data[0] == Atom('Message'):
        log.debug('Send job')
        message_model = []
        if chat_type == 'p2p':
            message_model = bert.decode(
                send_message(main_id,
                             group_friend_id,
                             group_chat,
                             mime,
                             data[1],
                             message_type='forward',
                             message_text=message_text))
        elif chat_type == 'group':
            message_model = bert.decode(
                send_message(main_id,
                             friend_id,
                             p2p_chat,
                             mime,
                             data[1],
                             message_type='forward',
                             message_text=message_text))
        act_model = act(name='publish', data=main_id)
        client.publish(topic="events/1//api/anon//",
                       payload=bytearray(
                           job(feed_id=act_model,
                               data=[message_model],
                               status=Atom('init'))),
                       qos=2,
                       retain=False)

    elif data == (Atom('io'), (Atom('error'), Atom('invalid_data')), b''):
        log.error("Something going wrong")
        client.disconnect()
        raise InvalidData("Invalid data response")

    if data == (Atom('io'), (Atom('error'), Atom('permission_denied')), b''):
        log.error("Something going wrong")
        client.disconnect()
        raise PermissionDenied("No permission")
Exemple #23
0
 def _decodeMessage(self, message):
     ''' Decode a bert message'''
     return bert.decode(message)
Exemple #24
0
 def on_message(self, client, userdata, msg):
     data = bert.decode(bytes(msg.payload))
     log.info('='*5 + 'RESPONSE' + '='*5 + '\r\n'+ str(data) + '\r\n')
     delete.parser(client, msg.payload, MAIN_NUMBER)
Exemple #25
0
 def on_message(self, client, userdata, msg):
     data = bert.decode(bytes(msg.payload))
     log.info('=' * 5 + 'RESPONSE' + '=' * 5 + '\r\n' + str(data) + '\r\n')
     registration_parser.parser(client, msg.payload, FRIEND_FIRST_NAME,
                                FRIEND_LAST_NAME, FRIEND_USER_NAME)
Exemple #26
0
 def read_berp(self):
     packet_size = self.read_size()
     return bert.decode(self.rfile.read(packet_size)) if packet_size else None
Exemple #27
0
def parser(client,
           payload,
           main_number,
           friend_phone,
           avatar=False,
           alias_check=False):
    data = bert.decode(bytes(payload))
    global user_id
    global main_first_name
    global main_last_name

    if data[0] == Atom('Profile') and data[8] == 'init':
        contacts = data[3][0][6]
        for field in contacts:
            if field[0] == Atom('Contact') and field[1].split(
                    b'_')[0] == string_to_bytes(main_number):
                log.debug('Main profile found')
                user_id = main_id = field[1]
                main_first_name = field[3]
                main_last_name = field[4]
                main_alias = []
                if field[5]:
                    main_alias = field[5]
            if field[0] == Atom('Contact') and field[-1] == Atom('friend') and \
                    field[1].split(b'_')[0] == string_to_bytes(friend_phone):
                friend_id = field[1]
                friend_first_name = field[3]
                friend_last_name = field[4]
                friend_alias = []
                if field[5]:
                    friend_alias = field[5]
        client.publish(topic="events/1//api/anon//",
                       payload=bytearray(
                           create_group(main_id, main_first_name,
                                        main_last_name, main_alias, friend_id,
                                        friend_first_name, friend_last_name,
                                        friend_alias, avatar)),
                       qos=2,
                       retain=False)

    if data[0] == Atom('Room') and alias_check:
        log.info('Verify group created and alias exist')
        Verify.true(
            (data[15][10][0][3] == user_id + b' created the group' and ([
                field[0][11] for field in data if field and list == type(field)
                and int != type(field[0]) and field[0][-1] == Atom("admin")
            ][0] == main_first_name + main_last_name)),
            "No message about creation")
        client.disconnect()

    elif data[0] == Atom('Room'):
        log.info("Verify group creation")
        Verify.true((data[15][10][0][3] == user_id + b' created the group' and
                     (data[8] != [] if avatar else True)),
                    "No message about creation")
        client.disconnect()

    if data == (Atom('io'), (Atom('error'), Atom('invalid_data')), b''):
        log.error("Something going wrong")
        client.disconnect()
        raise InvalidData("Invalid data response")

    if data == (Atom('io'), (Atom('error'), Atom('permission_denied')), b''):
        log.error("Something going wrong")
        client.disconnect()
        raise PermissionDenied("No permission")
Exemple #28
0
 def read_berp(self, input):
     packet_size = self.read_4(input)
     if packet_size == None:
         return None
     ber = input.read(packet_size)
     return bert.decode(ber)
Exemple #29
0
 def on_message(self, client, userdata, msg):
     print(msg.topic)
     print(bert.decode(bytes(msg.payload)))
Exemple #30
0
def parser(client,
           payload,
           first_name=None,
           last_name=None,
           user_name=None,
           avatar=None):
    data = bert.decode(bytes(payload))

    if data[0] == Atom('Profile') and (data[-1]) == Atom('init'):
        roas = (bert.decode(bytes(payload))[3])
        userid = roas[0][1]
        if user_name:
            first_name = ''
            last_name = ''
            avatar = []
            status = Atom('nick')
        elif avatar:
            first_name = []
            last_name = []
            user_name = ''
            status = Atom('patch')
        else:
            avatar = []
            status = Atom('patch')
        client.publish(topic="events/1//api/anon//",
                       payload=bytearray(
                           roster(user_id=userid,
                                  first_name=first_name,
                                  last_name=last_name,
                                  my_username='',
                                  avatar=avatar,
                                  status=status)),
                       qos=2,
                       retain=False)

    if data[0] == Atom('Roster') and (data[-1]) == Atom('nick'):
        log.info("Verify roster/nick updated")
        Verify.true(data[5] == string_to_bytes(user_name),
                    'Username does not set')
        client.disconnect()

    elif data[0] == Atom('Roster') and (data[-1]) == Atom('patch') and avatar:
        log.info("Verify roster/avatar updated")
        Verify.true(data[11] == string_to_bytes(avatar),
                    'Username does not set')
        client.disconnect()

    elif data[0] == Atom('Roster') and (data[-1]) == Atom('patch'):
        log.info("Verify roster/name updated")
        Verify.true(data[2] == string_to_bytes(first_name),
                    'Username does not set')
        client.disconnect()

    elif data == (Atom('io'), (Atom('error'), Atom('invalid_data')), b'') or data == \
            (Atom('io'), (Atom('error'), Atom('invalid_nick')), b''):
        log.error("Something going wrong")
        client.disconnect()
        raise InvalidData("Invalid data response")

    if data == (Atom('io'), (Atom('error'), Atom('permission_denied')), b''):
        log.error("Something going wrong")
        client.disconnect()
        raise PermissionDenied("No permission")
Exemple #31
0
def create_group(main_id, main_firstname, main_lastname, main_alias, friend_id,
                 friend_firstname, friend_lastname, friend_alias,
                 group_avatar):
    module = Atom('Room')
    room_id = 'Autotest_group_id' + str(
        time.time()).split('.')[0]  # id          = [] :: [] | binary(),
    name = magic.get_word  # name        = [] :: [] | binary(),
    links = []
    description = []  # description = [] :: [] | binary(),
    settings = []  # settings    = [] :: list(),

    friend_member = member(container=Atom('chain'),
                           phone_id=friend_id,
                           names=friend_firstname,
                           surnames=friend_lastname,
                           alias=friend_alias,
                           status=Atom('member'))
    main_admin = member(container=Atom('chain'),
                        phone_id=main_id,
                        names=main_firstname,
                        surnames=main_lastname,
                        alias=main_alias,
                        status=Atom('admin'))

    members = [bert.decode(friend_member)
               ]  # members     = [] :: list(#'Member'{}),
    admins = [bert.decode(main_admin)
              ]  # admins      = [] :: list(#'Member'{}),
    data = []  # data        = [] :: [] | list(#'Desc'{}),
    room_type = Atom(
        'group')  # type        = [] :: [] | atom() | group | channel,
    tos = []  # tos         = [] :: [] | binary(),
    tos_update = []  # tos_update  = 0  :: [] | integer(),
    unread = []  # unread      = 0  :: [] | integer(),
    mentions = []  # mentions    = [] :: [] | list(integer()),
    readers = []  # readers     = [] :: list(integer()),
    last_msg = []  # last_msg    = [] :: [] | #'Message'{},
    update = []  # update      = 0  :: [] | integer(),
    created = []  # created     = 0  :: [] | integer(),
    room_status = Atom(
        'create'
    )  # status      = [] :: [] | create | leave| add | remove | patch | get | delete | last_msg}).
    if group_avatar:
        avatar_module = Atom('Desc')
        avatar_id = 'Autotest_avatar' + str(time.time()).split('.')[0]
        mime = 'image'
        avatar_payload = "https://s3-us-west-2.amazonaws.com/nynja-defaults/Image_" \
                         "153310818583129_86FC1EF5-C297-4A1A-9FA1-A7D3C5E27E0E1533108186.jpg"
        parentid = []
        avatar_data = []
        data = [(avatar_module, avatar_id, mime, avatar_payload, parentid,
                 avatar_data)]

    request_f = (module, room_id, name, links, description, settings, members,
                 admins, data, room_type, tos, tos_update, unread, mentions,
                 readers, last_msg, update, created, room_status)

    request = bert.encode(request_f)
    log.info('=' * 5 + 'REQUEST' + '=' * 5 + '\r\n' + str(request_f) + '\r\n')
    log.debug("Send group creation request")
    log.debug(request_f)
    return request
Exemple #32
0
 def read_berp(self, input):
     packet_size = self.read_4(input)
     if packet_size == None:
         return None
     ber = input.read(packet_size)
     return bert.decode(ber)
Exemple #33
0
def parser(client, payload, name, main_number, friend_phone, avatar=False, alias_check=False, group_avatar=None):
    data = bert.decode(bytes(payload))
    global user_id
    global main_id
    global main_first_name
    global main_last_name
    global main_alias
    global friend_id
    global friend_first_name
    global friend_last_name
    global friend_alias

    if data[0] == Atom('Profile') and data[8] == 'init':
        contacts = data[3][0][6]
        for field in contacts:
            if field[0] == Atom('Contact') and field[1].split(b'_')[0] == string_to_bytes(main_number):
                log.debug('Main profile found')
                user_id = main_id = field[1]
                main_first_name = field[3]
                main_last_name = field[4]
                main_alias = []
                if field[5]:
                    main_alias = field[5]
            if field[0] == Atom('Contact') and field[-1] == Atom('friend') and \
                    field[1].split(b'_')[0] == string_to_bytes(friend_phone):
                friend_id = field[1]
                friend_first_name = field[3]
                friend_last_name = field[4]
                friend_alias = []
                if field[5]:
                    friend_alias = field[5]
        room_id = 'Autotest_group_id'+str(time.time()).split('.')[0]
        friend_member = member(container=Atom('chain'), phone_id=friend_id, names=friend_first_name,
                               surnames=friend_last_name, alias=friend_alias, status=Atom('member'))
        main_admin = member(container=Atom('chain'), phone_id=main_id, names=main_first_name, surnames=main_last_name,
                            alias=main_alias, status=Atom('admin'))
        room_data = []
        if group_avatar:
            avatar_module = Atom('Desc')
            avatar_id = 'Autotest_avatar' + str(time.time()).split('.')[0]
            mime = 'image'
            avatar_payload = "https://s3-us-west-2.amazonaws.com/nynja-defaults/Image_" \
                             "153310818583129_86FC1EF5-C297-4A1A-9FA1-A7D3C5E27E0E1533108186.jpg"
            parentid = []
            avatar_data = []
            room_data = [(avatar_module, avatar_id, mime, avatar_payload, parentid, avatar_data)]

        client.publish(topic="events/1//api/anon//", payload=bytearray(
            room(room_id=room_id,name=name,members=[bert.decode(friend_member)], admins=[bert.decode(main_admin)],
                 data=room_data, room_status=Atom('create'))), qos=2, retain=False)

    if data[0] == Atom('Room') and alias_check:
        log.info('Verify group created and alias exist')
        Verify.true((data[15][10][0][3] == user_id + b' created the group' and
                     ([field[0][11] for field in data if field and list == type(field) and int != type(field[0]) and
                       field[0][-1] == Atom("admin")][0] == main_first_name + main_last_name)),
                    "No message about creation")
        client.disconnect()

    elif data[0] == Atom('Room'):
        log.info("Verify group creation")
        Verify.true((data[15][10][0][3] == user_id + b' created the group' and
                     (data[8] != [] if avatar else True)), "No message about creation")
        client.disconnect()

    elif data == (Atom('io'), (Atom('error'), Atom('invalid_data')), b''):
        log.error("Something going wrong")
        client.disconnect()
        raise InvalidData("Invalid data response")

    elif data == (Atom('io'), (Atom('error'), Atom('permission_denied')), b''):
        log.error("Something going wrong")
        client.disconnect()
        raise PermissionDenied("No permission")