Beispiel #1
0
            public static NSJSObject NewContextObject(NSJSVirtualMachine machine,
                                                      NSJSObject application,
                                                      HTTPContext context)
            {
                if (context == null)
                {
                    throw new ArgumentNullException("context");
                }
                if (application == null)
                {
                    throw new ArgumentNullException("application");
                }
                if (machine == null)
                {
                    throw new ArgumentNullException("machine");
                }
                NSJSObject objective = NSJSObject.New(machine); // ctx

                objective.Set("Application", application);
                objective.Set("Close", m_CloseProc);
                objective.Set("Dispose", m_CloseProc);
                objective.Set("Request", HttpRequest.New(machine, objective, context.Request));
                objective.Set("Response", HttpResponse.New(machine, objective, context.Response));
                objective.DefineProperty("Asynchronous", m_AsynchronousProc, m_AsynchronousProc);
                NSJSKeyValueCollection.Set(objective, context);
                return(objective);
            }
Beispiel #2
0
        public static NSJSValue ToArray(NSJSVirtualMachine machine, DataTable dataTable)
        {
            if (machine == null)
            {
                return(null);
            }
            DataRowCollection rows = null;
            int       count        = dataTable == null ? 0 : (rows = dataTable.Rows).Count;
            NSJSArray results      = NSJSArray.New(machine, count);

            if (count <= 0)
            {
                return(results);
            }
            IDictionary <string, int> columns = new Dictionary <string, int>();

            foreach (DataColumn column in dataTable.Columns)
            {
                columns.Add(column.ColumnName, column.Ordinal);
            }
            for (int i = 0; i < count; i++)
            {
                NSJSObject item = NSJSObject.New(machine);
                DataRow    row  = rows[i];
                results[i] = item;
                foreach (KeyValuePair <string, int> column in columns)
                {
                    object value = row[column.Value];
                    item.Set(column.Key, value.As(machine));
                }
            }
            return(results);
        }
Beispiel #3
0
        public static NSJSValue ToObject(NSJSVirtualMachine machine, NameValueCollection s)
        {
            if (machine == null)
            {
                return(null);
            }
            NSJSObject obj = NSJSObject.New(machine);

            if (s != null)
            {
                foreach (string key in s.AllKeys)
                {
                    if (string.IsNullOrEmpty(key))
                    {
                        continue;
                    }
                    string value = s.Get(key);
                    string name  = key.ToLower();
                    if (value != null)
                    {
                        obj.Set(name, value);
                    }
                    else
                    {
                        obj.Set(name, NSJSValue.Null(machine));
                    }
                }
            }
            return(obj);
        }
Beispiel #4
0
        public static NSJSValue ToObject(NSJSVirtualMachine machine, IDictionary <string, string> s)
        {
            if (machine == null)
            {
                return(null);
            }
            NSJSObject obj = NSJSObject.New(machine);

            if (s != null)
            {
                foreach (KeyValuePair <string, string> kv in s)
                {
                    if (string.IsNullOrEmpty(kv.Key))
                    {
                        continue;
                    }
                    if (kv.Value == null)
                    {
                        obj.Set(kv.Key, NSJSValue.Null(machine));
                    }
                    else
                    {
                        obj.Set(kv.Key, kv.Value);
                    }
                }
            }
            return(obj);
        }
Beispiel #5
0
        public static NSJSValue ToObject(NSJSVirtualMachine machine, Cookie cookie)
        {
            if (machine == null)
            {
                return(null);
            }
            if (cookie == null)
            {
                return(NSJSValue.Null(machine));
            }
            NSJSObject objective = NSJSObject.New(machine);

            objective.Set("Comment", cookie.Comment);
            objective.Set("CommentUri", cookie.CommentUri?.ToString());
            objective.Set("Discard", cookie.Discard);
            objective.Set("Domain", cookie.Domain);
            objective.Set("Expired", cookie.Expired);
            objective.Set("Expires", cookie.Expires < NSJSDateTime.Min ? NSJSDateTime.Min : cookie.Expires);
            objective.Set("HttpOnly", cookie.HttpOnly);
            objective.Set("Name", cookie.Name);
            objective.Set("Path", cookie.Path);
            objective.Set("Port", cookie.Port);
            objective.Set("Secure", cookie.Secure);
            objective.Set("TimeStamp", cookie.TimeStamp);
            objective.Set("Value", cookie.Value);
            objective.Set("Version", cookie.Version);
            return(objective);
        }
