/// <summary>
        /// Creates a SearchResultEntry packet.
        /// </summary>
        /// <param name="context">The user context which contains message ID.</param>
        /// <param name="matchedDn">Matched DN.</param>
        /// <param name="attributes">The attributes and values that are contained in the entry.</param>
        /// <returns>The packet that contains the response.</returns>
        internal override AdtsSearchResultEntryPacket CreateSearchedResultEntry(
            AdtsLdapContext context,
            string matchedDn,
            params KeyValuePair <string, string[]>[] attributes)
        {
            int length = (attributes != null) ? attributes.Length : 0;

            SearchResponse_entry_attributes_element[] attributesElementArray = new SearchResponse_entry_attributes_element[length];
            for (int i = 0; i < length; i++)
            {
                attributesElementArray[i] = new SearchResponse_entry_attributes_element(
                    new AttributeType(attributes[i].Key),
                    CreateAttributeValueSet(attributes[i].Value));
            }
            Asn1SequenceOf <SearchResponse_entry_attributes_element> attributesElements = new Asn1SequenceOf <SearchResponse_entry_attributes_element>(attributesElementArray);

            SearchResponse_entry entry = new SearchResponse_entry(
                new LDAPDN(matchedDn ?? string.Empty),
                attributesElements);

            LDAPMessage_protocolOp operation = new LDAPMessage_protocolOp();

            operation.SetData(LDAPMessage_protocolOp.searchResponse, new SearchResponse(SearchResponse.entry, entry));

            LDAPMessage message = new LDAPMessage(new MessageID(context.MessageId), operation);
            AdtsSearchResultEntryPacket packet = new AdtsSearchResultEntryPacket();

            packet.ldapMessagev2 = message;
            packet.messageId     = context.MessageId;

            return(packet);
        }
