]> granicus.if.org Git - ejabberd/commitdiff
* src/mod_irc/: Still not completed...
authorAlexey Shchepin <alexey@process-one.net>
Mon, 17 Feb 2003 19:43:50 +0000 (19:43 +0000)
committerAlexey Shchepin <alexey@process-one.net>
Mon, 17 Feb 2003 19:43:50 +0000 (19:43 +0000)
SVN Revision: 76

src/ejabberd.cfg
src/mod_irc/mod_irc.erl
src/mod_irc/mod_irc_connection.erl

index f2f00b456d500b77e64c5a9af54616efcf9859a2..3373837f68e56f01eb50d376c8fd12ab6f670e79 100644 (file)
@@ -34,9 +34,9 @@
                      {normal, all}]}.
 
 
-{host, "localhost"}.
+{host, "e.localhost"}.
 
-{listen, [{5222, ejabberd_c2s,     start, [{access, c2s},
+{listen, [{5522, ejabberd_c2s,     start, [{access, c2s},
                                           {shaper, c2s_shaper}]},
          %{5523, ejabberd_c2s,     start,
          % [{access, c2s}, {ssl, [{certfile, "./ssl.pem"}]}]},
@@ -46,7 +46,7 @@
          ]}.
 
 % This value (5569) is only for debugging, must be 5269
-{outgoing_s2s_port, 5269}.
+{outgoing_s2s_port, 5569}.
 
 {modules, [
            {mod_register,  []},
index d9fad181787d3bda395856e001c4fddee10d6922..3d30852356a60e5c6dc0cc94820084fe95898ffc 100644 (file)
@@ -15,6 +15,7 @@
 -export([start/1, init/1, stop/0, closed_conection/2]).
 
 -include("ejabberd.hrl").
+-include("namespaces.hrl").
 
 -record(irc_connection, {userserver, pid}).
 
@@ -52,9 +53,32 @@ do_route(Host, From, To, Packet) ->
     {ChanServ, _, Resource} = To,
     case ChanServ of
        "" ->
-           % TODO
-           Err = jlib:make_error_reply(Packet, "406", "Not Acceptable"),
-           ejabberd_router:route(To, From, Err);
+           case Resource of
+               "" ->
+                   case jlib:iq_query_info(Packet) of
+                       {iq, ID, get, ?NS_DISCO_INFO = XMLNS, SubEl} ->
+                           Res = {iq, ID, result, XMLNS,
+                                  [{xmlelement, "query",
+                                    [{"xmlns", XMLNS}],
+                                    [{xmlelement, "identity",
+                                      [{"category", "conference"},
+                                       {"type", "irc"},
+                                       {"name", "ejabberd"}], []},
+                                     {xmlelement, "feature",
+                                      [{"var", ?NS_MUC}], []}]}]},
+                           ejabberd_router:route(To,
+                                                 From,
+                                                 jlib:iq_to_xml(Res));
+                       _ ->
+                           Err = jlib:make_error_reply(
+                                   Packet, "503", "Service Unavailable"),
+                           ejabberd_router:route(To, From, Err)
+                   end;
+               _ ->
+                   Err = jlib:make_error_reply(Packet,
+                                               "406", "Not Acceptable"),
+                   ejabberd_router:route(To, From, Err)
+           end;
        _ ->
            case string:tokens(ChanServ, "%") of
                [[_ | _] = Channel, [_ | _] = Server] ->
index f147742aeb542c193ad4d4f99a1f041a94e2e2e8..829125252341a861b6c18db89860912ba1996a8f 100644 (file)
@@ -18,7 +18,7 @@
 %% gen_fsm callbacks
 -export([init/1,
         open_socket/2,
-        %wait_for_registration/2,
+        wait_for_registration/2,
         stream_established/2,
         handle_event/3,
         handle_sync_event/4,
@@ -109,6 +109,19 @@ open_socket(init, StateData) ->
            {stop, normal, StateData}
     end.
 
+wait_for_registration(closed, StateData) ->
+    bounce_messages("Server Connect Failed"),
+    lists:foreach(
+      fun(Chan) ->
+             ejabberd_router:route(
+               {lists:concat([Chan, "%", StateData#state.server]),
+                StateData#state.myname, StateData#state.nick},
+               StateData#state.user,
+               {xmlelement, "presence", [{"type", "error"}],
+                [{xmlelement, "error", [{"code", "502"}],
+                  [{xmlcdata, "Server Connect Failed"}]}]})
+      end, ?SETS:to_list(StateData#state.channels)),
+    {stop, normal, StateData}.
 
 stream_established({xmlstreamend, Name}, StateData) ->
     {stop, normal, StateData};
@@ -208,9 +221,21 @@ handle_info({route, Channel, Resource,
                  {lists:concat([Channel, "%", StateData#state.server]),
                   StateData#state.myname, StateData#state.nick},
                  StateData#state.user, El),
-               % TODO: remove newlines from body
                Body = xml:get_path_s(El, [{elem, "body"}, cdata]),
-               ?SEND(io_lib:format("PRIVMSG #~s :~s\r\n", [Channel, Body]));
+               Body1 = case Body of
+                           [$/, $m, $e, $  | Rest] ->
+                               "\001ACTION " ++ Rest ++ "\001";
+                           _ ->
+                               Body
+                       end,
+               Strings = string:tokens(Body1, "\n"),
+               Res = lists:concat(
+                       lists:map(
+                         fun(S) ->
+                                 io_lib:format("PRIVMSG #~s :~s\r\n",
+                                               [Channel, S])
+                         end, Strings)),
+               ?SEND(Res);
            _ -> StateData
        end,
     {next_state, StateName, NewStateData};
@@ -231,7 +256,10 @@ handle_info({ircstring, [$: | String]}, StateName, StateData) ->
                process_channel_list(StateData, Items),
                StateData;
            [From, "PRIVMSG", [$# | Chan] | _] ->
-               process_privmsg(StateData, Chan, From, String),
+               process_chanprivmsg(StateData, Chan, From, String),
+               StateData;
+           [From, "PRIVMSG", Nick, ":\001VERSION\001" | _] ->
+               process_version(StateData, Nick, From),
                StateData;
            [From, "PART", [$# | Chan] | _] ->
                process_part(StateData, Chan, From, String),
@@ -338,14 +366,14 @@ send_text(Socket, Text) ->
 send_element(Socket, El) ->
     send_text(Socket, xml:element_to_string(El)).
 
-send_queue(Socket, Q) ->
-    case queue:out(Q) of
-       {{value, El}, Q1} ->
-           send_element(Socket, El),
-           send_queue(Socket, Q1);
-       {empty, Q1} ->
-           ok
-    end.
+%send_queue(Socket, Q) ->
+%    case queue:out(Q) of
+%      {{value, El}, Q1} ->
+%          send_element(Socket, El),
+%          send_queue(Socket, Q1);
+%      {empty, Q1} ->
+%          ok
+%    end.
 
 bounce_messages(Reason) ->
     receive
@@ -414,7 +442,7 @@ process_channel_list_user(StateData, Chan, User) ->
                               []}]}]}).
 
 
-process_privmsg(StateData, Chan, From, String) ->
+process_chanprivmsg(StateData, Chan, From, String) ->
     [FromUser | _] = string:tokens(From, "!"),
     Msg = lists:last(string:tokens(String, ":")),
     Msg1 = case Msg of
@@ -439,6 +467,25 @@ process_privmsg(StateData, Chan, From, String) ->
                          {xmlelement, "message", [{"type", "groupchat"}],
                           [{xmlelement, "body", [], [{xmlcdata, Msg2}]}]}).
 
+process_version(StateData, Nick, From) ->
+    case StateData#state.nick of
+       Nick ->
+           [FromUser | _] = string:tokens(From, "!"),
+           send_text(
+             StateData#state.socket,
+             io_lib:format("NOTICE ~s :\001VERSION "
+                           "ejabberd IRC transport ~s (c) Alexey Shchepin"
+                           "\001\r\n",
+                           [FromUser, ?VERSION]) ++
+             io_lib:format("NOTICE ~s :\001VERSION "
+                           "http://www.jabber.ru/projects/ejabberd/"
+                           "\001\r\n",
+                           [FromUser]));
+       _ ->
+           ok
+    end.
+
+
 process_part(StateData, Chan, From, String) ->
     [FromUser | _] = string:tokens(From, "!"),
     %Msg = lists:last(string:tokens(String, ":")),