static private int EventHandler(IntPtr conn_ptr, int ev)
    {
        MongooseConnection conn = (MongooseConnection)
                                  System.Runtime.InteropServices.Marshal.PtrToStructure(
            conn_ptr, typeof(MongooseConnection));

        if (ev == 102)
        {
            // MG_AUTH
            return(1);
        }
        else if (ev == 103)
        {
            // MG_REQUEST
            Mongoose.send_data(conn_ptr, "Hello from C#!\n");
            Mongoose.send_data(conn_ptr, "URI: " + conn.uri + "\n");
            Mongoose.send_data(conn_ptr, "HTTP Headers:\n");

            for (int i = 0; i < conn.num_headers; i++)
            {
                IntPtr name = conn.http_headers[i].name;
                IntPtr val  = conn.http_headers[i].value;
                System.Runtime.InteropServices.Marshal.PtrToStringAnsi(name);
                Mongoose.send_data(conn_ptr, "  " +
                                   System.Runtime.InteropServices.Marshal.PtrToStringAnsi(name) + ": " +
                                   System.Runtime.InteropServices.Marshal.PtrToStringAnsi(val) + "\n");
            }
            return(1);
        }
        return(0);
    }
示例#2
0
 private static int RequestHandler(MongooseConnection conn)
 {
     return 0;
     /*
     conn.write("HTTP/1.1 200 OK\r\n\r\n");
     conn.write("Hello from C#!\n");
     conn.write("Your user-agent is: " + conn.get_header("User-Agent") + "\n");
     */
 }
示例#3
0
    public void set_uri_callback(string uri_regex, MongooseCallback func)
    {
        // Build a closure around user function. Initialize connection object there which wraps
        // mg_write() and other useful methods, and then call user specified handler.
        MongooseCallback2 callback = delegate(IntPtr conn, ref MongooseRequestInfo ri, IntPtr user_data) {
            MongooseConnection connection = new MongooseConnection(conn, this);
            func(connection, ri);
        };

        mg_set_uri_callback(this.ctx, uri_regex, callback, IntPtr.Zero);
    }
示例#4
0
 static private void UriDumpInfo(MongooseConnection conn, MongooseRequestInfo ri)
 {
     conn.write("HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n");
     conn.write("<html><body><head>Calling Info</head>");
     conn.write("<p>Request: " + ri.request_method + "</p>");
     conn.write("<p>URI: " + ri.uri + "</p>");
     conn.write("<p>Query: " + ri.query_string + "</p>");
     if (ri.post_data_len > 0) conn.write("<p>Post(" + ri.post_data_len + ")[@" + ri.post_data + "]: '" + Marshal.PtrToStringAnsi(ri.post_data) + "'</p>");
     conn.write("<p>User:"******"</p>");
     conn.write("<p>IP: " + ri.remote_ip + "</p>");
     conn.write("<p>HTTP: " + ri.http_version + "</p>");
     conn.write("<p>Port: " + ri.remote_port + "</p>");
     conn.write("<p>NUM Headers: " + ri.num_headers + "</p>");
     for (int i = 0; i < Math.Min(64, ri.num_headers); i++)
     {
         conn.write("<p>" + i + ":" + Marshal.PtrToStringAnsi(ri.http_headers[i].name)
             + ":" + Marshal.PtrToStringAnsi(ri.http_headers[i].value) + "</p>");
     }
     conn.write("</body></html>");
 }
示例#5
0
 static private void UriDumpInfo(MongooseConnection conn, MongooseRequestInfo ri)
 {
     conn.write("HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n");
     conn.write("<html><body><head>Calling Info</head>");
     conn.write("<p>Request: " + ri.request_method + "</p>");
     conn.write("<p>URI: " + ri.uri + "</p>");
     conn.write("<p>Query: " + ri.query_string + "</p>");
     if (ri.post_data_len > 0)
     {
         conn.write("<p>Post(" + ri.post_data_len + ")[@" + ri.post_data + "]: '" + Marshal.PtrToStringAnsi(ri.post_data) + "'</p>");
     }
     conn.write("<p>User:"******"</p>");
     conn.write("<p>IP: " + ri.remote_ip + "</p>");
     conn.write("<p>HTTP: " + ri.http_version + "</p>");
     conn.write("<p>Port: " + ri.remote_port + "</p>");
     conn.write("<p>NUM Headers: " + ri.num_headers + "</p>");
     for (int i = 0; i < Math.Min(64, ri.num_headers); i++)
     {
         conn.write("<p>" + i + ":" + Marshal.PtrToStringAnsi(ri.http_headers[i].name)
                    + ":" + Marshal.PtrToStringAnsi(ri.http_headers[i].value) + "</p>");
     }
     conn.write("</body></html>");
 }
示例#6
0
 // This function is called when user types in his browser http://127.0.0.1:8080/foo
 static private void UriHandler(MongooseConnection conn, MongooseRequestInfo ri)
 {
     conn.write("HTTP/1.1 200 OK\r\n\r\n");
     conn.write("Hello from C#!\n");
     conn.write("Your user-agent is: " + conn.get_header("User-Agent") + "\n");
 }
示例#7
0
	// This function is called when user types in his browser http://127.0.0.1:8080/foo
	static private void UriHandler(MongooseConnection conn, MongooseRequestInfo ri) {
		conn.write("HTTP/1.1 200 OK\r\n\r\n");
		conn.write("Hello from C#!\n");
		conn.write("Your user-agent is: " + conn.get_header("User-Agent") + "\n");
	}
示例#8
0
 public void set_uri_callback(string uri_regex, MongooseCallback func)
 {
     // Build a closure around user function. Initialize connection object there which wraps
     // mg_write() and other useful methods, and then call user specified handler.
     MongooseCallback2 callback = delegate(IntPtr conn, ref MongooseRequestInfo ri, IntPtr user_data) {
         MongooseConnection connection = new MongooseConnection(conn, this);
         func(connection, ri);
     };
     mg_set_uri_callback(this.ctx, uri_regex, callback, IntPtr.Zero);
 }