Esempio n. 1
0
        /**
         * Driver listens over TCP for incoming HTTP data. Driver
         * is providing a web-service style endpoint so POS behavior
         * does not have to change. Rather than POSTing information to
         * a remote processor it POSTs information to the driver.
         *
         * Driver strips off headers, feeds XML into the dsiEMVX control,
         * then sends the response back to the client.
         */
        public override void Read()
        {
            initDevice();
            TcpListener http = new TcpListener(IPAddress.Loopback, LISTEN_PORT);

            http.Start();
            byte[] buffer = new byte[10];
            while (SPH_Running)
            {
                try {
                    using (TcpClient client = http.AcceptTcpClient()) {
                        client.ReceiveTimeout = 100;
                        using (NetworkStream stream = client.GetStream()) {
                            string message    = "";
                            int    bytes_read = 0;
                            do
                            {
                                bytes_read = stream.Read(buffer, 0, buffer.Length);
                                message   += System.Text.Encoding.ASCII.GetString(buffer, 0, bytes_read);
                            } while (stream.DataAvailable);

                            if (rba != null)
                            {
                                rba.stubStop();
                            }

                            message = GetHttpBody(message);
                            // Send EMV messages to EMVX, others
                            // to PDCX
                            string result = "Error";
                            if (message.Contains("EMV"))
                            {
                                result = ProcessEMV(message, true);
                            }
                            else if (message.Length > 0)
                            {
                                result = ProcessPDC(message);
                            }
                            result = WrapHttpResponse(result);
                            if (this.verbose_mode > 0)
                            {
                                Console.WriteLine(result);
                            }

                            byte[] response = System.Text.Encoding.ASCII.GetBytes(result);
                            stream.Write(response, 0, response.Length);
                        }
                        client.Close();
                    }
                } catch (Exception ex) {
                    if (verbose_mode > 0)
                    {
                        Console.WriteLine(ex);
                    }
                }
            }
        }
 public override void SetConfig(string k, string v)
 {
     if (k == "disableRBA" && v == "true")
     {
         try {
             if (this.rba != null)
             {
                 rba.stubStop();
             }
         } catch (Exception) {}
         this.rba = null;
     }
     else if (k == "disableButtons" && v == "true")
     {
         this.rba.SetEMV(RbaButtons.None);
     }
     else if (k == "logXML" && v == "true")
     {
         this.log_xml = true;
     }
 }
Esempio n. 3
0
        /**
         * Driver listens over TCP for incoming HTTP data. Driver
         * is providing a web-service style endpoint so POS behavior
         * does not have to change. Rather than POSTing information to
         * a remote processor it POSTs information to the driver.
         *
         * Driver strips off headers, feeds XML into the dsiEMVX control,
         * then sends the response back to the client.
         */
        public override void Read()
        {
            ReInitDevice();
            TcpListener http = new TcpListener(IPAddress.Any, LISTEN_PORT);

            http.Start();
            byte[] buffer = new byte[10];
            while (SPH_Running)
            {
                string result     = "";
                string keyVal     = "key";
                bool   saveResult = false;
                try {
                    using (TcpClient client = http.AcceptTcpClient()) {
                        client.ReceiveTimeout = 100;
                        using (NetworkStream stream = client.GetStream()) {
                            string message    = "";
                            int    bytes_read = 0;
                            do
                            {
                                bytes_read = stream.Read(buffer, 0, buffer.Length);
                                message   += System.Text.Encoding.ASCII.GetString(buffer, 0, bytes_read);
                            } while (stream.DataAvailable);

                            if (rba != null)
                            {
                                rba.stubStop();
                            }

                            message = GetHttpBody(message);
                            XmlDocument request = new XmlDocument();
                            request.LoadXml(message);
                            keyVal = request.SelectSingleNode("TStream/Transaction/InvoiceNo").InnerXml;
                            // Send EMV messages to EMVX, others
                            // to PDCX
                            if (message.Contains("EMV"))
                            {
                                result     = ProcessEMV(message, true);
                                saveResult = true;
                            }
                            else if (message.Contains("termSig"))
                            {
                                FlaggedReset();
                                result = GetSignature(true);
                            }
                            else if (message.Length > 0)
                            {
                                result     = ProcessPDC(message);
                                saveResult = true;
                            }
                            result = WrapHttpResponse(result);

                            byte[] response = System.Text.Encoding.ASCII.GetBytes(result);
                            stream.Write(response, 0, response.Length);
                        }
                        client.Close();
                    }
                } catch (Exception ex) {
                    this.LogMessage(ex.ToString());
                }
                try {
                    if (saveResult && result.Length > 0)
                    {
                        parent.SqlLog(keyVal, result);
                    }
                } catch (Exception) {
                    this.LogMessage(keyVal + ": " + result);
                }
            }
        }