Beispiel #6
0
        public static NSJSObject New(NSJSVirtualMachine machine, NSJSObject context, HTTPResponse response)
        {
            if (machine == null || context == null || response == null)
            {
                return(null);
            }
            NSJSObject objective = NSJSObject.New(machine);

            objective.Set("CurrentContext", context);
            objective.DefineProperty("ContentEncoding", g_ContentEncodingProc, g_ContentEncodingProc);
            objective.DefineProperty("ContentType", g_ContentTypeProc, g_ContentTypeProc);
            objective.DefineProperty("StatusDescription", g_StatusDescriptionProc, g_StatusDescriptionProc);
            objective.DefineProperty("StatusCode", g_StatusCodeProc, g_StatusCodeProc);
            objective.DefineProperty("KeepAlive", g_KeepAliveProc, g_KeepAliveProc);
            objective.DefineProperty("ProtocolVersion", g_ProtocolVersionProc, g_ProtocolVersionProc);
            objective.DefineProperty("RedirectLocation", g_RedirectLocationProc, g_RedirectLocationProc);
            objective.DefineProperty("SendChunked", g_SendChunkedProc, g_SendChunkedProc);
            objective.DefineProperty("Headers", g_HeadersProc, g_HeadersProc);
            objective.DefineProperty("Cookies", g_CookiesProc, g_CookiesProc);

            objective.Set("Redirect", g_RedirectProc);
            objective.Set("End", g_EndProc);
            objective.Set("Abort", g_AbortProc);

            objective.Set("SetCookie", g_SetCookieProc);
            objective.Set("AppendCookie", g_SetCookieProc);
            objective.Set("AddHeader", g_AddHeaderProc);
            objective.Set("AppendHeader", g_AddHeaderProc);

            objective.Set("Write", g_WriteProc);
            objective.Set("WriteFile", g_WriteFileProc);
            objective.Set("BinaryWrite", g_BinaryWriteProc);
            NSJSKeyValueCollection.Set(objective, response);
            return(objective);
        }
Beispiel #7
0
        public static NSJSObject New(NSJSVirtualMachine machine, HTTPApplication application)
        {
            if (machine == null || application == null)
            {
                return(null);
            }
            NSJSObject objective = NSJSObject.New(machine);

            objective.DefineProperty("Name", g_NameProc, g_NameProc);
            objective.DefineProperty("Root", g_RootProc, g_RootProc);
            objective.Set("Start", g_StartProc);
            objective.Set("Stop", g_StopProc);
            objective.Set("Close", g_CloseProc);
            objective.Set("Dispose", g_CloseProc);

            application.Tag          = objective;
            objective.CrossThreading = true;

            application.Handler              = new HttpHandler(objective, application);
            application.EndProcessRequest   += g_EndProcessRequestProc;
            application.BeginProcessRequest += g_BeginProcessRequestProc;

            NSJSKeyValueCollection.Set(objective, application);
            return(objective);
        }
Beispiel #8
0
        private static NSJSObject New(NSJSVirtualMachine machine, WebSocketListener server)
        {
            if (machine == null || server == null)
            {
                return(null);
            }
            NSJSObject objective = NSJSObject.New(machine);

            objective.Set("Port", server.Port);
            objective.Set("GetBindPort", g_GetBindPortProc);
            objective.Set("Stop", g_StopProc);
            objective.Set("Start", g_StartProc);
            objective.Set("Close", g_CloseProc);
            objective.Set("Dispose", g_CloseProc);

            server.UserToken         = objective;
            objective.CrossThreading = true;

            server.OnMessage += (websocket, e) => ProcessEvent(objective, websocket, "OnMessage", e);
            server.OnOpen    += (websocket, e) => ProcessEvent(objective, websocket, "OnOpen", e, true);
            server.OnError   += (websocket, e) => ProcessEvent(objective, websocket, "OnError", e);
            server.OnClose   += (websocket, e) => ProcessEvent(objective, websocket, "OnClose", e);

            NSJSKeyValueCollection.Set(objective, server);
            return(objective);
        }
