def debug_receive_associate_rq(self, a_associate_rq): """ Placeholder for a function callback. Function will be called immediately after receiving and decoding an A-ASSOCIATE-RQ Parameters ---------- a_associate_rq - pynetdicom.PDU.A_ASSOCIATE_RQ_PDU The A-ASSOCIATE-RQ PDU instance """ logger.info("Association Received") # Shorthand assoc_rq = a_associate_rq app_context = assoc_rq.application_context_name.title() pres_contexts = assoc_rq.presentation_context user_info = assoc_rq.user_information responding_ae = 'resp. AP Title' their_class_uid = 'unknown' their_version = 'unknown' if user_info.implementation_class_uid: their_class_uid = user_info.implementation_class_uid if user_info.implementation_version_name: their_version = user_info.implementation_version_name s = ['Request Parameters:'] s.append('====================== BEGIN A-ASSOCIATE-RQ ================' '=====') s.append('Their Implementation Class UID: %s' %their_class_uid) s.append('Their Implementation Version Name: %s' %their_version) s.append('Application Context Name: %s' %app_context) s.append('Calling Application Name: %s' %assoc_rq.calling_ae_title.decode('utf-8')) s.append('Called Application Name: %s' %assoc_rq.called_ae_title.decode('utf-8')) s.append('Their Max PDU Receive Size: %s' %user_info.maximum_length) ## Presentation Contexts s.append('Presentation Contexts:') for item in pres_contexts: s.append(' Context ID: %s (Proposed)' %item.ID) s.append(' Abstract Syntax: =%s' %item.abstract_syntax) if item.SCU is None and item.SCP is None: scp_scu_role = 'Default' else: scp_scu_role = '%s/%s' %(item.SCP, item.SCU) s.append(' Proposed SCP/SCU Role: %s' %scp_scu_role) s.append(' Proposed Transfer Syntax(es):') for ts in item.transfer_syntax: s.append(' =%s' %ts) ## Extended Negotiation if assoc_rq.user_information.ext_neg is not None: s.append('Requested Extended Negotiation:') for item in assoc_rq.user_information.ext_neg: s.append(' Abstract Syntax: =%s' %item.UID) #s.append(' Application Information, length: %d bytes' %len(item.app_info)) app_info = wrap_list(item.app_info) app_info[0] = '[' + app_info[0][1:] app_info[-1] = app_info[-1] + ' ]' for line in app_info: s.append(' %s' %line) else: s.append('Requested Extended Negotiation: None') ## Common Extended Negotiation if assoc_rq.user_information.common_ext_neg is not None: s.append('Requested Common Extended Negotiation:') for item in assoc_rq.user_information.common_ext_neg: s.append(' Abstract Syntax: =%s' %item.sop_class_uid) s.append(' Service Class: =%s' %item.service_class_uid) if item.related_general_sop_class_identification != []: s.append(' Related General SOP Class(es):') for sub_field in item.related_general_sop_class_identification: s.append(' =%s' %sub_field) else: s.append(' Related General SOP Classes: None') else: s.append('Requested Common Extended Negotiation: None') ## Asynchronous Operations Window Negotiation async_neg = 'None' if assoc_rq.user_information.async_ops_window is not None: s.append('Requested Asynchronous Operations Window Negotiation:') # FIXME else: s.append('Requested Asynchronous Operations Window Negotiation: None') ## User Identity if user_info.user_identity is not None: usid = user_info.user_identity s.append('Requested User Identity Negotiation:') s.append(' Authentication Mode: %d - %s' %(usid.id_type, usid.id_type_str)) if usid.id_type == 1: s.append(' Username: [%s]' %usid.primary.decode('utf-8')) elif usid.id_type == 2: s.append(' Username: [%s]' %usid.primary.decode('utf-8')) s.append(' Password: [%s]' %usid.secondary.decode('utf-8')) elif usid.id_type == 3: s.append(' Kerberos Service Ticket (not dumped) length: %d' %len(usid.primary)) elif usid.id_type == 4: s.append(' SAML Assertion (not dumped) length: %d' %len(usid.primary)) if usid.response_requested: s.append(' Positive Response requested: Yes') else: s.append(' Positive Response requested: None') else: s.append('Requested User Identity Negotiation: None') s.append('======================= END A-ASSOCIATE-RQ ==================' '====') for line in s: logger.debug(line)
def debug_send_associate_rq(self, a_associate_rq): """ Placeholder for a function callback. Function will be called immediately prior to encoding and sending an A-ASSOCIATE-RQ to a peer AE The default implementation is used for logging debugging information Parameters ---------- a_associate_rq - pynetdicom.PDU.A_ASSOCIATE_RQ_PDU The A-ASSOCIATE-RQ PDU instance to be encoded and sent """ # Shorthand assoc_rq = a_associate_rq app_context = assoc_rq.application_context_name.title() pres_contexts = assoc_rq.presentation_context user_info = assoc_rq.user_information s = ['Request Parameters:'] s.append('====================== BEGIN A-ASSOCIATE-RQ ================' '=====') s.append('Our Implementation Class UID: %s' %user_info.implementation_class_uid) s.append('Our Implementation Version Name: %s' %user_info.implementation_version_name) s.append('Application Context Name: %s' %app_context) s.append('Calling Application Name: %s' %assoc_rq.calling_ae_title.decode('utf-8')) s.append('Called Application Name: %s' %assoc_rq.called_ae_title.decode('utf-8')) s.append('Our Max PDU Receive Size: %s' %user_info.maximum_length) ## Presentation Contexts if len(pres_contexts) == 1: s.append('Presentation Context:') else: s.append('Presentation Contexts:') for context in pres_contexts: s.append(' Context ID: %s (Proposed)' %(context.ID)) s.append(' Abstract Syntax: =%s' %context.abstract_syntax) if 'SCU' in context.__dict__.keys(): scp_scu_role = '%s/%s' %(context.SCP, context.SCU) else: scp_scu_role = 'Default' s.append(' Proposed SCP/SCU Role: %s' %scp_scu_role) # Transfer Syntaxes if len(context.transfer_syntax) == 1: s.append(' Proposed Transfer Syntax:') else: s.append(' Proposed Transfer Syntaxes:') for ts in context.transfer_syntax: s.append(' =%s' %ts.name) ## Extended Negotiation if assoc_rq.user_information.ext_neg is not None: s.append('Requested Extended Negotiation:') for item in assoc_rq.user_information.ext_neg: s.append(' Abstract Syntax: =%s' %item.UID) #s.append(' Application Information, length: %d bytes' %len(item.app_info)) app_info = wrap_list(item.app_info) app_info[0] = '[' + app_info[0][1:] app_info[-1] = app_info[-1] + ' ]' for line in app_info: s.append(' %s' %line) else: s.append('Requested Extended Negotiation: None') ## Common Extended Negotiation if assoc_rq.user_information.common_ext_neg is not None: s.append('Requested Common Extended Negotiation:') for item in assoc_rq.user_information.common_ext_neg: s.append(' Abstract Syntax: =%s' %item.sop_class_uid) s.append(' Service Class: =%s' %item.service_class_uid) if item.related_general_sop_class_identification != []: s.append(' Related General SOP Class(es):') for sub_field in item.related_general_sop_class_identification: s.append(' =%s' %sub_field) else: s.append(' Related General SOP Classes: None') else: s.append('Requested Common Extended Negotiation: None') ## User Identity if user_info.user_identity is not None: usid = user_info.user_identity s.append('Requested User Identity Negotiation:') s.append(' Authentication Mode: %d - %s' %(usid.id_type, usid.id_type_str)) if usid.id_type == 1: s.append(' Username: [%s]' %usid.primary.decode('utf-8')) elif usid.id_type == 2: s.append(' Username: [%s]' %usid.primary.decode('utf-8')) s.append(' Password: [%s]' %usid.secondary.decode('utf-8')) elif usid.id_type == 3: s.append(' Kerberos Service Ticket (not dumped) length: %d' %len(usid.primary)) elif usid.id_type == 4: s.append(' SAML Assertion (not dumped) length: %d' %len(usid.primary)) if usid.response_requested: s.append(' Positive Response requested: Yes') else: s.append(' Positive Response requested: None') else: s.append('Requested User Identity Negotiation: None') s.append('======================= END A-ASSOCIATE-RQ ==================' '====') for line in s: logger.debug(line)