couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cml...@apache.org
Subject svn commit: r659244 - in /incubator/couchdb/trunk: bin/ src/mochiweb/
Date Thu, 22 May 2008 20:30:58 GMT
Author: cmlenz
Date: Thu May 22 13:30:57 2008
New Revision: 659244

URL: http://svn.apache.org/viewvc?rev=659244&view=rev
Log:
Updated MochiWeb in trunk to r73.

Added:
    incubator/couchdb/trunk/src/mochiweb/mochifmt.erl
      - copied unchanged from r659239, incubator/couchdb/vendor/mochiweb/r73/src/mochifmt.erl
    incubator/couchdb/trunk/src/mochiweb/mochifmt_records.erl
      - copied unchanged from r659239, incubator/couchdb/vendor/mochiweb/r73/src/mochifmt_records.erl
    incubator/couchdb/trunk/src/mochiweb/mochifmt_std.erl
      - copied unchanged from r659239, incubator/couchdb/vendor/mochiweb/r73/src/mochifmt_std.erl
Modified:
    incubator/couchdb/trunk/bin/couchdb.tpl.in
    incubator/couchdb/trunk/src/mochiweb/Makefile.am
    incubator/couchdb/trunk/src/mochiweb/mochiweb.erl
    incubator/couchdb/trunk/src/mochiweb/mochiweb_html.erl
    incubator/couchdb/trunk/src/mochiweb/mochiweb_multipart.erl
    incubator/couchdb/trunk/src/mochiweb/mochiweb_request.erl
    incubator/couchdb/trunk/src/mochiweb/mochiweb_socket_server.erl

Modified: incubator/couchdb/trunk/bin/couchdb.tpl.in
URL: http://svn.apache.org/viewvc/incubator/couchdb/trunk/bin/couchdb.tpl.in?rev=659244&r1=659243&r2=659244&view=diff
==============================================================================
--- incubator/couchdb/trunk/bin/couchdb.tpl.in (original)
+++ incubator/couchdb/trunk/bin/couchdb.tpl.in Thu May 22 13:30:57 2008
@@ -223,7 +223,7 @@
     command="`%ICU_CONFIG% --invoke` \
         %ERL% $interactive_option -sasl errlog_type error \
         -pa %erlanglibdir%/couch-%version%/ebin \
-            %erlanglibdir%/mochiweb-r64/ebin \
+            %erlanglibdir%/mochiweb-r73/ebin \
         -eval \"application:load(inets)\" \
         -eval \"application:load(crypto)\" \
         -eval \"application:load(couch)\" \

Modified: incubator/couchdb/trunk/src/mochiweb/Makefile.am
URL: http://svn.apache.org/viewvc/incubator/couchdb/trunk/src/mochiweb/Makefile.am?rev=659244&r1=659243&r2=659244&view=diff
==============================================================================
--- incubator/couchdb/trunk/src/mochiweb/Makefile.am (original)
+++ incubator/couchdb/trunk/src/mochiweb/Makefile.am Thu May 22 13:30:57 2008
@@ -12,9 +12,12 @@
 
 datarootdir = @prefix@/share
 
-mochiwebebindir = $(erlanglibdir)/mochiweb-r64/ebin
+mochiwebebindir = $(erlanglibdir)/mochiweb-r73/ebin
 
 mochiweb_file_collection = \
+    mochifmt.erl \
+    mochifmt_records.erl \
+    mochifmt_std.erl \
     mochihex.erl \
     mochijson.erl \
     mochijson2.erl \
@@ -39,6 +42,9 @@
 mochiwebebin_static_file = mochiweb.app
 
 mochiwebebin_make_generated_file_list = \
+    mochifmt.beam \
+    mochifmt_records.beam \
+    mochifmt_std.beam \
     mochihex.beam \
     mochijson.beam \
     mochijson2.beam \

Modified: incubator/couchdb/trunk/src/mochiweb/mochiweb.erl
URL: http://svn.apache.org/viewvc/incubator/couchdb/trunk/src/mochiweb/mochiweb.erl?rev=659244&r1=659243&r2=659244&view=diff
==============================================================================
--- incubator/couchdb/trunk/src/mochiweb/mochiweb.erl (original)
+++ incubator/couchdb/trunk/src/mochiweb/mochiweb.erl Thu May 22 13:30:57 2008
@@ -35,6 +35,7 @@
     mochijson:test(),
     mochiweb_charref:test(),
     mochiweb_html:test(),