예제 #2
0
        /// <summary>
        /// Creates a SearchResultEntry packet.
        /// </summary>
        /// <param name="context">The user context which contains message ID.</param>
        /// <param name="matchedDn">Matched DN.</param>
        /// <param name="attributes">The attributes and values that are contained in the entry.</param>
        /// <returns>The packet that contains the response.</returns>
        internal override AdtsSearchResultEntryPacket CreateSearchedResultEntry(
            AdtsLdapContext context,
            string matchedDn,
            params KeyValuePair <string, string[]>[] attributes)
        {
            int length = (attributes != null) ? attributes.Length : 0;

            PartialAttributeList_element[] partialAttributeElementArray = new PartialAttributeList_element[length];
            for (int i = 0; i < length; i++)
            {
                partialAttributeElementArray[i] = new PartialAttributeList_element(
                    new AttributeDescription(attributes[i].Key),
                    CreateAttributeValueSet(attributes[i].Value));
            }
            PartialAttributeList attributeList = new PartialAttributeList(partialAttributeElementArray);

            SearchResultEntry entry = new SearchResultEntry(
                new LDAPDN(matchedDn ?? string.Empty),
                attributeList);

            LDAPMessage_protocolOp operation = new LDAPMessage_protocolOp();

            operation.SetData(LDAPMessage_protocolOp.searchResEntry, entry);

            LDAPMessage message = new LDAPMessage(new MessageID(context.MessageId), operation, null);
            AdtsSearchResultEntryPacket packet = new AdtsSearchResultEntryPacket();

            packet.ldapMessagev3 = message;
            packet.messageId     = context.MessageId;

            return(packet);
        }
        /// <summary>
        /// Creates a SearchResultEntry packet.
        /// </summary>
        /// <param name="context">The user context which contains message ID.</param>
        /// <param name="matchedDn">Matched DN.</param>
        /// <param name="attributes">The attributes and values that are contained in the entry.</param>
        /// <returns>The packet that contains the response.</returns>
        internal override AdtsSearchResultEntryPacket CreateSearchedResultEntry(
            AdtsLdapContext context,
            string matchedDn,
            params KeyValuePair<string, string[]>[] attributes)
        {
            int length = (attributes != null) ? attributes.Length : 0;

            PartialAttributeList_element[] partialAttributeElementArray = new PartialAttributeList_element[length];
            for (int i = 0; i < length; i++)
            {
                partialAttributeElementArray[i] = new PartialAttributeList_element(
                    new AttributeDescription(attributes[i].Key),
                    CreateAttributeValueSet(attributes[i].Value));
            }
            PartialAttributeList attributeList = new PartialAttributeList(partialAttributeElementArray);

            SearchResultEntry entry = new SearchResultEntry(
                new LDAPDN(matchedDn ?? string.Empty),
                attributeList);

            LDAPMessage_protocolOp operation = new LDAPMessage_protocolOp();
            operation.SetData(LDAPMessage_protocolOp.searchResEntry, entry);

            LDAPMessage message = new LDAPMessage(new MessageID(context.MessageId), operation, null);
            AdtsSearchResultEntryPacket packet = new AdtsSearchResultEntryPacket();
            packet.ldapMessagev3 = message;
            packet.messageId = context.MessageId;

            return packet;
        }
        internal AdtsLdapPacket CreatePacketFromType(Type messageType)
        {
            AdtsLdapPacket packet = null;

            if (messageType == typeof(AbandonRequest))
            {
                packet = new AdtsAbandonRequestPacket();
            }
            else if (messageType == typeof(AddRequest))
            {
                packet = new AdtsAddRequestPacket();
            }
            else if (messageType == typeof(AddResponse))
            {
                packet = new AdtsAddResponsePacket();
            }
            else if (messageType == typeof(BindRequest))
            {
                packet = new AdtsBindRequestPacket();
            }
            else if (messageType == typeof(BindResponse))
            {
                packet = new AdtsBindResponsePacket();
            }
            else if (messageType == typeof(CompareRequest))
            {
                packet = new AdtsCompareRequestPacket();
            }
            else if (messageType == typeof(CompareResponse))
            {
                packet = new AdtsCompareResponsePacket();
            }
            else if (messageType == typeof(DelRequest))
            {
                packet = new AdtsDelRequestPacket();
            }
            else if (messageType == typeof(DelResponse))
            {
                packet = new AdtsDelResponsePacket();
            }
            else if (messageType == typeof(ExtendedRequest))
            {
                packet = new AdtsExtendedRequestPacket();
            }
            else if (messageType == typeof(ExtendedResponse))
            {
                packet = new AdtsExtendedResponsePacket();
            }
            else if (messageType == typeof(ModifyDNRequest))
            {
                packet = new AdtsModifyDnRequestPacket();
            }
            else if (messageType == typeof(ModifyDNResponse))
            {
                packet = new AdtsModifyDnResponsePacket();
            }
            else if (messageType == typeof(ModifyRequest))
            {
                packet = new AdtsModifyRequestPacket();
            }
            else if (messageType == typeof(ModifyResponse))
            {
                packet = new AdtsModifyResponsePacket();
            }
            else if (messageType == typeof(SearchRequest))
            {
                packet = new AdtsSearchRequestPacket();
            }
            else if (messageType == typeof(SearchResultEntry))
            {
                packet = new AdtsSearchResultEntryPacket();
            }
            else if (messageType == typeof(SearchResultReference))
            {
                packet = new AdtsSearchResultReferencePacket();
            }
            else if (messageType == typeof(SearchResultDone))
            {
                packet = new AdtsSearchResultDonePacket();
            }
            else if (messageType == typeof(SicilyBindResponse))
            {
                packet = new AdtsSicilyBindResponsePacket();
            }
            else if (messageType == typeof(UnbindRequest))
            {
                packet = new AdtsUnbindRequestPacket();
            }
            else
            {
                throw new StackException("Unknown message type: " + messageType.ToString());
            }

            return packet;
        }
        internal AdtsLdapPacket CreatePacketFromType(Type messageType)
        {
            AdtsLdapPacket packet = null;

            if (messageType == typeof(AbandonRequest))
            {
                packet = new AdtsAbandonRequestPacket();
            }
            else if (messageType == typeof(AddRequest))
            {
                packet = new AdtsAddRequestPacket();
            }
            else if (messageType == typeof(AddResponse))
            {
                packet = new AdtsAddResponsePacket();
            }
            else if (messageType == typeof(BindRequest))
            {
                packet = new AdtsBindRequestPacket();
            }
            else if (messageType == typeof(BindResponse))
            {
                packet = new AdtsBindResponsePacket();
            }
            else if (messageType == typeof(CompareRequest))
            {
                packet = new AdtsCompareRequestPacket();
            }
            else if (messageType == typeof(CompareResponse))
            {
                packet = new AdtsCompareResponsePacket();
            }
            else if (messageType == typeof(DelRequest))
            {
                packet = new AdtsDelRequestPacket();
            }
            else if (messageType == typeof(DelResponse))
            {
                packet = new AdtsDelResponsePacket();
            }
            else if (messageType == typeof(ExtendedRequest))
            {
                packet = new AdtsExtendedRequestPacket();
            }
            else if (messageType == typeof(ExtendedResponse))
            {
                packet = new AdtsExtendedResponsePacket();
            }
            else if (messageType == typeof(ModifyDNRequest))
            {
                packet = new AdtsModifyDnRequestPacket();
            }
            else if (messageType == typeof(ModifyDNResponse))
            {
                packet = new AdtsModifyDnResponsePacket();
            }
            else if (messageType == typeof(ModifyRequest))
            {
                packet = new AdtsModifyRequestPacket();
            }
            else if (messageType == typeof(ModifyResponse))
            {
                packet = new AdtsModifyResponsePacket();
            }
            else if (messageType == typeof(SearchRequest))
            {
                packet = new AdtsSearchRequestPacket();
            }
            else if (messageType == typeof(SearchResultEntry))
            {
                packet = new AdtsSearchResultEntryPacket();
            }
            else if (messageType == typeof(SearchResultReference))
            {
                packet = new AdtsSearchResultReferencePacket();
            }
            else if (messageType == typeof(SearchResultDone))
            {
                packet = new AdtsSearchResultDonePacket();
            }
            else if (messageType == typeof(SicilyBindResponse))
            {
                packet = new AdtsSicilyBindResponsePacket();
            }
            else if (messageType == typeof(UnbindRequest))
            {
                packet = new AdtsUnbindRequestPacket();
            }
            else
            {
                throw new StackException("Unknown message type: " + messageType.ToString());
            }

            return(packet);
        }
        /// <summary>
        /// Creates a SearchResultEntry packet.
        /// </summary>
        /// <param name="context">The user context which contains message ID.</param>
        /// <param name="matchedDn">Matched DN.</param>
        /// <param name="attributes">The attributes and values that are contained in the entry.</param>
        /// <returns>The packet that contains the response.</returns>
        internal override AdtsSearchResultEntryPacket CreateSearchedResultEntry(
            AdtsLdapContext context,
            string matchedDn,
            params KeyValuePair<string, string[]>[] attributes)
        {
            int length = (attributes != null) ? attributes.Length : 0;

            SearchResponse_entry_attributes_element[] attributesElementArray = new SearchResponse_entry_attributes_element[length];
            for (int i = 0; i < length; i++)
            {
                attributesElementArray[i] = new SearchResponse_entry_attributes_element(
                    new AttributeType(attributes[i].Key),
                    CreateAttributeValueSet(attributes[i].Value));
            }
            Asn1SequenceOf<SearchResponse_entry_attributes_element> attributesElements = new Asn1SequenceOf<SearchResponse_entry_attributes_element>(attributesElementArray);

            SearchResponse_entry entry = new SearchResponse_entry(
                new LDAPDN(matchedDn ?? string.Empty),
                attributesElements);

            LDAPMessage_protocolOp operation = new LDAPMessage_protocolOp();
            operation.SetData(LDAPMessage_protocolOp.searchResponse, new SearchResponse(SearchResponse.entry, entry));

            LDAPMessage message = new LDAPMessage(new MessageID(context.MessageId), operation);
            AdtsSearchResultEntryPacket packet = new AdtsSearchResultEntryPacket();
            packet.ldapMessagev2 = message;
            packet.messageId = context.MessageId;

            return packet;
        }