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
bfcc9cdc
Commit
bfcc9cdc
authored
Nov 21, 2013
by
louiz’
1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Send XMPP multi-line messages as multiple IRC messages
parent
70a58a8f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
14 deletions
+36
-14
src/bridge/bridge.cpp
src/bridge/bridge.cpp
+12
-5
src/test.cpp
src/test.cpp
+23
-8
src/utils/split.cpp
src/utils/split.cpp
+1
-1
No files found.
src/bridge/bridge.cpp
View file @
bfcc9cdc
...
...
@@ -73,6 +73,10 @@ 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
())
{
std
::
cout
<<
"Cannot send message to channel: ["
<<
iid
.
chan
<<
"] on server ["
<<
iid
.
server
<<
"]"
<<
std
::
endl
;
...
...
@@ -84,16 +88,19 @@ void Bridge::send_channel_message(const Iid& iid, const std::string& body)
std
::
cout
<<
"Cannot send message: no client exist for server "
<<
iid
.
server
<<
std
::
endl
;
return
;
}
if
(
body
.
substr
(
0
,
6
)
==
"/mode "
)
if
(
first_line
.
substr
(
0
,
6
)
==
"/mode "
)
{
std
::
vector
<
std
::
string
>
args
=
utils
::
split
(
body
.
substr
(
6
),
' '
,
false
);
std
::
vector
<
std
::
string
>
args
=
utils
::
split
(
first_line
.
substr
(
6
),
' '
,
false
);
irc
->
send_mode_command
(
iid
.
chan
,
args
);
return
;
}
if
(
body
.
substr
(
0
,
4
)
==
"/me "
)
irc
->
send_channel_message
(
iid
.
chan
,
action_prefix
+
body
.
substr
(
4
)
+
"
\01
"
);
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
,
body
);
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
(),
body
,
this
->
user_jid
);
...
...
src/test.cpp
View file @
bfcc9cdc
...
...
@@ -2,18 +2,18 @@
* Just a very simple test suite, by hand, using assert()
*/
#include <assert.h>
#include <iostream>
#include <bridge/colors.hpp>
#include <xmpp/xmpp_parser.hpp>
#include <utils/encoding.hpp>
#include <config/config.hpp>
#include <bridge/colors.hpp>
#include <utils/split.hpp>
#include <xmpp/jid.hpp>
#include <string.h>
#include <config/config.hpp>
#include <iostream>
#include <vector>
#include <xmpp/jid.hpp>
#include <xmpp/xmpp_parser.hpp>
#include <assert.h>
int
main
()
{
...
...
@@ -48,6 +48,21 @@ int main()
remove_irc_colors
(
coucou
);
assert
(
coucou
==
"COUCOU"
);
/**
* Utils
*/
std
::
vector
<
std
::
string
>
splitted
=
utils
::
split
(
"a::a"
,
':'
,
false
);
assert
(
splitted
.
size
()
==
2
);
splitted
=
utils
::
split
(
"a::a"
,
':'
,
true
);
assert
(
splitted
.
size
()
==
3
);
assert
(
splitted
[
0
]
==
"a"
);
assert
(
splitted
[
1
]
==
""
);
assert
(
splitted
[
2
]
==
"a"
);
splitted
=
utils
::
split
(
"
\n
a"
,
'\n'
,
true
);
assert
(
splitted
.
size
()
==
2
);
assert
(
splitted
[
0
]
==
""
);
assert
(
splitted
[
1
]
==
"a"
);
/**
* XML parsing
*/
...
...
src/utils/split.cpp
View file @
bfcc9cdc
...
...
@@ -2,7 +2,7 @@
namespace
utils
{
std
::
vector
<
std
::
string
>
split
(
const
std
::
string
&
s
,
const
char
delim
,
const
bool
allow_empty
)
std
::
vector
<
std
::
string
>
split
(
const
std
::
string
&
s
,
const
char
delim
,
const
bool
allow_empty
)
{
std
::
vector
<
std
::
string
>
ret
;
std
::
stringstream
ss
(
s
);
...
...
Pacien
@Pacien
Mentioned in issue
#3214 (closed)
·
Oct 08, 2016
Mentioned in issue
#3214 (closed)
Mentioned in issue #3214
Toggle commit list
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