+    mochifmt:test(),
     test_request(),
     ok.
 

Modified: incubator/couchdb/trunk/src/mochiweb/mochiweb_html.erl
URL: http://svn.apache.org/viewvc/incubator/couchdb/trunk/src/mochiweb/mochiweb_html.erl?rev=659244&r1=659243&r2=659244&view=diff
==============================================================================
--- incubator/couchdb/trunk/src/mochiweb/mochiweb_html.erl (original)
+++ incubator/couchdb/trunk/src/mochiweb/mochiweb_html.erl Thu May 22 13:30:57 2008
@@ -35,7 +35,7 @@
 -define(IS_LITERAL_SAFE(C),
         ((C >= $A andalso C =< $Z) orelse (C >= $a andalso C =< $z)
          orelse (C >= $0 andalso C =< $9))).
-                                
+
 -record(decoder, {line=1,
                   column=1,
                   offset=0}).
@@ -202,7 +202,7 @@
     attrs_to_html(Rest,
                   [[<<" ">>, escape(K), <<"=\"">>,
                     escape_attr(V), <<"\"">>] | Acc]).
-    
+
 test_escape() ->
     <<"&amp;quot;\"word &lt;&lt;up!&amp;quot;">> =
         escape(<<"&quot;\"word <<up!&quot;">>),