Beispiel #9
0
 public static NSJSObject New(NSJSVirtualMachine machine, ENCODING encoding)
 {
     lock (g_Locker)
     {
         if (machine == null || encoding == null)
         {
             return(null);
         }
         IDictionary <IntPtr, NSJSObject> dVirtualTables;
         if (!g_EncodingInstanceTable.TryGetValue(encoding.CodePage, out dVirtualTables))
         {
             dVirtualTables = new Dictionary <IntPtr, NSJSObject>();
             g_EncodingInstanceTable.Add(encoding.CodePage, dVirtualTables);
         }
         NSJSObject o;
         if (dVirtualTables.TryGetValue(machine.Isolate, out o))
         {
             return(o);
         }
         if (!g_UninitializedEncoding)
         {
             g_UninitializedEncoding = true;
             g_GetBytesProc          = NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(GetBytes);
             g_GetStringProc         = NSJSPinnedCollection.Pinned <NSJSFunctionCallback>(GetString);
         }
         o = NSJSObject.New(machine);
         o.CrossThreading = true;
         o.Set("GetBytes", g_GetBytesProc);
         o.Set("GetString", g_GetStringProc);
         dVirtualTables.Add(machine.Isolate, o);
         NSJSKeyValueCollection.Set(o, encoding);
         return(o);
     }
 }
Beispiel #10
0
        public static NSJSObject GetMessageEventData(NSJSVirtualMachine machine, EventArgs e)
        {
            if (machine == null || e == null)
            {
                return(null);
            }
            MessageEventArgs message = e as MessageEventArgs;

            if (message == null)
            {
                return(null);
            }
            NSJSObject data = NSJSObject.New(machine);

            data.Set("IsText", message.IsText);
            if (message.IsText)
            {
                data.Set("RawData", message.Message);
            }
            else // BLOB
            {
                data.Set("RawData", message.RawData);
            }
            return(data);
        }
Beispiel #11
0
        public static NSJSValue ToObject(NSJSVirtualMachine machine, HttpFileCollection files)
        {
            if (machine == null)
            {
                return(null);
            }
            if (files == null)
            {
                return(NSJSValue.Null(machine));
            }
            NSJSObject owner = NSJSObject.New(machine);

            foreach (string key in files.AllKeys)
            {
                if (string.IsNullOrEmpty(key))
                {
                    continue;
                }
                HttpPostedFile fileinfo = files[key];
                if (fileinfo == null)
                {
                    continue;
                }
                owner.Set(key, ToObject(machine, fileinfo));
            }
            return(owner);
        }
Beispiel #12
0
        private static void GetConfigurationView(IntPtr info)
        {
            NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info);
            string path = GetFullPath(arguments.Length > 0 ? (arguments[0] as NSJSString)?.Value : null);

            if (File.Exists(path))
            {
                NSJSObject configuration = NSJSObject.New(arguments.VirtualMachine);
                foreach (string section in GetAllSection(path))
                {
                    if (string.IsNullOrEmpty(section))
                    {
                        continue;
                    }
                    NSJSObject sectionObject = NSJSObject.New(arguments.VirtualMachine);
                    foreach (KeyValuePair <string, string> kv in GetAllKeyValue(path, section))
                    {
                        if (string.IsNullOrEmpty(kv.Key))
                        {
                            continue;
                        }
                        sectionObject.Set(kv.Key, kv.Value);
                    }
                    configuration.Set(section, sectionObject);
                }
                arguments.SetReturnValue(configuration);
            }
        }
Beispiel #13
0
        public static NSJSValue ToObject(NSJSVirtualMachine machine, IPHostEntry host)
        {
            if (machine == null)
            {
                return(null);
            }
            if (host == null)
            {
                return(NSJSValue.Null(machine));
            }
            NSJSObject entry = NSJSObject.New(machine);

            entry.Set("HostName", host.HostName);
            entry.Set("AddressList", ArrayAuxiliary.ToArray(machine, host.AddressList));

            string[]  aliases = host.Aliases;
            NSJSArray array   = NSJSArray.New(machine, aliases.Length);

            for (int i = 0; i < aliases.Length; i++)
            {
                array[i] = NSJSString.New(machine, aliases[i]);
            }
            entry.Set("Aliases", array);

            return(entry);
        }
