Skip to content

Commit

Permalink
Make password argument to connect optional
Browse files Browse the repository at this point in the history
If no password is supplied, don't send the PASS command at all.

Signed-off-by: John Else <john.else@citrix.com>
  • Loading branch information
johnelse committed Mar 9, 2014
1 parent 3f13614 commit bc2e8c6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
16 changes: 10 additions & 6 deletions lib/irc_client.ml
Expand Up @@ -40,21 +40,25 @@ module Make(Io: Irc_transport.IO) = struct
send_raw ~connection
~data:(Printf.sprintf "USER %s %i * :%s" username mode realname)

let connect ~addr ~port ~username ~mode ~realname ~nick ~password =
let connect ~addr ~port ~username ~mode ~realname ~nick ?password () =
Io.open_socket addr port >>= (fun sock ->
let connection = {sock = sock} in
send_pass ~connection ~password
let connection = {sock = sock} in begin
match password with
| Some password -> send_pass ~connection ~password
| None -> return ()
end
>>= (fun () -> send_nick ~connection ~nick)
>>= (fun () -> send_user ~connection ~username ~mode ~realname)
>>= (fun () -> return connection))

let connect_by_name ~server ~port ~username ~mode ~realname ~nick ~password =
let connect_by_name ~server ~port ~username ~mode
~realname ~nick ?password () =
Io.gethostbyname server >>= fun addr_list ->
match addr_list with
| [] -> Io.return None
| addr ::_ ->
connect ~addr ~port ~username ~mode ~realname ~nick ~password >>= fun c ->
Io.return (Some c)
connect ~addr ~port ~username ~mode ~realname ~nick ?password ()
>>= fun c -> Io.return (Some c)

let listen ~connection ~callback =
let read_length = 1024 in
Expand Down
5 changes: 3 additions & 2 deletions lib/irc_client.mli
Expand Up @@ -13,10 +13,11 @@ module Make : functor (Io: Irc_transport.IO) ->
username:string -> mode:int -> realname:string -> unit Io.t

val connect : addr:Io.inet_addr -> port:int -> username:string -> mode:int ->
realname:string -> nick:string -> password:string -> connection_t Io.t
realname:string -> nick:string -> ?password:string -> unit ->
connection_t Io.t

val connect_by_name : server:string -> port:int -> username:string ->
mode:int -> realname:string -> nick:string -> password:string ->
mode:int -> realname:string -> nick:string -> ?password:string -> unit ->
connection_t option Io.t
(** Try to resolve the [server] name using DNS, otherwise behaves like
{!connect}. Returns [None] if no IP could be found for the given
Expand Down

0 comments on commit bc2e8c6

Please sign in to comment.