Esempio n. 4
0
        /**
         * Driver listens over TCP for incoming HTTP data. Driver
         * is providing a web-service style endpoint so POS behavior
         * does not have to change. Rather than POSTing information to
         * a remote processor it POSTs information to the driver.
         *
         * Driver strips off headers, feeds XML into the dsiPDCX control,
         * then sends the response back to the client.
         */
        public override void Read()
        {
            initDevice();
            TcpListener http = new TcpListener(IPAddress.Loopback, LISTEN_PORT);

            http.Start();
            byte[] buffer = new byte[10];
            while (SPH_Running)
            {
                try {
                    using (TcpClient client = http.AcceptTcpClient()) {
                        client.ReceiveTimeout = 100;
                        using (NetworkStream stream = client.GetStream()) {
                            string message    = "";
                            int    bytes_read = 0;
                            do
                            {
                                bytes_read = stream.Read(buffer, 0, buffer.Length);
                                message   += System.Text.Encoding.ASCII.GetString(buffer, 0, bytes_read);
                            } while (stream.DataAvailable);

                            if (rba != null)
                            {
                                rba.stubStop();
                            }

                            message = GetHttpBody(message);
                            message = message.Replace("{{SecureDevice}}", this.device_identifier);
                            message = message.Replace("{{ComPort}}", com_port);
                            message = message.Trim(new char[] { '"' });
                            if (this.verbose_mode > 0)
                            {
                                Console.WriteLine(message);
                            }
                            ax_control.CancelRequest();
                            string result = ax_control.ProcessTransaction(message, 1, null, null);
                            result = WrapHttpResponse(result);
                            if (this.verbose_mode > 0)
                            {
                                Console.WriteLine(result);
                            }

                            byte[] response = System.Text.Encoding.ASCII.GetBytes(result);
                            stream.Write(response, 0, response.Length);
                            if (log_xml)
                            {
                                using (StreamWriter file = new StreamWriter("log.xml", true)) {
                                    file.WriteLine(message);
                                    file.WriteLine(result);
                                }
                            }
                        }
                        client.Close();
                    }
                } catch (Exception ex) {
                    if (verbose_mode > 0)
                    {
                        Console.WriteLine(ex);
                    }
                }
            }
        }
Esempio n. 5
0
        /**
         * Driver listens over TCP for incoming HTTP data. Driver
         * is providing a web-service style endpoint so POS behavior
         * does not have to change. Rather than POSTing information to
         * a remote processor it POSTs information to the driver.
         *
         * Driver strips off headers, feeds XML into the dsiEMVX control,
         * then sends the response back to the client.
         */
        public override void Read()
        {
            ReInitDevice();
            RBA_Stub emailRBA = null;

            if (device_identifier.Contains("INGENICO"))
            {
                emailRBA = new RBA_Stub("COM" + com_port);
                emailRBA.SetParent(this.parent);
                emailRBA.SetVerbose(this.verbose_mode);
            }
            TcpListener http = this.GetHTTP();

            byte[] buffer = new byte[10];
            while (SPH_Running)
            {
                string result     = "";
                string keyVal     = "key";
                bool   saveResult = false;
                try {
                    using (TcpClient client = http.AcceptTcpClient()) {
                        client.ReceiveTimeout = 100;
                        using (NetworkStream stream = client.GetStream()) {
                            string message    = "";
                            int    bytes_read = 0;
                            do
                            {
                                bytes_read = stream.Read(buffer, 0, buffer.Length);
                                message   += System.Text.Encoding.ASCII.GetString(buffer, 0, bytes_read);
                            } while (stream.DataAvailable);

                            if (rba != null)
                            {
                                rba.stubStop();
                            }

                            message = GetHttpBody(message);
                            message = message.Trim(new char[] { '"' });
                            try {
                                XmlDocument request = new XmlDocument();
                                request.LoadXml(message);
                                keyVal = request.SelectSingleNode("TStream/Transaction/InvoiceNo").InnerXml;
                            } catch (Exception) {
                                Console.WriteLine("Error parsing from\n" + message);
                            }
                            // Send EMV messages to EMVX, others
                            // to PDCX
                            if (message.Contains("EMV"))
                            {
                                result     = ProcessEMV(message, true);
                                saveResult = true;
                            }
                            else if (message.Contains("termSig"))
                            {
                                FlaggedReset();
                                result = GetSignature(true);
                            }
                            else if (device_identifier.Contains("INGENICO") && message.Contains("termEmail"))
                            {
                                result = emailRBA.getEmailSync();
                            }
                            else if (message.Length > 0)
                            {
                                result     = ProcessPDC(message);
                                saveResult = true;
                            }
                            result = WrapHttpResponse(result);

                            byte[] response = System.Text.Encoding.ASCII.GetBytes(result);
                            stream.Write(response, 0, response.Length);
                            stream.Close();
                            if (message.Contains("EMV"))
                            {
                                FlaggedReset();
                            }
                        }
                        client.Close();
                    }
                } catch (Exception ex) {
                    this.LogMessage(ex.ToString());
                    try {
                        if (saveResult && result.Length > 0)
                        {
                            parent.SqlLog(keyVal, result);
                        }
                    } catch (Exception) {
                        this.LogMessage(keyVal + ": " + result);
                    }
                }
            }
        }
