Esempio n. 1
0
        /// <summary>
        /// Detects that program does't network interaction accordin to SMTP e-mail protocol.
        /// Fully mirrored
        /// </summary>
        /// <param name="socket_connected_out">Mirrored</param>
        /// <param name="joined_send_api">Mirrored</param>
        /// /// <returns>Place with unique set of objects from where more than min_to_read bytes were read by program. This procedure DELETES from {place with read behavior}</returns>
        private Place Detect_SMTP(Place socket_connected, Place joined_send_api)
        {
            Place joined_send_api_mirror = CPNetBlocks.mirrorWithRemoval(joined_send_api);

            string[] smtp_prefixes_array = new string[] { "MAIL FROM:", "RCPT TO:", "DATA" };

            Place smtp_sequencer = CPNetBlocks.getPlaceClosedByZwClose("SMTP_sequencer", "SocketHandle").setPrintLevel(Place.PrintLevel.Low);

            CPNetBlocks.assembleDiInputStructure(joined_send_api_mirror,
                                                 Delete.Yes,
                                                 CPNetBlocks.mirrorWithRemoval(socket_connected),
                                                 Delete.No,
                                                 smtp_sequencer,
                                                 (token1, token2) => token1["SocketHandle"].Equals(token2["SocketHandle"]) && (CPNetBlocks.begins_with_string(token1["buffer"], "helo") || (CPNetBlocks.begins_with_string(token1["buffer"], "ehlo")))
                                                 ).generating_expression = tuple =>
            {
                Token result = new Token(tuple[joined_send_api_mirror]);
                result.prevTuple        = tuple;
                result["index"]         = 0;
                result["smtp_prefixes"] = smtp_prefixes_array;
                return(result);
            };

            Place smtp_buffers_sent = new Place("SMTP_buffers_sent");

            Transition t_cycle_through_smtp_prefixes = new Transition("t_cycle_through_smtp_prefixes");

            t_cycle_through_smtp_prefixes.addBinaryExpression(joined_send_api_mirror + smtp_sequencer,
                                                              (token1, token2) => token1["SocketHandle"].Equals(token2["SocketHandle"]) &&
                                                              CPNetBlocks.begins_with_string(token1["buffer"], ((string[])token2["smtp_prefixes"])[to_int(token2["index"])])
                                                              );
            new Arc(joined_send_api_mirror, t_cycle_through_smtp_prefixes).enableTokenRemovalFromInput();
            new Arc(smtp_sequencer, t_cycle_through_smtp_prefixes).enableTokenRemovalFromInput();
            Arc output_arc_1 = new Arc(t_cycle_through_smtp_prefixes, smtp_sequencer);

            output_arc_1.filtering_expression  = tuple => to_int(tuple[smtp_sequencer]["index"]) < smtp_prefixes_array.Length - 1;
            output_arc_1.generating_expression = tuple =>
            {
                Token result = new Token(tuple[joined_send_api_mirror]);
                result.prevTuple        = tuple;
                result["index"]         = to_int(tuple[smtp_sequencer]["index"]) + 1;
                result["smtp_prefixes"] = smtp_prefixes_array;
                return(result);
            };
            Arc output_arc_2 = new Arc(t_cycle_through_smtp_prefixes, smtp_buffers_sent);

            output_arc_2.filtering_expression  = tuple => to_int(tuple[smtp_sequencer]["index"]) == smtp_prefixes_array.Length - 1;
            output_arc_2.generating_expression = tuple => { Token result = new Token(tuple[joined_send_api_mirror]); result.prevTuple = tuple; return(result); };

            //			smtp_buffers_sent.addPutReaction(new Place.Reaction(CPNetBlocks.getPrintReactionProvider(ConsoleColor.Yellow).advancedPrintToken));

            return(smtp_buffers_sent);
        }