@@ -299,6 +299,14 @@
         tokens(<<"<foo bar=baz wibble='wibble' alice=bob/>">>),
     [{comment, <<"[if lt IE 7]>\n<style type=\"text/css\">\n.no_ie { display:
none; }\n</style>\n<![endif]">>}] =
         tokens(<<"<!--[if lt IE 7]>\n<style type=\"text/css\">\n.no_ie
{ display: none; }\n</style>\n<![endif]-->">>),
+    [{start_tag, <<"script">>, [{<<"type">>, <<"text/javascript">>}],
false},
+     {data, <<" A= B <= C ">>, false},
+     {end_tag, <<"script">>}] =
+        tokens(<<"<script type=\"text/javascript\"> A= B <= C </script>">>),
+    [{start_tag, <<"textarea">>, [], false},
+     {data, <<"<html></body>">>, false},
+     {end_tag, <<"textarea">>}] =
+        tokens(<<"<textarea><html></body></textarea>">>),
     ok.
 
 tokens(B, S=#decoder{offset=O}, Acc) ->
@@ -307,8 +315,29 @@
             lists:reverse(Acc);
         _ ->
             {Tag, S1} = tokenize(B, S),
-            tokens(B, S1, [Tag | Acc])
-    end.
+            case parse_flag(Tag) of
+                script ->
+                    {Tag2, S2} = tokenize_script(B, S1),
+                    tokens(B, S2, [Tag2, Tag | Acc]);
+                textarea ->
+                    {Tag2, S2} = tokenize_textarea(B, S1),
+                    tokens(B, S2, [Tag2, Tag | Acc]);
+                none ->
+                    tokens(B, S1, [Tag | Acc])
+            end
+    end.
+
+parse_flag({start_tag, B, _, false}) ->
+    case string:to_lower(binary_to_list(B)) of
+        "script" ->
+            script;
+        "textarea" ->
+            textarea;
+        _ ->
+            none
+    end;
+parse_flag(_) ->
+    none.
 
 tokenize(B, S=#decoder{offset=O}) ->
     case B of
@@ -330,7 +359,7 @@
             {S2, _} = find_gt(B, S1),
             {{end_tag, Tag}, S2};
         <<_:O/binary, "<", C, _/binary>> when ?IS_WHITESPACE(C) ->
-            %% This isn't really strict HTML but we want this for markdown
+            %% This isn't really strict HTML
             tokenize_data(B, ?INC_COL(S));
         <<_:O/binary, "<", _/binary>> ->
             {Tag, S1} = tokenize_literal(B, ?INC_COL(S)),
@@ -524,7 +553,7 @@
 
 destack(TagName, Stack) when is_list(Stack) ->
     F = fun (X) ->
-                case X of 
+                case X of
                     {TagName, _, _} ->
                         false;
                     _ ->
@@ -542,7 +571,7 @@
             %% Unfurl up to the tag, then accumulate it
             [{T0, A0, [destack(Pre ++ [T]) | Acc0]} | Post]
     end.
-    
+
 destack([{Tag, Attrs, Acc}]) ->
     {Tag, Attrs, lists:reverse(Acc)};
 destack([{T1, A1, Acc1}, {T0, A0, Acc0} | Rest]) ->
@@ -655,7 +684,7 @@
 
 tokenize_charref(Bin, S=#decoder{offset=O}) ->
     tokenize_charref(Bin, S, O).
-    
+
 tokenize_charref(Bin, S=#decoder{offset=O}, Start) ->
     case Bin of
         <<_:O/binary>> ->
@@ -758,3 +787,49 @@
         <<_:Start/binary, Raw/binary>> ->
             {{comment, Raw}, S}
     end.
+
+tokenize_script(Bin, S=#decoder{offset=O}) ->
+    tokenize_script(Bin, S, O).
+
+tokenize_script(Bin, S=#decoder{offset=O}, Start) ->
+    case Bin of
+        %% Just a look-ahead, we want the end_tag separately
+        <<_:O/binary, $<, $/, SS, CC, RR, II, PP, TT, _/binary>>
+        when (SS =:= $s orelse SS =:= $S) andalso
+             (CC =:= $c orelse CC =:= $C) andalso
+             (RR =:= $r orelse RR =:= $R) andalso
+             (II =:= $i orelse II =:= $I) andalso
+             (PP =:= $p orelse PP =:= $P) andalso
+             (TT=:= $t orelse TT =:= $T) ->
+            Len = O - Start,
+            <<_:Start/binary, Raw:Len/binary, _/binary>> = Bin,
+            {{data, Raw, false}, S};
+        <<_:O/binary, C, _/binary>> ->
+            tokenize_script(Bin, ?INC_CHAR(S, C), Start);
+        <<_:Start/binary, Raw/binary>> ->
+            {{data, Raw, false}, S}
+    end.
+
+tokenize_textarea(Bin, S=#decoder{offset=O}) ->
+    tokenize_textarea(Bin, S, O).
+
+tokenize_textarea(Bin, S=#decoder{offset=O}, Start) ->
+    case Bin of
+        %% Just a look-ahead, we want the end_tag separately
+        <<_:O/binary, $<, $/, TT, EE, XX, TT2, AA, RR, EE2, AA2, _/binary>>
+        when (TT =:= $t orelse TT =:= $T) andalso
+             (EE =:= $e orelse EE =:= $E) andalso
+             (XX =:= $x orelse XX =:= $X) andalso
+             (TT2 =:= $t orelse TT2 =:= $T) andalso
+             (AA =:= $a orelse AA =:= $A) andalso
+             (RR =:= $r orelse RR =:= $R) andalso
+             (EE2 =:= $e orelse EE2 =:= $E) andalso
+             (AA2 =:= $a orelse AA2 =:= $A) ->
+            Len = O - Start,
+            <<_:Start/binary, Raw:Len/binary, _/binary>> = Bin,
+            {{data, Raw, false}, S};
+        <<_:O/binary, C, _/binary>> ->
+            tokenize_textarea(Bin, ?INC_CHAR(S, C), Start);
+        <<_:Start/binary, Raw/binary>> ->
+            {{data, Raw, false}, S}
+    end.

Modified: incubator/couchdb/trunk/src/mochiweb/mochiweb_multipart.erl
URL: http://svn.apache.org/viewvc/incubator/couchdb/trunk/src/mochiweb/mochiweb_multipart.erl?rev=659244&r1=659243&r2=659244&view=diff
==============================================================================
--- incubator/couchdb/trunk/src/mochiweb/mochiweb_multipart.erl (original)
+++ incubator/couchdb/trunk/src/mochiweb/mochiweb_multipart.erl Thu May 22 13:30:57 2008
@@ -6,7 +6,7 @@
 -module(mochiweb_multipart).
 -author('bob@mochimedia.com').
 
--export([parse_form/2]).
+-export([parse_form/1, parse_form/2]).
 -export([parse_multipart_request/2]).
 -export([test/0]).
 
@@ -16,6 +16,9 @@
 
 %% TODO: DOCUMENT THIS MODULE.
 
+parse_form(Req) ->
+    parse_form(Req, fun default_file_handler/2).
+
 parse_form(Req, FileHandler) ->
     Callback = fun (Next) -> parse_form_outer(Next, FileHandler, []) end,
     {_, _, Res} = parse_multipart_request(Req, Callback),
@@ -56,6 +59,17 @@
     H1 = Handler(Data),
     fun (Next) -> parse_form_file(Next, {Name, H1}, FileHandler, State) end.
 
+default_file_handler(Filename, ContentType) ->
+    default_file_handler_1(Filename, ContentType, []).
+
+default_file_handler_1(Filename, ContentType, Acc) ->
+    fun(eof) ->
+            Value = iolist_to_binary(lists:reverse(Acc)),
+            {Filename, ContentType, Value};
+       (Next) ->
+            default_file_handler_1(Filename, ContentType, [Next | Acc])
+    end.
+
 parse_multipart_request(Req, Callback) ->
     %% TODO: Support chunked?
     Length = list_to_integer(Req:get_header_value("content-length")),
@@ -295,19 +309,6 @@
     ok = with_socket_server(ServerFun, ClientFun),
     ok.
 
-handler_test(Filename, ContentType) ->
-    fun (Next) ->
-            handler_test_read(Next, {Filename, ContentType}, [])
-    end.
-
-handler_test_read(eof, {Filename, ContentType}, Acc) ->
-    Value = iolist_to_binary(lists:reverse(Acc)),
-    {Filename, ContentType, Value};
-handler_test_read(Data, H, Acc) ->
-    Acc1 = [Data | Acc],
-    fun (Next) -> handler_test_read(Next, H, Acc1) end.
-
-
 test_parse_form() ->
     ContentType = "multipart/form-data; boundary=AaB03x",
     "AaB03x" = get_boundary(ContentType),
@@ -334,7 +335,7 @@
     ClientFun = fun (Socket) ->
                         Req = fake_request(Socket, ContentType,
                                            size(BinContent)),
-                        Res = parse_form(Req, fun handler_test/2),
+                        Res = parse_form(Req),
                         [{"submit-name", "Larry"},
                          {"files", {"file1.txt", {"text/plain",[]},
                                     <<"... contents of file1.txt ...">>}

Modified: incubator/couchdb/trunk/src/mochiweb/mochiweb_request.erl
URL: http://svn.apache.org/viewvc/incubator/couchdb/trunk/src/mochiweb/mochiweb_request.erl?rev=659244&r1=659243&r2=659244&view=diff
==============================================================================
--- incubator/couchdb/trunk/src/mochiweb/mochiweb_request.erl (original)
+++ incubator/couchdb/trunk/src/mochiweb/mochiweb_request.erl Thu May 22 13:30:57 2008
@@ -386,7 +386,7 @@
                              [];
                          Binary ->
                              case get_primary_header_value("content-type") of
-                                 "application/x-www-form-urlencoded" ->
+                                 "application/x-www-form-urlencoded" ++ _ ->
                                      mochiweb_util:parse_qs(Binary);
                                  _ ->
                                      []

Modified: incubator/couchdb/trunk/src/mochiweb/mochiweb_socket_server.erl
URL: http://svn.apache.org/viewvc/incubator/couchdb/trunk/src/mochiweb/mochiweb_socket_server.erl?rev=659244&r1=659243&r2=659244&view=diff
==============================================================================
--- incubator/couchdb/trunk/src/mochiweb/mochiweb_socket_server.erl (original)
+++ incubator/couchdb/trunk/src/mochiweb/mochiweb_socket_server.erl Thu May 22 13:30:57 2008
@@ -103,7 +103,8 @@
                 {packet, 0},
                 {backlog, Backlog},
                 {recbuf, 8192},
-                {active, false}],
+                {active, false},
+                {nodelay, true}],
     Opts = case Ip of
                any ->
                    BaseOpts;



Mime
View raw message