Beispiel #14
0
        public static NSJSObject New(NSJSVirtualMachine machine, BaseStream stream)
        {
            if (machine == null || stream == null)
            {
                return(null);
            }
            NSJSObject o = NSJSObject.New(machine);

            o.Set("CanWrite", stream.CanWrite);
            o.Set("CanSeek", stream.CanSeek);
            o.Set("CanRead", stream.CanRead);

            o.DefineProperty("Length", m_LengthProc, (NSJSFunctionCallback)null);
            o.DefineProperty("Position", m_PositionProc, m_PositionProc);
            o.Set("Seek", m_SeekProc);
            o.Set("CopyTo", m_CopyToProc);

            o.Set("Read", m_ReadProc);
            o.Set("Write", m_WriteProc);
            o.Set("Flush", m_FlushProc);
            o.Set("ReadBytes", m_ReadBytesProc);

            o.Set("Close", m_DisposeProc);
            o.Set("Dispose", m_DisposeProc);

            NSJSKeyValueCollection.Set(o, stream);
            return(o);
        }
Beispiel #15
0
        private static void Invalid(IntPtr info)
        {
            NSJSFunctionCallbackInfo arguments = NSJSFunctionCallbackInfo.From(info);
            SocketContext            context   = GetSocketContext(arguments.Length > 0 ? arguments[0] as NSJSObject : null);
            NSJSObject o = NSJSObject.New(arguments.VirtualMachine);

            arguments.SetReturnValue(!(context != null && context.Socket != null && context.This != null));
        }
Beispiel #16
0
        private static NSJSObject New(NSJSVirtualMachine machine, RC4CSP provider)
        {
            NSJSObject o = NSJSObject.New(machine);

            o.Set("Encrypt", m_EncryptProc);
            o.Set("Decrypt", m_DecryptProc);
            o.Set("Dispose", m_DisposeProc);
            NSJSKeyValueCollection.Set(o, provider);
            return(o);
        }
Beispiel #17
0
        private NSJSObject New(NSJSVirtualMachine machine, RijndaelCryptoServiceProvider provider)
        {
            NSJSObject o = NSJSObject.New(machine);

            o.Set("Encrypt", this.m_EncryptProc);
            o.Set("Decrypt", this.m_DecryptProc);
            o.Set("Dispose", this.m_DisposeProc);
            NSJSKeyValueCollection.Set(o, provider);
            return(o);
        }
Beispiel #18
0
            public static NSJSObject New(NSJSVirtualMachine machine, IDbTransaction transaction)
            {
                if (machine == null || transaction == null)
                {
                    return(null);
                }
                NSJSObject o = NSJSObject.New(machine);

                o.Set("Commit", g_CommitProc);
                o.Set("Rollback", g_RollbackProc);
                o.Set("Close", g_CloseProc);
                o.Set("Dispose", g_CloseProc);
                NSJSKeyValueCollection.Set(o, transaction);
                return(o);
            }
Beispiel #19
0
        public static NSJSObject New(NSJSVirtualMachine machine, MailClient smtp)
        {
            if (machine == null || smtp == null)
            {
                return(null);
            }
            NSJSObject o = NSJSObject.New(machine);

            o.Set("Send", g_SendProc);
            o.Set("SendAsync", m_SendAsyncProc);
            o.Set("Close", g_CloseProc);
            o.Set("Dispose", g_CloseProc);
            NSJSKeyValueCollection.Set(o, smtp);
            return(o);
        }
Beispiel #20
0
 private static void OnBeginProcessRequest(object sender, HttpBeginProcessRequestEventArgs e)
 {
     DoProcessRequest(sender, (application, origin, machine) =>
     {
         NSJSFunction callback = origin.Get("BeginProcessRequest") as NSJSFunction;
         if (callback != null)
         {
             NSJSObject args = NSJSObject.New(machine);
             args.Set("Cancel", e.Cancel);
             args.Set("Application", origin);
             args.Set("CurrentContext", HttpHandler.NewContextObject(machine, origin, e.CurrentContext));
             callback.Call(args);
             e.Cancel = args.Get("Cancel").As <bool>();
         }
     });
 }
