/// <summary> /// Get a list of my registeres rules /// </summary> /// <returns></returns> public List <GrcBoxRule> getRules() { string uri = baseUri + APPS + "/" + appId + RULES; GrcBoxRuleList list = makeGetRequest <GrcBoxRuleList>(uri); return(list.list); }
/// <summary> /// Register a new rule /// </summary> /// <param name="rule">The rule to be registered, the field ID is ignored by the server</param> /// <returns>The actual rule registered in the server, with the new ID</returns> public GrcBoxRule registerNewRule(GrcBoxRule.Protocol protocol, GrcBoxRule.RuleType t, GrcBoxInterface iface, long expireDate, int dstPort, string dstAddr = null, int srcPort = -1, string mcastPlugin = null, int dstFwdPort = -1, string srcAddr = null) { string ifName = iface.name; string type = t.ToString(); string dstFwdAddr; if (GrcBoxRule.RuleType.INCOMING.Equals(t)) { dstAddr = iface.address; dstFwdAddr = getMyIpAddr(); if (dstFwdPort == -1) { dstFwdPort = dstPort; } } else { srcAddr = getMyIpAddr(); dstFwdAddr = null; } GrcBoxRule rule = new GrcBoxRule(0, protocol.ToString(), type, appId, ifName, expireDate, srcPort, dstPort, srcAddr, dstAddr, mcastPlugin, dstFwdPort, dstFwdAddr); string uri = baseUri + APPS + "/" + appId + RULES; MemoryStream stream = new MemoryStream(); DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(GrcBoxRule)); jsonSerializer.WriteObject(stream, rule); stream.Position = 0; StreamReader r = new StreamReader(stream); string content = r.ReadToEnd(); GrcBoxRuleList list = makePostRequest <GrcBoxRuleList>(uri, content, appId.ToString(), mPass); return(list.list[list.list.Count - 1]); }