Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
biboumi
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
98
Issues
98
List
Boards
Labels
Service Desk
Milestones
Merge Requests
12
Merge Requests
12
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
louiz’
biboumi
Commits
020325db
Commit
020325db
authored
Apr 13, 2014
by
louiz’
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[WIP] DummyIrcChannel
parent
65601a96
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
101 additions
and
4 deletions
+101
-4
src/bridge/bridge.cpp
src/bridge/bridge.cpp
+20
-0
src/irc/irc_channel.cpp
src/irc/irc_channel.cpp
+6
-0
src/irc/irc_channel.hpp
src/irc/irc_channel.hpp
+32
-1
src/irc/irc_client.cpp
src/irc/irc_client.cpp
+22
-1
src/irc/irc_client.hpp
src/irc/irc_client.hpp
+17
-0
src/test.cpp
src/test.cpp
+1
-0
src/xmpp/xmpp_component.cpp
src/xmpp/xmpp_component.cpp
+3
-2
No files found.
src/bridge/bridge.cpp
View file @
020325db
#include <bridge/bridge.hpp>
#include <bridge/colors.hpp>
#include <xmpp/xmpp_component.hpp>
#include <irc/irc_message.hpp>
#include <network/poller.hpp>
#include <utils/encoding.hpp>
#include <logger/logger.hpp>
...
...
@@ -100,6 +101,25 @@ IrcClient* Bridge::get_irc_client(const std::string& hostname)
bool
Bridge
::
join_irc_channel
(
const
Iid
&
iid
,
const
std
::
string
&
username
)
{
IrcClient
*
irc
=
this
->
get_irc_client
(
iid
.
server
,
username
);
if
(
iid
.
chan
.
empty
())
{
// Join the dummy channel
if
(
irc
->
is_welcomed
())
{
if
(
irc
->
get_dummy_channel
().
joined
)
return
false
;
// Immediately simulate a message coming from the IRC server saying that we
// joined the channel
const
IrcMessage
join_message
(
irc
->
get_nick
(),
"JOIN"
,
{
""
});
irc
->
on_channel_join
(
join_message
);
const
IrcMessage
end_join_message
(
std
::
string
(
iid
.
server
),
"366"
,
{
irc
->
get_nick
(),
""
,
"End of NAMES list"
});
irc
->
on_channel_completely_joined
(
end_join_message
);
}
else
irc
->
get_dummy_channel
().
joining
=
true
;
return
true
;
}
if
(
irc
->
is_channel_joined
(
iid
.
chan
)
==
false
)
{
irc
->
send_join_command
(
iid
.
chan
);
...
...
src/irc/irc_channel.cpp
View file @
020325db
...
...
@@ -47,3 +47,9 @@ void IrcChannel::remove_user(const IrcUser* user)
}
}
}
DummyIrcChannel
::
DummyIrcChannel
()
:
IrcChannel
(),
joining
(
false
)
{
}
src/irc/irc_channel.hpp
View file @
020325db
...
...
@@ -25,13 +25,44 @@ public:
IrcUser
*
find_user
(
const
std
::
string
&
name
)
const
;
void
remove_user
(
const
IrcUser
*
user
);
pr
ivate
:
pr
otected
:
std
::
unique_ptr
<
IrcUser
>
self
;
std
::
vector
<
std
::
unique_ptr
<
IrcUser
>>
users
;
private:
IrcChannel
(
const
IrcChannel
&
)
=
delete
;
IrcChannel
(
IrcChannel
&&
)
=
delete
;
IrcChannel
&
operator
=
(
const
IrcChannel
&
)
=
delete
;
IrcChannel
&
operator
=
(
IrcChannel
&&
)
=
delete
;
};
/**
* A special channel that is not actually linked to any real irc
* channel. This is just a channel representing a connection to the
* server. If an user wants to maintain the connection to the server without
* having to be on any irc channel of that server, he can just join this
* dummy channel.
* It’s not actually dummy because it’s useful and it does things, but well.
*/
class
DummyIrcChannel
:
public
IrcChannel
{
public:
explicit
DummyIrcChannel
();
/**
* This flag is at true whenever the user wants to join this channel, but
* he is not yet connected to the server. When the connection is made, we
* check that flag and if it’s true, we inform the user that he has just
* joined that channel.
* If the user is already connected to the server when he tries to join
* the channel, we don’t use that flag, we just join it immediately.
*/
bool
joining
;
private:
DummyIrcChannel
(
const
DummyIrcChannel
&
)
=
delete
;
DummyIrcChannel
(
DummyIrcChannel
&&
)
=
delete
;
DummyIrcChannel
&
operator
=
(
const
DummyIrcChannel
&
)
=
delete
;
DummyIrcChannel
&
operator
=
(
DummyIrcChannel
&&
)
=
delete
;
};
#endif // IRC_CHANNEL_INCLUDED
src/irc/irc_client.cpp
View file @
020325db
...
...
@@ -280,7 +280,11 @@ void IrcClient::set_and_forward_user_list(const IrcMessage& message)
void
IrcClient
::
on_channel_join
(
const
IrcMessage
&
message
)
{
const
std
::
string
chan_name
=
utils
::
tolower
(
message
.
arguments
[
0
]);
IrcChannel
*
channel
=
this
->
get_channel
(
chan_name
);
IrcChannel
*
channel
;
if
(
chan_name
.
empty
())
channel
=
&
this
->
dummy_channel
;
else
channel
=
this
->
get_channel
(
chan_name
);
const
std
::
string
nick
=
message
.
prefix
;
if
(
channel
->
joined
==
false
)
channel
->
set_self
(
nick
);
...
...
@@ -394,6 +398,18 @@ void IrcClient::on_welcome_message(const IrcMessage& message)
for
(
const
std
::
string
&
chan_name
:
this
->
channels_to_join
)
this
->
send_join_command
(
chan_name
);
this
->
channels_to_join
.
clear
();
// Indicate that the dummy channel is joined as well, if needed
if
(
this
->
dummy_channel
.
joining
)
{
// Simulate a message coming from the IRC server saying that we joined
// the channel
const
IrcMessage
join_message
(
this
->
get_nick
(),
"JOIN"
,
{
""
});
this
->
on_channel_join
(
join_message
);
const
IrcMessage
end_join_message
(
std
::
string
(
this
->
hostname
),
"366"
,
{
this
->
get_nick
(),
""
,
"End of NAMES list"
});
this
->
on_channel_completely_joined
(
end_join_message
);
}
}
void
IrcClient
::
on_part
(
const
IrcMessage
&
message
)
...
...
@@ -624,3 +640,8 @@ size_t IrcClient::number_of_joined_channels() const
{
return
this
->
channels
.
size
();
}
DummyIrcChannel
&
IrcClient
::
get_dummy_channel
()
{
return
this
->
dummy_channel
;
}
src/irc/irc_client.hpp
View file @
020325db
...
...
@@ -194,6 +194,14 @@ public:
* Return the number of joined channels
*/
size_t
number_of_joined_channels
()
const
;
/**
* Get a reference to the unique dummy channel
*/
DummyIrcChannel
&
get_dummy_channel
();
const
std
::
string
&
get_hostname
()
const
{
return
this
->
hostname
;
}
std
::
string
get_nick
()
const
{
return
this
->
current_nick
;
}
bool
is_welcomed
()
const
{
return
this
->
welcomed
;
}
private:
/**
...
...
@@ -216,6 +224,11 @@ private:
* The list of joined channels, indexed by name
*/
std
::
unordered_map
<
std
::
string
,
std
::
unique_ptr
<
IrcChannel
>>
channels
;
/**
* A single channel with a iid of the form "hostname" (normal channel have
* an iid of the form "chan%hostname".
*/
DummyIrcChannel
dummy_channel
;
/**
* A list of chan we want to join, but we need a response 001 from
* the server before sending the actual JOIN commands. So we just keep the
...
...
@@ -223,6 +236,10 @@ private:
* whenever the WELCOME message is received.
*/
std
::
vector
<
std
::
string
>
channels_to_join
;
/**
* This flag indicates that the server is completely joined (connection
* has been established, we are authentified and we have a nick)
*/
bool
welcomed
;
/**
* See http://www.irc.org/tech_docs/draft-brocklesby-irc-isupport-03.txt section 3.3
...
...
src/test.cpp
View file @
020325db
...
...
@@ -10,6 +10,7 @@
#include <utils/tolower.hpp>
#include <utils/split.hpp>
#include <xmpp/jid.hpp>
#include <irc/iid.hpp>
#include <string.h>
#include <iostream>
...
...
src/xmpp/xmpp_component.cpp
View file @
020325db
...
...
@@ -290,8 +290,9 @@ void XmppComponent::handle_presence(const Stanza& stanza)
error_type
,
error_name
,
""
);
});
if
(
!
iid
.
chan
.
empty
()
&&
!
iid
.
server
.
empty
())
{
// presence toward a MUC that corresponds to an irc channel
if
(
!
iid
.
server
.
empty
())
{
// presence toward a MUC that corresponds to an irc channel, or a
// dummy channel if iid.chan is empty
if
(
type
.
empty
())
{
const
std
::
string
own_nick
=
bridge
->
get_own_nick
(
iid
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment