def read_notify_new_session(data): """Reads and parses a NNS ('Notify New Session') request.""" return { "user": read(data, "S", 0), "session_id": read(data, "S", 2), "clientContext": read_map(data, 4) }
def read_notify_device_access(data): """Reads and parses a MDA ('Notify MPN Device Access') request.""" return { "user": read(data, "S", 0), "sessionId": read(data, "S", 2), "mpnDeviceInfo": _read_mpn_device_info(data, 4) }
def read_notify_new_tables(data): """Reads and parses a NNT ('Notify New Table') request.""" return { "user": read(data, "S", 0), "session_id": read(data, "S", 2), "tableInfos": _read_tables(data, 4) }
def read_notify_user_message(data): """Reads and parses a NUM ('Notify User Message') request.""" return { "user": read(data, 'S', 0), "session_id": read(data, 'S', 2), "message": read(data, 'S', 4) }
def read_notify_user(data): """Reads and parses a NUS ('Notify User') request.""" return { "user": read(data, "S", 0), "password": read(data, "S", 2), "httpHeaders": read_map(data, 4) }
def read_get_items(data): """Reads and parses a GIS ('Get Items') request.""" return { "user": read(data, "S", 0), "group": read(data, "S", 2), "session_id": read(data, "S", 4) }
def read_notify_user_auth(data): """Reads and parses a NUA (extended version of 'Notify User', to carry identification data included in the client SSL certificate)) request. """ return {"user": read(data, "S", 0), "password": read(data, "S", 2), "clientPrincipal": read(data, "S", 4), "httpHeaders": read_map(data, 6)}
def _read_mpn_device_info(data, offset=0): mobile_platform_type = read(data, "P", offset) application_id = read(data, "S", offset + 2) device_token = read(data, "S", offset + 4) return MpnDeviceInfo(mobile_platform_type, application_id, device_token)
def read_get_schema(data): """Reads and parses a GSC ('Get Schema') request.""" return { "user": read(data, "S", 0), "group": read(data, "S", 2), "schema": read(data, "S", 4), "session_id": read(data, "S", 6) }
def read_device_token_change(data): """Reads and parses a MDC ('Notify MPN Subscription Activation') request. """ return { "user": read(data, "S", 0), "sessionId": read(data, "S", 2), "mpnDeviceInfo": _read_mpn_device_info(data, 4), "newDeviceToken": read(data, "S", 10) }
def read_subscription_activation(data): """Reads and parses a MSA ('Notify MPN Subscription Activation') request. """ values = dict() values["user"] = read(data, "S", 0) values["session_id"] = read(data, "S", 2) values["table"] = _read_table(data, 4, False) values["subscription"] = _read_subscription_info(data, 16) return values
def _read_gcm_subscription_info(data, offset): num_of_data = int(read_token(data, offset)) map_start_idx = offset + 11 map_length = num_of_data * 4 return MpnGcmSubscriptionInfo( device=_read_mpn_device_info(data, offset + 1), trigger=read(data, "S", offset + 7), collapse_key=read(data, "S", offset + 9), data=read_map(data, map_start_idx, map_length), delay_while_idle=read(data, "S", map_start_idx + map_length), time_to_live=read(data, "S", map_start_idx + map_length + 2))
def read_subscription_activation(data): """Reads and parses a MSA ('Notify MPN Subscription Activation') request. """ values = dict() values["user"] = read(data, "S", 0) values["session_id"] = read(data, "S", 2) values["table"] = _read_table(data, 4, False) subscription_type = read_token(data, 16) if subscription_type == 'PA': values["subscription"] = _read_apn_subscription_info(data, 17) elif subscription_type == 'PG': values["subscription"] = _read_gcm_subscription_info(data, 17) else: raise RemotingException("Unsupported MPN subscription type") return values
def _read_table(table, offset, with_selector=True): table_info = {'winIndex': read(table, "I", offset), 'mode': read(table, "M", offset + 2), 'group': read(table, "S", offset + 4), 'schema': read(table, "S", offset + 6), 'min': read(table, "I", offset + 8), 'max': read(table, "I", offset + 10), 'selector': (read(table, "S", offset + 12) if with_selector else None)} return TableInfo(table_info['winIndex'], table_info['mode'], table_info['group'], table_info['schema'], table_info['min'], table_info['max'], table_info['selector'])
def _read_apn_subscription_info(data, offset): arg_length = int(read_token(data, offset)) arguments = read_seq(data, offset + 22, arg_length * 2) cust_data_size = int(read_token(data, offset + 1)) custom_data = read_map(data, offset + 22 + arg_length * 2, cust_data_size * 4) return MpnApnsSubscriptionInfo( device=_read_mpn_device_info(data, offset + 2), trigger=read(data, "S", offset + 8), sound=read(data, "S", offset + 10), badge=read(data, "S", offset + 12), localized_action_key=read(data, "S", offset + 14), launch_image=read(data, "S", offset + 16), txt_format=read(data, "S", offset + 18), localized_format_key=read(data, "S", offset + 20), arguments=arguments, custom_data=custom_data)
def read_sub(data): """Reads and parses a SUB ('Subscribe') request.""" return read(data, "S", 0)
def read_notify_tables_close(data): """Reads and parses a NTC ('Notify Table Close') request.""" return {"session_id": read(data, "S", 0), "tableInfos": _read_tables(data, 2)}
def read_get_user_item_data(data): """Reads and parses a GUI ('Get User Item Data') request.""" return {"user": read(data, 'S', 0), "items": read_seq(data, 2)}
def read_notifiy_session_close(data): """Reads and parses a NSC ('Notify Session Close') request.""" return read(data, "S", 0)
def read_usub(data): """Reads and parses a USB ('Unsubscribe') request.""" return read(data, "S", 0)
def _read_subscription_info(data, offset): return MpnSubscriptionInfo(device=_read_mpn_device_info(data, offset), trigger=read(data, "S", offset + 6), notification_format=read(data, "S", offset + 8))