private SipRegistration(String contact_prefs, List<Destination> destination_list, UsageManager manager) { if (contact_prefs == null || destination_list == null || destination_list.Count == 0) throw new ArgumentException("SipRegistration does not allow null parameter or destination list < 1"); type = SipRegistrationType.sip_registration_route; codePoint = Usage_Code_Point.SIP_REGISTRATION; length = (UInt16)(contact_prefs.Length + 2); length += (UInt16)(ReloadMessage.GetDestListNetLength(destination_list) + 2); // + 2 destList preceeding "length" value data = new SipRegistrationData(contact_prefs, destination_list); myManager = manager; }
/// <summary> /// This method reads deserializes a SipRegistration datagramm from incomming bytes. /// </summary> /// <param name="rm">The ReloadMessage helper class</param> /// <param name="reader">The incomming byte stream reader</param> /// <param name="usage_size">Size of the Usage datagramm.</param> /// <returns></returns> public IUsage FromReader(ReloadMessage rm, BinaryReader reader, long usage_size) { try { type = (SipRegistrationType)reader.ReadByte(); this.length = (UInt16)(IPAddress.HostToNetworkOrder( (short)reader.ReadInt16())); switch (type) { case SipRegistrationType.sip_registration_uri: UInt16 len = (UInt16)(IPAddress.HostToNetworkOrder((short)reader.ReadInt16())); data = new SipRegistrationData(Encoding.UTF8.GetString(reader.ReadBytes(len), 0, len)); break; case SipRegistrationType.sip_registration_route: len = (UInt16)(IPAddress.HostToNetworkOrder((short)reader.ReadInt16())); string contact_prefs = Encoding.UTF8.GetString(reader.ReadBytes(len), 0, len); len = (UInt16)(IPAddress.HostToNetworkOrder((short)reader.ReadInt16())); data = new SipRegistrationData(contact_prefs, rm.ReadDestList(reader, len)); break; default: throw new SystemException(String.Format("Invalid SipRegistrationType {0}!", type)); } usage_size = usage_size - (length); } catch (Exception ex) { throw ex; } return this; }
/// <summary> /// If the registration is of type "sip_registration_uri", then the /// contents are an opaque string containing the URI. /// </summary> /// <param name="sip_uri">The SIP URI to be stored</param> private SipRegistration(String sip_uri, UsageManager manager) { if (sip_uri == null || sip_uri.Length == 0) throw new ArgumentNullException("SIP URI can not be null or size = 0"); codePoint = Usage_Code_Point.SIP_REGISTRATION; type = SipRegistrationType.sip_registration_uri; data = new SipRegistrationData(sip_uri); length = (UInt16)(sip_uri.Length + 2); // +2 for preceding length value (short) myManager = manager; }