/// <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; }
public AccessList(UsageManager manager) { myManager = manager; codePoint = Usage_Code_Point.ACCESS_LIST; length = 0; SetHashCode(); }
/// <summary> /// Deserializes AccessControlList Kind from byte stream. /// </summary> /// <param name="rm">Not used.</param> /// <param name="reader">Binary reader containing message byte stream.</param> /// <param name="usage_size">Not used. ACL has fix length.</param> /// <returns></returns> public IUsage FromReader(ReloadMessage rm, BinaryReader reader, long usage_size) { codePoint = Usage_Code_Point.ACCESS_LIST; UInt16 len = 0; // for opaque string lengths try { /* read resource_name*/ len = (UInt16)(System.Net.IPAddress.HostToNetworkOrder((short)reader.ReadInt16())); resource_name = Encoding.UTF8.GetString(reader.ReadBytes(len), 0, len); /* read length of PDU */ length = (UInt16)(System.Net.IPAddress.HostToNetworkOrder((short)reader.ReadInt16())); /* read to_user value */ len = (UInt16)(System.Net.IPAddress.HostToNetworkOrder((short)reader.ReadInt16())); string to_uri = Encoding.UTF8.GetString(reader.ReadBytes(len), 0, len); /* read kindId to be shared */ UInt32 kindId = (UInt32)System.Net.IPAddress.NetworkToHostOrder((int)reader.ReadInt32()); /* read allow_delegation flag */ Boolean allow_delegation = (reader.ReadByte() == 0 ? false : true); /* Create ACL data */ data = new AccessListData(kindId, to_uri, allow_delegation); usage_size = usage_size - (length + 1); } catch (Exception ex) { myManager.m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_ERROR, String.Format("AccessList FromReader(): {0}", ex.Message)); } SetHashCode(); return this; }
/// <summary> /// Deserializes a DisCoRegistration from byte stream. /// </summary> /// <param name="rm">Not used.</param> /// <param name="reader"> /// The binary reader containing the entire RELOAD message</param> /// <param name="usage_size">Not used. DisCoReg has fixed length</param> /// <returns></returns> public IUsage FromReader(ReloadMessage rm, BinaryReader reader, long usage_size) { codePoint = Usage_Code_Point.DISCO; UInt16 len = 0; // used for length of opaque values try { /* lenght of resource name and resource name */ len = (UInt16)(Conv.NetworkToHostOrder((short)reader.ReadInt16())); resourceName = Encoding.ASCII.GetString(reader.ReadBytes(len), 0, len); /* length of rest PDU */ length = (UInt16)(Conv.NetworkToHostOrder((short)reader.ReadInt16())); /* length of coordiate and coordinate */ len = (UInt16)(Conv.NetworkToHostOrder((short)reader.ReadInt16())); string coord = Encoding.UTF8.GetString(reader.ReadBytes(len), 0, len); /* node_id of remote peer */ NodeId nodeId = new NodeId(reader.ReadBytes(ReloadGlobals.NODE_ID_DIGITS)); /* Instanciate DisCo data */ data = new DisCoRegistrationData(coord, nodeId); usage_size = usage_size - (length + 1); } catch (Exception ex) { myManager.m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_ERROR, String.Format("DisCoRegistration FromBytes(): {0}", ex.Message)); } return this; }
/// <summary> /// This contructor instanciates an Access List Kind. /// </summary> /// <param name="resource_name">The Name of the Resource to be shared.</param> /// <param name="kindId">The Kind Id of the Resource to be shared.</param> /// <param name="to_user"></param> /// <param name="to_user"></param> /// <param name="allow_delegation"></param> private AccessList(string resource_name, string to_user, UInt32 kindId, Boolean allow_delegation, UsageManager manager) { if (resource_name == null || kindId == 0 || to_user == null) throw new ArgumentNullException("An Access List does not allow null parameter."); codePoint = Usage_Code_Point.ACCESS_LIST; this.resource_name = resource_name; length = (UInt16)(resource_name.Length + 2); length += (UInt16)2; // KindId length += (UInt16)(to_user.Length + 2); length += (UInt16)1; // Boolean allow_delegation length += 2; // the length itself data = new AccessListData(kindId, to_user, allow_delegation); myManager = manager; SetHashCode(); }
public Request(Machine machine, Usage_Code_Point codePoint = 0, int type=0, string[] args = null) { this.machine = machine; this.CodePoint = codePoint; this.type = type; this.args = args; }
/// <summary> /// This contructor should be taken if you want to create a DisCoRegistration from wire. /// </summary> public DisCoRegistration(UsageManager manager) { myManager = manager; codePoint = Usage_Code_Point.DISCO; length = 0; }
public IUsage FromReader(ReloadMessage rm, BinaryReader reader, long usage_size) //REDIR_SERVICE_PROVIDER { codePoint = Usage_Code_Point.REDIR_SERVICE_PROVIDER; UInt16 namespacelength; string nameSpace; UInt16 level; UInt16 node; NodeId serviceProviderID; try { uint length = (UInt32)(System.Net.IPAddress.NetworkToHostOrder((int)reader.ReadInt32())); UInt16 serviceProviderID_len = (UInt16)(System.Net.IPAddress.NetworkToHostOrder(reader.ReadInt16())); serviceProviderID = new NodeId(reader.ReadBytes(serviceProviderID_len)); namespacelength = (UInt16)(System.Net.IPAddress.NetworkToHostOrder(reader.ReadInt16())); nameSpace = Encoding.ASCII.GetString(reader.ReadBytes(namespacelength)); //ASCII for wireshark dissector level = (UInt16)(System.Net.IPAddress.NetworkToHostOrder(reader.ReadInt16())); node = (UInt16)(System.Net.IPAddress.NetworkToHostOrder(reader.ReadInt16())); string resourceName = (nameSpace + "," + level + "," + node); RedirServiceProvider serviceProvider = new RedirServiceProvider(serviceProviderID, resourceName, nameSpace, level, node, myManager); return serviceProvider; } catch (Exception ex) { throw ex; } }
/// <summary> /// This contructor should be taken if you want to create a RedirServiceProvider from wire. /// </summary> public CertificateStore(bool bnode) { codePoint = bnode ? Usage_Code_Point.CERTIFICATE_STORE_BY_NODE : Usage_Code_Point.CERTIFICATE_STORE_BY_USER; byNode = bnode; }
/// <summary> /// This contructor should be taken if you want to create a RedirServiceProvider from wire. /// </summary> public RedirServiceProvider(UsageManager manager) { myManager = manager; codePoint = Usage_Code_Point.REDIR_SERVICE_PROVIDER; }
/// <summary> /// This constructor instantiates a RedirServiceProvider /// </summary> /// <param name="serviceProvider">The NodeId of the ServiceProvider.</param> /// <param name="resourceName">resourceName is "nameSpace,level,node"</param> /// <param name="level">level in Redir Tree</param> /// <param name="node">node in Redir Tree</param> public RedirServiceProvider(NodeId serviceProvider, string resourceName, string nameSpace, UInt16 level, UInt16 node, UsageManager manager) { if (serviceProvider == null || nameSpace == null) throw new ArgumentNullException("RedirServiceProvider does not accept null parameters"); codePoint = Usage_Code_Point.REDIR_SERVICE_PROVIDER; data = new RedirServiceProviderData(serviceProvider, nameSpace, level, node); myManager = manager; this.resourceName = resourceName; }
public void GatherCommandsInQueue(string command, Usage_Code_Point codePoint, int type, NodeId viaGateway, bool CommandFinished = false, params object[] arguments) //TODO: combine to one single method { IUsage usage = null; StoredDataSpecifier specifier = null; if (command.Equals("Store")) { StoreKindData kindData; usage = m_UsageManager.CreateUsage(codePoint, type, arguments); //foreach (UInt32 kindId in usage.Kinds) TODO: { //kindData = new StoreKindData(kindId, 0, new StoredData(usage.Encapsulate(kindId, true))); kindData = new StoreKindData(usage.KindId, 0, new StoredData(usage.Encapsulate(true))); gatheredStoreDatas.Add(kindData); //m_ReloadConfig.GatheringList.Add(kindData); } if (CommandFinished == true) { if (viaGateway != null) storeViaGateway.Add(gatheredStoreDatas, viaGateway); gatheredStoreDatasQueue.Post(gatheredStoreDatas); gatheredStoreDatas = new List<StoreKindData>(); } } if (command.Equals("Fetch")) { //UInt32[] kinds = UsageManager.CreateUsage(codePoint, null, null).Kinds; TODO: cleanup UInt32 kind = UsageManager.CreateUsage(codePoint, null, null).KindId; // To further garantee SIP Usage with Telefonenumbers if (codePoint == Usage_Code_Point.SIP_REGISTRATION && arguments[0].ToString().StartsWith("+")) { string FetchUrl = ""; ReloadConfigResolve res = new ReloadConfigResolve(m_ReloadConfig); FetchUrl = res.ResolveNaptr(arguments[0].ToString()); if (FetchUrl == null) { ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_WARNING, "DNS Enum fallback to sip uri analysis"); FetchUrl = arguments[0].ToString(); FetchUrl = FetchUrl.TrimStart(' '); FetchUrl = FetchUrl.Replace(" ", ""); FetchUrl = "sip:" + FetchUrl + "@" + m_ReloadConfig.OverlayName; arguments[0] = FetchUrl; } } //foreach (UInt32 kindId in kinds) TODO: cleanup { specifier = m_UsageManager.createSpecifier(kind, arguments); gatheredSpecifiers.Add(specifier); } if (CommandFinished == true) { if (viaGateway != null) fetchViaGateway.Add(gatheredSpecifiers, viaGateway); gatheredSpecifiersQueue.Post(gatheredSpecifiers); gatheredSpecifiers = new List<StoredDataSpecifier>(); } } }
/// <summary> /// This method gathers all Kinds that will be sent withon one single request. /// @precondition: The storing data MUST have the same Resource Name. /// @precondition: The the command MUST be the same. (e.g., ONLY store | fetch) /// </summary> /// <param name="command">Store | Fetch</param> /// <param name="codePoint">The Identifier for the Usage to be performed</param> /// <param name="type">Some Usages define differents types (see sip usage). Place here that value in Usage spec.</param> /// <param name="arguments">argument[0] Resource Name /// /// If SIP Registration: args[1] = uri | contact prefs /// If DisCo Registration: args[1] TODO /// If Access List: args[1] = kinId /// args[2] = from_user /// args[3] = to_user /// args[4] = allow_delegation</param> public void GatherCommands(string command, Usage_Code_Point codePoint, int type, params object[] arguments) { IUsage usage = null; StoredDataSpecifier specifier = null; /* Check plausibility of user commands */ if (m_ReloadConfig.CommandQueuePort.ItemCount > 0 && command != (string)m_ReloadConfig.CommandQueuePort.Test()) { throw new ArgumentException(String.Format( "Your command {0} is not the same as previews command {1}.", command, (string)m_ReloadConfig.CommandQueuePort.Test())); } /* Process store command */ if (command.Equals("Store")) { StoreKindData kindData; usage = m_UsageManager.CreateUsage(codePoint, type, arguments); kindData = new StoreKindData(usage.KindId, 0, // mok! TODO generation management new StoredData(usage.Encapsulate(true))); gatheredStoreDatas.Add(kindData); } /* Process fetch command */ if (command.Equals("Fetch")) { string[] str_arguments = arguments.Select(item => (string)item).ToArray(); UInt32 kind = UsageManager.CreateUsage(codePoint, null, null).KindId; // To further garantee SIP Usage with Telefonenumbers if (codePoint == Usage_Code_Point.SIP_REGISTRATION && str_arguments[0].StartsWith("+")) { string FetchUrl = ""; ReloadConfigResolve res = new ReloadConfigResolve(m_ReloadConfig); FetchUrl = res.ResolveNaptr(str_arguments[0]); if (FetchUrl == null) { ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_WARNING, "DNS Enum fallback to sip uri analysis"); FetchUrl = str_arguments[0]; FetchUrl = FetchUrl.TrimStart(' '); FetchUrl = FetchUrl.Replace(" ", ""); FetchUrl = "sip:" + FetchUrl + "@" + m_ReloadConfig.OverlayName; } arguments[0] = FetchUrl; } specifier = m_UsageManager.createSpecifier(kind, str_arguments); gatheredSpecifiers.Add(specifier); } }
public StoreRequest(Machine machine, Usage_Code_Point codePoint = 0, int type=0, string[] args = null) : base(machine, codePoint, type, args) { }
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 creates Usages. Use this if your intending to Store or Delete Kinds in the Overlay. /// If type and arguments are null, it returns an empty usage obejct of the specified Usage /// </summary> /// <param name="kindId"></param> /// <param name="type"></param> /// <param name="arguments">argument[0] Resource Name /// /// If SIP Registration: args[0] = uri | contact prefs /// If DisCo Registration: args[1] TODO /// If Access List: args[1] = kindId /// args[2] = from_user /// args[3] = to_user /// args[4] = allow_delegation</param> /// <returns></returns> public IUsage CreateUsage(Usage_Code_Point usageCode, int? type, params object[] arguments) { if (type == null && arguments == null) { return usages[usageCode]; } return usages[usageCode].Create(type, arguments); }
/// <summary> /// Use this constructor just to have a SipRegistration object. /// </summary> public SipRegistration(UsageManager manager) { myManager = manager; codePoint = Usage_Code_Point.SIP_REGISTRATION; //length = 0; }
public void storeVia(string NameSpace, Usage_Code_Point codePoint, int type, string[] args) { StoreRequest req = new StoreRequest(machine, codePoint, type, args); if (gateWayCache.ContainsKey(NameSpace) == true) { req.fire(NameSpace, gateWayCache[NameSpace]); } else { RequestQueue[NameSpace].Enqueue(req); ReDiRNode.lookupService(NameSpace); } }