Beispiel #21
0
        public static NSJSObject New(NSJSVirtualMachine machine, DATATableGateway gateway)
        {
            if (machine == null || gateway == null)
            {
                return(null);
            }
            NSJSObject o = NSJSObject.New(machine);

            o.Set("Select", g_SelectProc);
            o.Set("Close", g_CloseProc);
            o.Set("Dispose", g_CloseProc);
            o.Set("ExecuteNonQuery", g_ExecuteNonQueryProc);
            o.Set("DeriveParameters", g_DeriveParametersProc);
            o.Set("BeginTransaction", g_BeginTransactionProc);
            NSJSKeyValueCollection.Set(o, gateway);
            return(o);
        }
Beispiel #22
0
        public static NSJSValue ToObject(NSJSVirtualMachine machine, IDbDataParameter parameter)
        {
            if (machine == null)
            {
                return(null);
            }
            if (parameter == null)
            {
                return(NSJSValue.Null(machine));
            }
            NSJSObject o = NSJSObject.New(machine);

            o.Set("Name", parameter.ParameterName);
            o.Set("IsNullable", parameter.IsNullable);
            o.Set("DbType", unchecked ((int)parameter.DbType));
            return(o);
        }
Beispiel #23
0
        public static NSJSValue ToObject(NSJSVirtualMachine machine, EncodingInfo encoding)
        {
            if (machine == null)
            {
                return(null);
            }
            if (encoding == null)
            {
                return(NSJSValue.Null(machine));
            }
            NSJSObject obj = NSJSObject.New(machine);

            obj.Set("Name", encoding.Name);
            obj.Set("DisplayName", encoding.DisplayName);
            obj.Set("CodePage", encoding.CodePage);
            return(obj);
        }
Beispiel #24
0
        public static NSJSValue New(NSJSVirtualMachine machine, MSSQLDatabaseAccessAdapter adapter)
        {
            if (machine == null)
            {
                return(null);
            }
            if (adapter == null)
            {
                return(NSJSValue.Null(machine));
            }
            NSJSObject self = NSJSObject.New(machine);

            self.UserToken = adapter;
            self.Set("Close", g_CloseProc);
            self.Set("Dispose", g_CloseProc);
            return(self);
        }
Beispiel #25
0
        public static NSJSValue ToObject(NSJSVirtualMachine machine, HttpPostedFile file)
        {
            if (machine == null)
            {
                return(null);
            }
            if (file == null)
            {
                return(NSJSValue.Null(machine));
            }
            NSJSObject objective = NSJSObject.New(machine);

            objective.Set("ContentLength", file.ContentLength);
            objective.Set("ContentType", file.ContentType);
            objective.Set("FileName", file.FileName);
            objective.Set("InputStream", NSJSValue.NullMerge(machine, NSJSStream.New(machine, file.InputStream)));
            return(objective);
        }
Beispiel #26
0
        public static NSJSObject New(NSJSVirtualMachine machine, WebSocket websocket)
        {
            if (machine == null || websocket == null)
            {
                return(null);
            }
            object usertoken = websocket.UserToken;

            if (usertoken != null)
            {
                return(usertoken as NSJSObject);
            }
            NSJSObject objective = NSJSObject.New(machine);

            objective.Set("Open", m_OpenProc);
            objective.Set("Close", m_CloseProc);
            objective.Set("Dispose", m_CloseProc);
            objective.Set("Send", m_SendProc);
            objective.Set("Path", websocket.Path);

            objective.Set("Ttl", websocket.Ttl);
            objective.Set("Handle", websocket.Handle.ToInt32());
            objective.Set("LocalEndPoint", ObjectAuxiliary.ToObject(machine, websocket.LocalEndPoint));
            objective.Set("RemoteEndPoint", ObjectAuxiliary.ToObject(machine, websocket.RemoteEndPoint));

            objective.Set("OnMessage", NSJSValue.Null(machine));
            objective.Set("OnClose", NSJSValue.Null(machine));
            objective.Set("OnError", NSJSValue.Null(machine));
            objective.Set("OnOpen", NSJSValue.Null(machine));

            websocket.OnMessage += m_OnMessageProc;
            websocket.OnOpen    += m_OnOpenProc;
            websocket.OnError   += m_OnErrorProc;
            websocket.OnClose   += m_OnCloseProc;

            websocket.UserToken      = objective;
            objective.CrossThreading = true;

            objective.DefineProperty("NoDelay", m_NoDelayProc, m_NoDelayProc);
            objective.DefineProperty("Available", m_AvailableProc, (NSJSFunctionCallback)null);

            NSJSKeyValueCollection.Set(objective, websocket);
            return(objective);
        }
