/** * Send an auth error to peer because he sent a bad cookie. The auth error * uses his cookie (not revealing ours). This is just like send_reg * otherwise */ protected void CookieError(OtpLocalNode local, OtpErlangAtom cookie) { try { OtpOutputStream header = new OtpOutputStream(headerLen); // preamble: 4 byte length + "passthrough" tag + version header.Write4BE(0); // reserve space for length header.Write1(passThrough); header.Write1(version); header.WriteTupleHead(4); header.WriteLong(regSendTag); header.WriteAny(local.CreatePid()); // disposable pid header.WriteAtom(cookie.Value); // important: his cookie, // not mine... header.WriteAtom("auth"); // version for payload header.Write1(version); // the payload // the no_auth message (copied from Erlang) Don't change this // (Erlang will crash) // {$gen_cast, {print, "~n** Unauthorized cookie ~w **~n", // [foo@aule]}} IOtpErlangObject[] msg = new IOtpErlangObject[2]; IOtpErlangObject[] msgbody = new IOtpErlangObject[3]; msgbody[0] = new OtpErlangAtom("print"); msgbody[1] = new OtpErlangString("~n** Bad cookie sent to " + local + " **~n"); // Erlang will crash and burn if there is no third argument here... msgbody[2] = new OtpErlangList(); // empty list msg[0] = new OtpErlangAtom("$gen_cast"); msg[1] = new OtpErlangTuple(msgbody); OtpOutputStream payload = new OtpOutputStream(new OtpErlangTuple(msg)); // fix up length in preamble header.Poke4BE(0, header.Length + payload.Length - 4); try { DoSend(header, payload); } catch (IOException) { } // ignore } finally { Close(); } throw new OtpAuthException("Remote cookie not authorized: " + cookie.Value); }
/** * Create an Erlang string from a list of integers. * * @return an Erlang string with Unicode code units. * * @throws OtpErlangException * for non-proper and non-integer lists. * @throws OtpErlangRangeException * if an integer in the list is not * a valid Unicode code point according to Erlang. */ public OtpErlangString(OtpErlangList list) { String s = list.stringValue(); int[] offset = System.Globalization.StringInfo.ParseCombiningCharacters(s); int n = offset.Length; for (int i = 0; i < n; i++) { int cp = (int)codePointAt(s, offset[i]); if (!isValidCodePoint(cp)) { throw new OtpErlangRangeException("Invalid CodePoint: " + cp); } } str = s; }
/** * Send an RPC request to the remote Erlang node. This convenience function * creates the following message and sends it to 'rex' on the remote node: * * <pre> * { self, { call, Mod, Fun, Args, user } } * </pre> * * <p> * Note that this method has unpredicatble results if the remote node is not * an Erlang node. * </p> * * @param mod * the name of the Erlang module containing the function to * be called. * @param fun * the name of the function to call. * @param args * a list of Erlang terms, to be used as arguments to the * function. * * @exception java.io.IOException * if the connection is not active or a communication * error occurs. */ public void sendRPC(String mod, String fun, OtpErlangList args) { OtpErlangObject[] rpc = new OtpErlangObject[2]; OtpErlangObject[] call = new OtpErlangObject[5]; /* {self, { call, Mod, Fun, Args, user}} */ call[0] = new OtpErlangAtom("call"); call[1] = new OtpErlangAtom(mod); call[2] = new OtpErlangAtom(fun); call[3] = args; call[4] = new OtpErlangAtom("user"); rpc[0] = self.Pid; rpc[1] = new OtpErlangTuple(call); send("rex", new OtpErlangTuple(rpc)); }
/** * Determine if two lists are equal. Lists are equal if they have the same * arity and all of the elements are equal. * * @param o * the list to compare to. * * @return true if the lists have the same arity and all the elements are * equal. */ public override bool Equals(Object o) { /* * Be careful to use methods even for "this", so that equals work also * for sublists */ if (!(o is OtpErlangList)) { return(false); } OtpErlangList l = (OtpErlangList)o; int a = arity(); if (a != l.arity()) { return(false); } for (int i = 0; i < a; i++) { if (!elementAt(i).Equals(l.elementAt(i))) { return(false); // early exit } } OtpErlangObject otherTail = l.getLastTail(); if (getLastTail() == null && otherTail == null) { return(true); } if (getLastTail() == null) { return(false); } return(getLastTail().Equals(l.getLastTail())); }
/// <summary>Extracts the nodes.</summary> /// <param name="nodes">The nodes.</param> /// <param name="nodesList">The nodes list.</param> private void ExtractNodes(IList<Node> nodes, OtpErlangList nodesList) { foreach (var erlangNodeName in nodesList) { var nodeName = erlangNodeName.ToString(); nodes.Add(new Node(nodeName)); } }
/// <summary>Extracts the applications.</summary> /// <param name="applications">The applications.</param> /// <param name="appList">The app list.</param> private void ExtractApplications(IList<Application> applications, OtpErlangList appList) { foreach (var appDescription in appList) { var appDescriptionTuple = (OtpErlangTuple)appDescription; var name = appDescriptionTuple.elementAt(0).ToString(); var description = appDescriptionTuple.elementAt(1).ToString(); var version = appDescriptionTuple.elementAt(2).ToString(); applications.Add(new Application(name, description, version)); } }
/** * Create an Erlang string from a list of integers. * * @return an Erlang string with Unicode code units. * * @throws OtpErlangException * for non-proper and non-integer lists. * @throws OtpErlangRangeException * if an integer in the list is not * a valid Unicode code point according to Erlang. */ public OtpErlangString(OtpErlangList list) { str = list.stringValue(); }
public SubList(OtpErlangList parent, int start) : base() { this.parent = parent; this.start = start; }
/* * Send an auth error to peer because he sent a bad cookie. The auth error * uses his cookie (not revealing ours). This is just like send_reg * otherwise */ private void cookieError(OtpLocalNode local, OtpErlangAtom cookie) { try { OtpOutputStream header = new OtpOutputStream(headerLen); // preamble: 4 byte length + "passthrough" tag + version header.write4BE(0); // reserve space for length header.write1(passThrough); header.write1(version); header.write_tuple_head(4); header.write_long(regSendTag); header.write_any(local.createPid()); // disposable pid header.write_atom(cookie.atomValue()); // important: his cookie, // not mine... header.write_atom("auth"); // version for payload header.write1(version); // the payload // the no_auth message (copied from Erlang) Don't change this // (Erlang will crash) // {$gen_cast, {print, "~n** Unauthorized cookie ~w **~n", // [foo@aule]}} OtpErlangObject[] msg = new OtpErlangObject[2]; OtpErlangObject[] msgbody = new OtpErlangObject[3]; msgbody[0] = new OtpErlangAtom("print"); msgbody[1] = new OtpErlangString("~n** Bad cookie sent to " + local + " **~n"); // Erlang will crash and burn if there is no third argument here... msgbody[2] = new OtpErlangList(); // empty list msg[0] = new OtpErlangAtom("$gen_cast"); msg[1] = new OtpErlangTuple(msgbody); OtpOutputStream payload = new OtpOutputStream(new OtpErlangTuple(msg)); // fix up length in preamble header.poke4BE(0, header.size() + payload.size() - 4); try { do_send(header, payload); } catch (IOException) { } // ignore } finally { close(); } throw new OtpAuthException("Remote cookie not authorized: " + cookie.atomValue()); }
/// <summary>Sends the RPC.</summary> /// <param name="mod">The mod.</param> /// <param name="fun">The fun.</param> /// <param name="args">The args.</param> public void SendRPC(string mod, string fun, OtpErlangList args) { this.otpConnection.sendRPC(mod, fun, args); }