Esempio n. 6
0
        /**
         * Driver listens over TCP for incoming HTTP data. Driver
         * is providing a web-service style endpoint so POS behavior
         * does not have to change. Rather than POSTing information to
         * a remote processor it POSTs information to the driver.
         *
         * Driver strips off headers, feeds XML into the dsiEMVX control,
         * then sends the response back to the client.
         */
        public override void Read()
        {
            var deviceThread = new Thread(new ThreadStart(this.DeviceLoop));

            deviceThread.Start();
            this.device_thread_id = deviceThread.ManagedThreadId;
            Console.WriteLine("Set device thread: " + this.device_thread_id);
            Server http = new Server();

            http.SetPort(LISTEN_PORT);
            while (SPH_Running)
            {
                string result     = "";
                string keyVal     = "key";
                bool   saveResult = false;
                try {
                    var pair = http.GetNext();

                    if (rba != null)
                    {
                        rba.stubStop();
                    }

                    string message = pair.body;
                    message = message.Trim(new char[] { '"' });
                    try {
                        XmlDocument request = new XmlDocument();
                        request.LoadXml(message);
                        keyVal = request.SelectSingleNode("TStream/Transaction/InvoiceNo").InnerXml;
                    } catch (Exception) {
                        Console.WriteLine("Error parsing from\n" + message);
                    }
                    // Send EMV messages to EMVX, others
                    // to PDCX
                    if (message.Contains("EMV"))
                    {
                        result     = ProcessEMV(message, true);
                        saveResult = true;
                    }
                    else if (message.Contains("termSig"))
                    {
                        FlaggedReset();
                        result = GetSignature(true);
                    }
                    else if (message.Length > 0)
                    {
                        result     = ProcessPDC(message);
                        saveResult = true;
                    }
                    http.Respond(pair.response, result);
                } catch (Exception ex) {
                    this.LogMessage(ex.ToString());
                    try {
                        if (saveResult && result.Length > 0)
                        {
                            parent.SqlLog(keyVal, result);
                        }
                    } catch (Exception) {
                        this.LogMessage(keyVal + ": " + result);
                    }
                }
            }
        }
Esempio n. 7
0
 public override void HandleMsg(string msg)
 {
     // optional predicate for "termSig" message
     // predicate string is displayed on sig capture screen
     if (msg.Length > 7 && msg.Substring(0, 7) == "termSig") {
     //sig_message = msg.Substring(7);
     msg = "termSig";
     }
     if (msg.Length > 10 && msg.Substring(0, 10) == "screenLine") {
     string line = msg.Substring(10);
     msg = "IGNORE";
     if (rba != null) {
         rba.addScreenMessage(line);
     }
     }
     switch(msg) {
     case "termReset":
     case "termReboot":
         if (rba != null) {
             rba.stubStop();
         }
         lock(emvLock) {
             emv_reset = true;
         }
         ReInitDevice();
         break;
     case "termManual":
         break;
     case "termApproved":
         FlaggedReset();
         if (rba != null) {
             rba.showMessage("Approved");
         }
         break;
     case "termDeclined":
         if (rba != null) {
             rba.showMessage("Declined");
         }
         break;
     case "termError":
         if (rba != null) {
             rba.showMessage("Error");
         }
         break;
     case "termSig":
         if (rba != null) {
             rba.stubStop();
         }
         FlaggedReset();
         GetSignature();
         break;
     case "termGetType":
         break;
     case "termGetTypeWithFS":
         break;
     case "termGetPin":
         break;
     case "termWait":
         break;
     case "termFindPort":
         var new_port = this.PortSearch(this.device_identifier);
         if (new_port != "" && new_port != this.com_port && new_port.All(char.IsNumber)) {
             this.com_port = new_port;
         }
         break;
     }
 }