Beispiel #27
0
        public static NSJSValue ToObject(NSJSVirtualMachine machine, IPAddress address)
        {
            if (machine == null)
            {
                return(null);
            }
            if (address == null)
            {
                return(NSJSValue.Null(machine));
            }
            NSJSObject o = NSJSObject.New(machine);

            if (address.AddressFamily == AddressFamily.InterNetworkV6)
            {
                o.Set("ScopeId", address.ScopeId);
            }
            o.Set("AddressFamily", (int)address.AddressFamily);
            o.Set("Address", address.ToString());
            o.Set("AddressBytes", address.GetAddressBytes());
            return(o);
        }
Beispiel #28
0
        public static NSJSValue ToObject(NSJSVirtualMachine machine, EndPoint endpoint)
        {
            if (machine == null)
            {
                return(null);
            }
            if (endpoint == null)
            {
                return(NSJSValue.Null(machine));
            }
            NSJSObject obj = NSJSObject.New(machine);

            obj.Set("AddressFamily", (int)endpoint.AddressFamily);
            IPEndPoint ipep = endpoint as IPEndPoint;

            if (ipep != null)
            {
                obj.Set("Address", ToObject(machine, ipep.Address));
                obj.Set("Port", ipep.Port);
            }
            return(obj);
        }
Beispiel #29
0
        private static NSJSObject New(NSJSVirtualMachine machine, SOCKET socket)
        {
            if (machine == null || socket == null)
            {
                return(null);
            }
            NSJSObject o = NSJSObject.New(machine);

            o.Set("MSS", SocketExtension.MSS);
            o.Set("PPP", SocketExtension.PPP);
            o.Set("MTU", SocketExtension.MTU);
            o.Set("LocalEndPoint", ObjectAuxiliary.ToObject(machine, socket.LocalEndPoint));
            o.Set("RemoteEndPoint", ObjectAuxiliary.ToObject(machine, socket.RemoteEndPoint));
            o.Set("Send", m_SendProc);
            o.Set("Bind", m_BindProc);
            o.Set("Handle", socket.Handle.ToInt32());
            o.Set("Close", m_CloseProc);
            o.Set("Dispose", m_CloseProc);
            o.Set("Connect", m_ConnectProc);
            o.Set("Receive", m_ReceiveProc);
            o.Set("Accept", m_AcceptProc);
            o.Set("Connected", m_ConnectedProc);
            o.Set("ConnectAsync", m_ConnectAsyncProc);
            o.Set("AcceptAsync", m_AcceptAsyncProc);
            o.Set("SendAsync", m_SendAsyncProc);
            o.Set("ReceiveAsync", m_ReceiveAsyncProc);
            o.Set("SendTo", m_SendToProc);
            o.Set("SendToAsync", m_SendToAsyncProc);
            o.Set("ReceiveFrom", m_ReceiveFromProc);
            o.Set("ReceiveFromAsync", m_ReceiveFromAsyncProc);
            o.CrossThreading = true;
            NSJSKeyValueCollection.Set(o, new SocketContext
            {
                This   = o,
                Socket = socket,
            });
            return(o);
        }
Beispiel #30
0
        public static NSJSValue ToObject(NSJSVirtualMachine machine, KeyValuePair <string, string> kv)
        {
            if (machine == null)
            {
                return(null);
            }
            if (string.IsNullOrEmpty(kv.Key))
            {
                return(null);
            }
            NSJSObject obj = NSJSObject.New(machine);

            obj.Set("Key", kv.Key);
            if (kv.Value == null)
            {
                obj.Set("Value", NSJSValue.Null(machine));
            }
            else
            {
                obj.Set("Value", kv.Value);
            }
            return(obj);
        }