Permalink
Browse files

Switch back to exmpp, revert "feeds_fetch: switch to erlsom"

This reverts commit 894e499.
  • Loading branch information...
astro committed Apr 10, 2012
1 parent 9dfa636 commit a8a2e8623e9be62859d71579cda2b502b682414f
Showing with 33 additions and 44 deletions.
  1. +29 −41 apps/feeds/src/feeds_fetch.erl
  2. +4 −3 rebar.config
@@ -4,56 +4,44 @@
fetch(Url) ->
+ Parser = exmpp_xml:start_parser([{max_size, 10 * 1024 * 1024},
+ {names_as_atom, false},
+ {engine, expat}]),
+ http_fold(Url, fun(Chunk, _) ->
+ R1 = exmpp_xml:parse(Parser, Chunk),
+ io:format("Parsed: ~p~n",[R1])
+ end, undefined),
+ exmpp_xml:parse_final(Parser, <<"">>),
+ R = exmpp_xml:stop_parser(Parser),
+ io:format("Downloaded ~s - ~p~n",[Url,R]),
+ receive
+ M -> io:format("M=~p~n",[M])
+ after 1000 ->
+ ignore
+ end,
+ ok.
+
+http_fold(Url, Fold, AccIn) ->
Headers =
[{"User-Agent", "PritTorrent/0.1"}],
{ibrowse_req_id, ReqId} =
ibrowse:send_req(Url, Headers, get, [],
[{stream_to, {self(), once}}], 10000),
+ http_fold1(ReqId, Fold, AccIn).
+http_fold1(ReqId, Fold, AccIn) ->
ok = ibrowse:stream_next(ReqId),
receive
{ibrowse_async_headers, ReqId, [$2, _, _], _Headers} ->
- ok;
+ http_fold1(ReqId, Fold, AccIn);
{ibrowse_async_headers, ReqId, StatusS, _Headers} ->
{Status, _} = string:to_integer(StatusS),
exit({http, Status});
- {ibrowse_async_response, ReqId, {error, Err1}} ->
- exit(Err1)
- end,
-
- Continuation =
- fun(Tail, _) ->
- ok = ibrowse:stream_next(ReqId),
- receive
- {ibrowse_async_response, ReqId, Data} ->
- Bin = list_to_binary(Data),
- {<<Tail/binary, Bin/binary>>, ok};
- {ibrowse_async_response_end, ReqId} ->
- {Tail, eof};
- {ibrowse_async_response, ReqId, {error, Err2}} ->
- exit(Err2)
- end
- end,
-
- {ok, Result, _TrailingBytes} =
- erlsom:parse_sax(<<>>, state, fun sax_callback/2,
- [{continuation_function, Continuation, state}]),
- {ok, Result}.
-
-sax_callback(startDocument, _) ->
- {false, []};
-sax_callback({startElement, _, "title", _, _}, {false, Titles}) ->
- {"", Titles};
-sax_callback({characters, C}, {Title, Titles}) when is_list(Title) ->
- {Title ++ C, Titles};
-sax_callback({endElement, _, "title", _}, {Title, Titles}) when is_list(Title) ->
- {false, [Title | Titles]};
-sax_callback(endDocument, State) ->
- case State of
- {false, Titles} ->
- lists:reverse(Titles);
- _ ->
- []
- end;
-sax_callback(_Event, State) ->
- State.
+ {ibrowse_async_response, ReqId, {error, Err}} ->
+ exit(Err);
+ {ibrowse_async_response, ReqId, Data} ->
+ AccOut = Fold(list_to_binary(Data), AccIn),
+ http_fold1(ReqId, Fold, AccOut);
+ {ibrowse_async_response_end, ReqId} ->
+ AccIn
+ end.
View
@@ -1,4 +1,4 @@
-{sub_dirs, ["apps/servtorrent", "apps/model", "apps/ui", "apps/feeds"]}.
+{sub_dirs, ["apps/servtorrent", "apps/model", "apps/ui"]}.
{deps, [{misultin, "0.*",
{git, "git://github.com/ostinelli/misultin.git", {branch, "master"}}},
@@ -10,6 +10,7 @@
{git, "git://github.com/tonyg/erlang-rfc4627.git", {branch, "master"}}},
{poolboy, "0.*",
{git, "git://github.com/devinus/poolboy.git", {branch, "master"}}},
- {erlsom, "1.2.*",
- {git, "git://github.com/willemdj/erlsom.git", {branch, "master"}}}
+ %{exmpp, "1.*",
+ %{git, "git://git.process-one.net/exmpp/mainline.git", {branch, "master"}}}
+ %{git, "git://github.com/Zert/exmpp.git", {branch, "master"}}}
]}.

0 comments on commit a8a2e86

Please sign in to comment.