ASC_acceptPresentationContext(
    T_ASC_Parameters * params,
    T_ASC_PresentationContextID presentationContextID,
    const char* transferSyntax,
    T_ASC_SC_ROLE acceptedRole,
    const OFBool alwaysAcceptDefaultRole)
{
    DUL_PRESENTATIONCONTEXT *proposedContext, *acceptedContext;
    OFCondition cond = EC_Normal;
    LST_HEAD *lst;

    proposedContext = findPresentationContextID(
                              params->DULparams.requestedPresentationContext,
                                                presentationContextID);
    if (proposedContext == NULL) return ASC_BADPRESENTATIONCONTEXTID;
    OFStandard::strlcpy(proposedContext->acceptedTransferSyntax, transferSyntax, sizeof(proposedContext->acceptedTransferSyntax));

    /* we want to mark this proposed context as being ok */
    proposedContext->result = ASC_P_ACCEPTANCE;
    proposedContext->acceptedSCRole = ascRole2dulRole(acceptedRole);

    /* Here we check the only role selection case which leads to clear rejection of the
     * proposed presentation context: If the requestor connects with default role but the
     * acceptor explicitly requires the SCP role (only) then the presentation context
     * will be rejected. All other cases do not lead to rejection but to actual "negotiation".
     * DCMTK's behaviour can be seen in the declaration of enum DUL_SC_ROLE (see dul.h).
     * The logic of the role negotiation is implemented in constructSCUSCPRoles() (see dulconst.cc).
     */
    if ( (proposedContext->proposedSCRole == DUL_SC_ROLE_DEFAULT)
      && (proposedContext->acceptedSCRole == DUL_SC_ROLE_SCP) )
    {
      // If user wants to override rejection (e.g. for faulty clients), skip the check but print warning
      if (alwaysAcceptDefaultRole)
      {
        DCMNET_WARN("ASSOC: Deliberately accepting Default role proposed by association requestor, "
            << "while originally being configured for role SCP only");
      }
      else
      {
        proposedContext->result = ASC_P_NOREASON;
          DCMNET_ERROR("ASSOC: SCP/SCU role selection failed, Default role (i.e. SCU) proposed "
              << "but only SCP role configured for acceptance");
          return ASC_SCPSCUROLESELECTIONFAILED;
      }
    }

    acceptedContext = findPresentationContextID(
                              params->DULparams.acceptedPresentationContext,
                                                presentationContextID);

    if (acceptedContext != NULL) {
        /* it is already in the list, mark it as accepted */
        acceptedContext->result = ASC_P_ACCEPTANCE;
        OFStandard::strlcpy(acceptedContext->abstractSyntax,
               proposedContext->abstractSyntax, sizeof(acceptedContext->abstractSyntax));
        OFStandard::strlcpy(acceptedContext->acceptedTransferSyntax, transferSyntax, sizeof(acceptedContext->acceptedTransferSyntax));
        acceptedContext->proposedSCRole = proposedContext->proposedSCRole;
        acceptedContext->acceptedSCRole = ascRole2dulRole(acceptedRole);
    } else {
        /*
         * make a new presentation context, mark it as accepted and add to
         * end of accepted list
         */

        cond = DUL_MakePresentationCtx(
            &acceptedContext,
            proposedContext->proposedSCRole, ascRole2dulRole(acceptedRole),
            presentationContextID, ASC_P_ACCEPTANCE,
            proposedContext->abstractSyntax,
            (char*)transferSyntax, NULL);
        if (cond.bad()) return cond;

        lst = params->DULparams.acceptedPresentationContext;
        if (lst == NULL) {
            lst = LST_Create();
            if (lst == NULL) return EC_MemoryExhausted;
        }

        LST_Enqueue(&lst, (LST_NODE*)acceptedContext);
        params->DULparams.acceptedPresentationContext = lst;
    }
    return EC_Normal;
}