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
99
Issues
99
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
01cd6eb5
Commit
01cd6eb5
authored
May 18, 2014
by
louiz’
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Split the messages on \n when sending them back to the XMPP user
parent
df765faa
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
19 deletions
+25
-19
src/bridge/bridge.cpp
src/bridge/bridge.cpp
+25
-19
No files found.
src/bridge/bridge.cpp
View file @
01cd6eb5
...
...
@@ -135,10 +135,6 @@ bool Bridge::join_irc_channel(const Iid& iid, const std::string& username)
void
Bridge
::
send_channel_message
(
const
Iid
&
iid
,
const
std
::
string
&
body
)
{
std
::
vector
<
std
::
string
>
lines
=
utils
::
split
(
body
,
'\n'
,
true
);
if
(
lines
.
empty
())
return
;
const
std
::
string
first_line
=
lines
[
0
];
if
(
iid
.
chan
.
empty
()
||
iid
.
server
.
empty
())
{
log_warning
(
"Cannot send message to channel: ["
<<
iid
.
chan
<<
"] on server ["
<<
iid
.
server
<<
"]"
);
...
...
@@ -150,23 +146,33 @@ void Bridge::send_channel_message(const Iid& iid, const std::string& body)
log_warning
(
"Cannot send message: no client exist for server "
<<
iid
.
server
);
return
;
}
if
(
first_line
.
substr
(
0
,
6
)
==
"/mode "
)
// Because an IRC message cannot contain \n, we need to convert each line
// of text into a separate IRC message. For conveniance, we also cut the
// message into submessages on the XMPP side, this way the user of the
// gateway sees what was actually sent over IRC. For example if an user
// sends “hello\n/me waves”, two messages will be generated: “hello” and
// “/me waves”. Note that the “command” handling (messages starting with
// /me, /mode, etc) is done for each message generated this way. In the
// above example, the /me will be interpreted.
std
::
vector
<
std
::
string
>
lines
=
utils
::
split
(
body
,
'\n'
,
true
);
if
(
lines
.
empty
())
return
;
for
(
const
std
::
string
&
line
:
lines
)
{
std
::
vector
<
std
::
string
>
args
=
utils
::
split
(
first_line
.
substr
(
6
),
' '
,
false
);
irc
->
send_mode_command
(
iid
.
chan
,
args
);
return
;
if
(
line
.
substr
(
0
,
6
)
==
"/mode "
)
{
std
::
vector
<
std
::
string
>
args
=
utils
::
split
(
line
.
substr
(
6
),
' '
,
false
);
irc
->
send_mode_command
(
iid
.
chan
,
args
);
continue
;
// We do not want to send that back to the
// XMPP user, that’s not a textual message.
}
else
if
(
line
.
substr
(
0
,
4
)
==
"/me "
)
irc
->
send_channel_message
(
iid
.
chan
,
action_prefix
+
line
.
substr
(
4
)
+
"
\01
"
);
else
irc
->
send_channel_message
(
iid
.
chan
,
line
);
this
->
xmpp
->
send_muc_message
(
iid
.
chan
+
"%"
+
iid
.
server
,
irc
->
get_own_nick
(),
this
->
make_xmpp_body
(
line
),
this
->
user_jid
);
}
if
(
first_line
.
substr
(
0
,
4
)
==
"/me "
)
irc
->
send_channel_message
(
iid
.
chan
,
action_prefix
+
first_line
.
substr
(
4
)
+
"
\01
"
);
else
irc
->
send_channel_message
(
iid
.
chan
,
first_line
);
// Send each of the other lines of the message as a separate IRC message
for
(
std
::
vector
<
std
::
string
>::
const_iterator
it
=
lines
.
begin
()
+
1
;
it
!=
lines
.
end
();
++
it
)
irc
->
send_channel_message
(
iid
.
chan
,
*
it
);
// We do not need to convert body to utf-8: it comes from our XMPP server,
// so it's ok to send it back
this
->
xmpp
->
send_muc_message
(
iid
.
chan
+
"%"
+
iid
.
server
,
irc
->
get_own_nick
(),
this
->
make_xmpp_body
(
body
),
this
->
user_jid
);
}
void
Bridge
::
send_private_message
(
const
Iid
&
iid
,
const
std
::
string
&
body
,
const
std
::
string
&
type
)
...
...
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