Exemple #1
0
        private SIPMessage makeSIPConstructor(string data)
        {
            SIPM = new SIPMessage();
            StreamWriter sw = new StreamWriter("PacketDump_" + DateTime.Now.ToShortDateString() + ".txt", true, Encoding.Default);
            try
            {
                string code = "Unknown";
                string method = "Unknown";
                string callid = "Unknown";
                string cseq = "Unknown";
                string from = "Unknown";
                string to = "Unknown";
                string agent = "Unknown";
                string sName = "Unknown";


                StringReader sr = new StringReader(data);
                
                while (sr.Peek() != -1)
                {
                    string line = sr.ReadLine();
                    string Gubun = "";

                    if (line.Length > 2)
                    {
                        Gubun = line.Substring(0, 3);
                    }
                    if (Gubun.Equals("REG"))
                    {
                        break;
                    }
                    else
                    {
                        if (Gubun.Equals(ConstDef.NIC_SIP))  //Status Line
                        {
                            string[] sipArr = line.Split(' ');
                            if (sipArr.Length > 0)
                            {
                                code = sipArr[1].Trim();
                                method = sipArr[2].Trim();
                                sw.WriteLine("code : "+code + " / method : " + method);
                            }
                        }
                        else if (Gubun.Equals("INV"))
                        {
                            method = "INVITE";
                        }
                        else if (Gubun.Equals("CAN"))
                        {
                            method = "CANCEL";
                        }
                        else
                        {
                            string[] sipArr = line.Split(':');
                            if (sipArr.Length < 2)
                            {
                                sipArr = line.Split('=');
                                if (sipArr.Length > 1)
                                {
                                    sw.WriteLine(sipArr[0] + " = " + sipArr[1]);
                                    if (sipArr[0].Equals("s")) sName = sipArr[1];
                                }
                            }
                            else
                            {
                                string key = sipArr[0];

                                switch (key)
                                {
                                    case "From":
                                        from = sipArr[2].Split('@')[0];
                                        sw.WriteLine("From = " + from);
                                        break;

                                    case "To":
                                        to = sipArr[2].Split('@')[0];
                                        sw.WriteLine("To = " + to);
                                        break;

                                    case "Call-ID":
                                        callid = sipArr[1].Split('@')[0];
                                        sw.WriteLine("Call-ID = " + callid);
                                        break;

                                    case "CSeq":
                                        cseq = sipArr[1].Split('@')[0];
                                        sw.WriteLine("CSeq = " + cseq);
                                        break;

                                    case "User-Agent":
                                        agent = sipArr[1].Split('@')[0];
                                        sw.WriteLine("User-Agent = " + cseq);
                                        break;

                                    default:

                                        string value = "";
                                        for (int i = 1; i < sipArr.Length; i++)
                                        {
                                            value += sipArr[i];
                                        }
                                        sw.WriteLine(key + " = " + value);

                                        break;
                                }
                            }
                        }
                    }
                }
                sw.WriteLine("\r\n");
                sw.WriteLine("###########");
                sw.Flush();
                sw.Close();
                if (!from.Equals(to) && !from.Equals("unknown") && !to.Equals("unknown"))
                {
                    LogWrite(data);
                }
                SIPM.setSIPMessage(code, method, callid, cseq, from, to, agent, sName);

            }
            catch (Exception ex)
            {
                LogWrite(ex.ToString());
                sw.Close();
            }

            return SIPM;
        }