コード例 #1
0
		public void GenerateForwardedRequest(SipMessageWriter writer, SipMessageReader reader, ArraySegment<byte> content, ConnectionAddresses fromConnectionAddress, int serverTransactionId)
		{
			//int? tag = HexEncoding.ParseHex8(reader.To.Tag);
			//var dialog2 = trunk.GetExternalDialog(tag);

			//if (dialog2 != null)
			//{
			//    this.tag = tag.Value;
			//    //this.dialog1 = dialog1;
			//    this.dialog2 = dialog2;
			//}

			Dialog dialog2 = null;
			if (HexEncoding.TryParseHex8(reader.To.Tag, out tag))
				dialog2 = trunk.GetDialog2(tag);
			else
				tag = DialogManager.NewLocalTag();

			dialog1 = new Dialog(reader, tag, fromConnectionAddress);
			trunk.AddDialog1(tag, dialog1);


			writer.WriteRequestLine(reader.Method, trunk.Transport.ToScheme(), reader.To.AddrSpec.User, trunk.Domain);

			//var msReceivedCid = fromConnectionAddress.ToLowerHexChars(serverTransactionId);
			//writer.WriteVia(trunk.ConnectionAddresses.Transport, trunk.ConnectionAddresses.LocalEndPoint, TransactionId, msReceivedCid);
			writer.WriteVia(trunk.ConnectionAddresses.Transport, trunk.ConnectionAddresses.LocalEndPoint, TransactionId);

			for (int i = 0; i < reader.Count.HeaderCount; i++)
			{
				switch (reader.Headers[i].HeaderName)
				{
					case HeaderNames.MaxForwards:
						writer.WriteMaxForwards((reader.MaxForwards == int.MinValue) ? 69 : reader.MaxForwards - 1);
						break;

					case HeaderNames.Contact:
						writer.WriteContact(trunk.LocalEndPoint, trunk.Transport, reader.Contact[0].SipInstance);
						break;

					case HeaderNames.Via:
						via = reader.Headers[i].Value.DeepCopy();
						break;

					case HeaderNames.To:
						writer.WriteTo2(reader.To.AddrSpec.User, trunk.Domain, (dialog2 != null) ? dialog2.RemoteTag : ByteArrayPart.Invalid);
						break;

					case HeaderNames.From:
						writer.WriteFrom(trunk.Uri, tag);
						break;

					case HeaderNames.CSeq:
						writer.WriteCseq(trunk.GetCSeq(reader.CSeq.Method, reader.CallId, reader.CSeq.Value), reader.CSeq.Method);
						break;

					case HeaderNames.Authorization:
					case HeaderNames.ContentLength:
					case HeaderNames.Extension:
						break;

					default:
						writer.WriteHeader(reader, i);
						break;
				}
			}

			WriteAuthorization(writer, reader.Method, content);

			if (reader.Method == Methods.Invitem && reader.ContentType.Subtype.Equals(sdp)) // temp
				content = Sip.Sdp.Helpers.CutCandidates(content);

			writer.WriteContentLength(content.Count);
			writer.WriteCRLF();

			writer.Write(content);
		}