Esempio n. 1
0
        private void run()
        {
            cont = true;
            while (cont)
            {
                //loop messages
                BitMsg[] MSGs = JsonConverter.getMessages(BA.getAllInboxMessages());

                foreach (BitMsg M in MSGs)
                {
                    if (M.toAddress == Addr)
                    {
                        GenericMessageReceived(new GenericMessage()
                        {
                            Server = this, Tag = M.msgid, Sender = M.fromAddress, Receiver = M.toAddress, RawContent = M.message, Command = M.subject
                        });
                    }
                    else
                    {
                        GenericServerLog(this, GenericLogType.Debug, false, "Ignoring message to " + M.toAddress);
                    }
                }
                for (int i = 0; i < 20 && cont; i++)
                {
                    Thread.Sleep(500);
                }
            }
        }
Esempio n. 2
0
 private static void msgListen()
 {
     while (s != null)
     {
         BitMsg[] Messages = JsonConverter.getMessages(BA.getAllInboxMessages());
         foreach (BitMsg m in Messages)
         {
             if (Req.ContainsKey(m.subject) && m.message.StartsWith("HTTP"))
             {
                 string[] Parts = m.message.Split(new string[] { "\r\n\r\n" }, 2, StringSplitOptions.None);
                 if (Parts.Length == 2)
                 {
                     //Decode content, if present
                     byte[] content = null;
                     if (Parts[1].Length > 0)
                     {
                         Ascii85 A5 = new Ascii85();
                         content = A5.Decode(Parts[1]);
                     }
                     BA.trashMessage(m.msgid);
                     Req[m.subject].Send(Parts[0], content);
                     //Remove connection and request
                     cc.Remove(Req[m.subject]);
                     Req.Remove(m.subject);
                 }
             }
         }
         Thread.Sleep(2000);
     }
 }
Esempio n. 3
0
 private static void msgListen()
 {
     cont = true;
     while (cont)
     {
         BitMsg[] Messages = JsonConverter.getMessages(BA.getAllInboxMessages());
         foreach (BitMsg m in Messages)
         {
             if (m.message.StartsWith("GET ") || m.message.StartsWith("POST "))
             {
                 string[] Parts = m.message.Split(new string[] { "\r\n\r\n" }, 2, StringSplitOptions.None);
                 //Decode content, if present
                 byte[] content = null;
                 if (Parts.Length == 2 && Parts[1].Length > 0)
                 {
                     Ascii85 A5 = new Ascii85();
                     content = A5.Decode(Parts[1]);
                 }
                 Thread t = new Thread(new ParameterizedThreadStart(sr));
                 t.IsBackground = true;
                 t.Start(new object[] { m.fromAddress, m.toAddress, m.subject, Parts[0], content });
                 BA.trashMessage(m.msgid);
             }
         }
         Thread.Sleep(2000);
     }
 }
Esempio n. 4
0
        /// <summary>
        /// List of all Bitmessage Messages in Inbox
        /// </summary>
        /// <param name="BA">BitAPI object</param>
        /// <returns>Array of Bitmessage Messages</returns>
        public static BitMsg[] getMessages(BitAPI BA)
        {
            BitMsgs MSG;

            try
            {
                MSG = JsonConvert.DeserializeObject <BitMsgs>(BA.getAllInboxMessages());
            }
            catch
            {
                return(null);
            }

            if (MSG.inboxMessages != null)
            {
                for (int i = 0; i < MSG.inboxMessages.Length; i++)
                {
                    //Decode Base64
                    MSG.inboxMessages[i].message = B64dec(MSG.inboxMessages[i].message.Trim()).Trim();
                    MSG.inboxMessages[i].subject = B64dec(MSG.inboxMessages[i].subject.Trim()).Trim();
                    //Convert line endings
                    MSG.inboxMessages[i].message = MSG.inboxMessages[i].message
                                                   .Replace("\r\n", "\n")
                                                   .Replace("\r", "")
                                                   .Replace("\n", "\r\n");
                }
            }
            else
            {
                //Empty array
                MSG.inboxMessages = new BitMsg[0];
            }
            return(MSG.inboxMessages);
        }
        /// <summary>
        /// List of all Bitmessage Messages in Inbox
        /// </summary>
        /// <param name="BA">BitAPI object</param>
        /// <returns>Array of Bitmessage Messages</returns>
        public static BitMsg[] getMessages(BitAPI BA)
        {
            BitMsgs MSG;
            try
            {
                MSG = JsonConvert.DeserializeObject<BitMsgs>(BA.getAllInboxMessages());
            }
            catch
            {
                return null;
            }

            if (MSG.inboxMessages != null)
            {
                for (int i = 0; i < MSG.inboxMessages.Length; i++)
                {
                    //Decode Base64
                    MSG.inboxMessages[i].message = B64dec(MSG.inboxMessages[i].message.Trim()).Trim();
                    MSG.inboxMessages[i].subject = B64dec(MSG.inboxMessages[i].subject.Trim()).Trim();
                    //Convert line endings
                    MSG.inboxMessages[i].message = MSG.inboxMessages[i].message
                        .Replace("\r\n", "\n")
                        .Replace("\r", "")
                        .Replace("\n", "\r\n");
                }
            }
            else
            {
                //Empty array
                MSG.inboxMessages = new BitMsg[0];
            }
            return MSG.inboxMessages;
        }