Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
Openfire
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Openfire
Commits
fe357fc1
Commit
fe357fc1
authored
Sep 24, 2017
by
Guus der Kinderen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove duplicated code (no functional changes).
parent
0650e0db
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
44 deletions
+52
-44
InterceptorManager.java
...jivesoftware/openfire/interceptor/InterceptorManager.java
+52
-44
No files found.
src/java/org/jivesoftware/openfire/interceptor/InterceptorManager.java
View file @
fe357fc1
...
@@ -16,6 +16,12 @@
...
@@ -16,6 +16,12 @@
package
org
.
jivesoftware
.
openfire
.
interceptor
;
package
org
.
jivesoftware
.
openfire
.
interceptor
;
import
org.jivesoftware.openfire.XMPPServer
;
import
org.jivesoftware.openfire.session.Session
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.xmpp.packet.Packet
;
import
java.util.Collection
;
import
java.util.Collection
;
import
java.util.Collections
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.List
;
...
@@ -23,12 +29,6 @@ import java.util.Map;
...
@@ -23,12 +29,6 @@ import java.util.Map;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.CopyOnWriteArrayList
;
import
java.util.concurrent.CopyOnWriteArrayList
;
import
org.jivesoftware.openfire.XMPPServer
;
import
org.jivesoftware.openfire.session.Session
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.xmpp.packet.Packet
;
/**
/**
* An InterceptorManager manages the list of global interceptors and per-user
* An InterceptorManager manages the list of global interceptors and per-user
* interceptors that are invoked before and after packets are read and sent.
* interceptors that are invoked before and after packets are read and sent.
...
@@ -227,27 +227,8 @@ public class InterceptorManager {
...
@@ -227,27 +227,8 @@ public class InterceptorManager {
throws
PacketRejectedException
throws
PacketRejectedException
{
{
// Invoke the global interceptors for this packet
// Invoke the global interceptors for this packet
// Checking if collection is empty to prevent creating an iterator of
invokeInterceptors
(
globalInterceptors
,
packet
,
session
,
read
,
processed
);
// a CopyOnWriteArrayList that is an expensive operation
if
(!
globalInterceptors
.
isEmpty
())
{
for
(
PacketInterceptor
interceptor
:
globalInterceptors
)
{
try
{
interceptor
.
interceptPacket
(
packet
,
session
,
read
,
processed
);
}
catch
(
PacketRejectedException
e
)
{
if
(
processed
)
{
Log
.
error
(
"Post interceptor cannot reject packet."
,
e
);
}
else
{
// Throw this exception since we don't really want to catch it
throw
e
;
}
}
catch
(
Throwable
e
)
{
Log
.
error
(
"Error in interceptor: "
+
interceptor
+
" while intercepting: "
+
packet
,
e
);
}
}
}
// Invoke the interceptors that are related to the address of the session
// Invoke the interceptors that are related to the address of the session
if
(
usersInterceptors
.
isEmpty
())
{
if
(
usersInterceptors
.
isEmpty
())
{
// Do nothing
// Do nothing
...
@@ -256,24 +237,51 @@ public class InterceptorManager {
...
@@ -256,24 +237,51 @@ public class InterceptorManager {
String
username
=
session
!=
null
?
session
.
getAddress
().
getNode
()
:
null
;
String
username
=
session
!=
null
?
session
.
getAddress
().
getNode
()
:
null
;
if
(
username
!=
null
&&
server
.
isLocal
(
session
.
getAddress
()))
{
if
(
username
!=
null
&&
server
.
isLocal
(
session
.
getAddress
()))
{
Collection
<
PacketInterceptor
>
userInterceptors
=
usersInterceptors
.
get
(
username
);
Collection
<
PacketInterceptor
>
userInterceptors
=
usersInterceptors
.
get
(
username
);
if
(
userInterceptors
!=
null
&&
!
userInterceptors
.
isEmpty
())
{
invokeInterceptors
(
userInterceptors
,
packet
,
session
,
read
,
processed
);
for
(
PacketInterceptor
interceptor
:
userInterceptors
)
{
}
try
{
}
interceptor
.
interceptPacket
(
packet
,
session
,
read
,
processed
);
}
/**
catch
(
PacketRejectedException
e
)
{
* Invokes a collection of interceptors for the provided packet.
if
(
processed
)
{
*
Log
.
error
(
"Post interceptor cannot reject packet."
,
e
);
* @param interceptors The interceptors to be triggered (can be null, can be empty).
}
* @param packet the packet that has been read or is about to be sent.
else
{
* @param session the session that received the packet or that the packet
// Throw this exception since we don't really want to catch it
* will be sent to.
throw
e
;
* @param read true indicates that the packet was read. When false, the packet
}
* is being sent to a user.
}
* @param processed true if the packet has already processed (incoming or outgoing).
catch
(
Throwable
e
)
{
* If the packet hasn't already been processed, this flag will be false.
Log
.
error
(
"Error in interceptor: "
+
interceptor
+
" while intercepting: "
+
packet
,
e
);
* @throws PacketRejectedException if the packet should be prevented from being processed.
}
*/
protected
static
void
invokeInterceptors
(
Collection
<
PacketInterceptor
>
interceptors
,
Packet
packet
,
Session
session
,
boolean
read
,
boolean
processed
)
throws
PacketRejectedException
{
if
(
interceptors
==
null
||
interceptors
.
isEmpty
()
)
{
return
;
}
for
(
final
PacketInterceptor
interceptor
:
interceptors
)
{
try
{
interceptor
.
interceptPacket
(
packet
,
session
,
read
,
processed
);
}
catch
(
PacketRejectedException
e
)
{
if
(
processed
)
{
Log
.
error
(
"Post interceptor cannot reject packet."
,
e
);
}
}
else
{
// Throw this exception since we don't really want to catch it
throw
e
;
}
}
catch
(
Throwable
e
)
{
Log
.
error
(
"Error in interceptor: "
+
interceptor
+
" while intercepting: "
+
packet
,
e
);
}
}
}
}
}
}
...
...
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