public StartLine(byte [] buf) { Init(); if (buf == null || buf.Length < 2) { return; } //最後の\r\nがない場合は、エラーとする if (buf[buf.Length - 2] != '\r' || buf[buf.Length - 1] != '\n'){ return; } var str = Encoding.ASCII.GetString(Inet.TrimCrlf(buf)); //3カラムで無い場合はエラーと認識される var tmp = str.Split(' '); if (tmp.Count() != 3) { return; } //先頭がSIP/で始まっている場合、ステータスラインとして処理する if (tmp[0].IndexOf("SIP/") == 0) { SipVer = new SipVer(tmp[0]); int result; if (Int32.TryParse(tmp[1], out result)) { StatusCode = result; } ResponseStr = tmp[2]; //すべての初期化が成功したとき、リクエストラインとして認める if (StatusCode != 0 && ResponseStr != "" && SipVer.No != 0) { ReceptionKind = ReceptionKind.Status; } } else { foreach (SipMethod m in Enum.GetValues(typeof(SipMethod))) { if (m.ToString().ToUpper() == tmp[0].ToUpper()) { SipMethod = m; break; } } if (tmp[1].IndexOf("sip:") == 0) { RequestUri = tmp[1].Substring(4); } SipVer = new SipVer(tmp[2]); //すべての初期化が成功したとき、リクエストラインとして認める if (SipMethod != SipMethod.Unknown && RequestUri != "" && SipVer.No != 0) { ReceptionKind = ReceptionKind.Request; } } if (ReceptionKind == ReceptionKind.Unknown) { Init();//無効の場合は、誤動作の発見を早くするため、すべてを初期化する } }
void Init() { ReceptionKind = ReceptionKind.Unknown; SipMethod = SipMethod.Unknown; RequestUri = ""; SipVer = new SipVer(); StatusCode = 0; ResponseStr = ""; }
public StartLine(byte [] buf) { Init(); if (buf == null || buf.Length < 2) { return; } //最後の\r\nがない場合は、エラーとする if (buf[buf.Length - 2] != '\r' || buf[buf.Length - 1] != '\n') { return; } var str = Encoding.ASCII.GetString(Inet.TrimCrlf(buf)); //3カラムで無い場合はエラーと認識される var tmp = str.Split(' '); if (tmp.Count() != 3) { return; } //先頭がSIP/で始まっている場合、ステータスラインとして処理する if (tmp[0].IndexOf("SIP/") == 0) { SipVer = new SipVer(tmp[0]); int result; if (Int32.TryParse(tmp[1], out result)) { StatusCode = result; } ResponseStr = tmp[2]; //すべての初期化が成功したとき、リクエストラインとして認める if (StatusCode != 0 && ResponseStr != "" && SipVer.No != 0) { ReceptionKind = ReceptionKind.Status; } } else { foreach (SipMethod m in Enum.GetValues(typeof(SipMethod))) { if (m.ToString().ToUpper() == tmp[0].ToUpper()) { SipMethod = m; break; } } if (tmp[1].IndexOf("sip:") == 0) { RequestUri = tmp[1].Substring(4); } SipVer = new SipVer(tmp[2]); //すべての初期化が成功したとき、リクエストラインとして認める if (SipMethod != SipMethod.Unknown && RequestUri != "" && SipVer.No != 0) { ReceptionKind = ReceptionKind.Request; } } if (ReceptionKind == ReceptionKind.Unknown) { Init();//無効の場合は、誤動作の発見を早くするため、すべてを初期化する } }