ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/util/uk/org/iscream/cms/util/ACLDatagramSocket.java
Revision: 1.2
Committed: Sat May 18 18:16:03 2002 UTC (21 years, 11 months ago) by tdb
Branch: MAIN
Changes since 1.1: +21 -2 lines
Log Message:
i-scream is now licensed under the GPL. I've added the GPL headers to every
source file, and put a full copy of the license in the appropriate places.
I think I've covered everything. This is going to be a mad commit ;)

File Contents

# Content
1 /*
2 * i-scream central monitoring system
3 * Copyright (C) 2000-2002 i-scream
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */
19
20 //---PACKAGE DECLARATION---
21 package uk.org.iscream.cms.server.util;
22
23 //---IMPORTS---
24 import java.net.DatagramSocket;
25 import java.net.DatagramPacket;
26 import java.net.InetAddress;
27 import java.io.IOException;
28
29 /**
30 * Access Control List DatagramSocket wrapper. Used
31 * to wrap a DatagramSocket with an ACL, whilst extending
32 * DatagramSocket to make integration into code easier.
33 * Once the ACL has been set, receive() can be used exactly
34 * as it would be with a DatagramSocket.
35 *
36 * @author $Author: tdb $
37 * @version $Id: ACLDatagramSocket.java,v 1.1 2002/01/08 14:24:28 tdb Exp $
38 */
39 public class ACLDatagramSocket extends DatagramSocket {
40
41 //---FINAL ATTRIBUTES---
42
43 /**
44 * The current CVS revision of this class
45 */
46 public static final String REVISION = "$Revision: 1.1 $";
47
48 //---STATIC METHODS---
49
50 //---CONSTRUCTORS---
51
52 /**
53 * See relevant DatagramSocket constructor.
54 */
55 public ACLDatagramSocket() throws IOException {
56 super();
57 setACL(new ACL());
58 }
59
60 /**
61 * See relevant DatagramSocket constructor.
62 */
63 public ACLDatagramSocket(int port) throws IOException {
64 super(port);
65 setACL(new ACL());
66 }
67
68 /**
69 * See relevant DatagramSocket constructor.
70 */
71 public ACLDatagramSocket(int port, InetAddress laddr) throws IOException {
72 super(port, laddr);
73 setACL(new ACL());
74 }
75
76 /**
77 * See relevant DatagramSocket constructor, and
78 * sets the default acl.
79 */
80 public ACLDatagramSocket(ACL acl) throws IOException {
81 super();
82 setACL(acl);
83 }
84
85 /**
86 * See relevant DatagramSocket constructor, and
87 * sets the default acl.
88 */
89 public ACLDatagramSocket(ACL acl, int port) throws IOException {
90 super(port);
91 setACL(acl);
92 }
93
94 /**
95 * See relevant DatagramSocket constructor, and
96 * sets the default acl.
97 */
98 public ACLDatagramSocket(ACL acl, int port, InetAddress laddr) throws IOException {
99 super(port, laddr);
100 setACL(acl);
101 }
102
103 //---PUBLIC METHODS---
104
105 /**
106 * Essentially has the same behaviour as the
107 * Datagram.receive() method, except won't
108 * return unless it is permitted by the ACL.
109 */
110 public void receive(DatagramPacket p) throws IOException {
111 while(true) {
112 super.receive(p);
113 if(_acl.check(p.getAddress())) {
114 return;
115 }
116 }
117 }
118
119 /**
120 * Set the ACL at any point in the operation
121 * of the DatagramSocket.
122 *
123 * @param acl the new ACL to apply
124 */
125 public void setACL(ACL acl) {
126 _acl = acl;
127 }
128
129 /**
130 * Overrides the {@link java.lang.Object#toString() Object.toString()}
131 * method to provide clean logging (every class should have this).
132 *
133 * This uses the uk.org.iscream.cms.server.util.FormatName class
134 * to format the toString()
135 *
136 * @return the name of this class and its CVS revision
137 */
138 public String toString() {
139 return FormatName.getName(
140 _name,
141 getClass().getName(),
142 REVISION);
143 // super.toString() isn't implemented...
144 //REVISION) + ":" + super.toString();
145 }
146
147 //---PRIVATE METHODS---
148
149 //---ACCESSOR/MUTATOR METHODS---
150
151 //---ATTRIBUTES---
152
153 /**
154 * This is the friendly identifier of the
155 * component this class is running in.
156 * eg, a Filter may be called "filter1",
157 * If this class does not have an owning
158 * component, a name from the configuration
159 * can be placed here. This name could also
160 * be changed to null for utility classes.
161 */
162 private String _name = null;
163
164 /**
165 * The ACL used by this ACLDatagramSocket.
166 */
167 private ACL _acl;
168
169 //---STATIC ATTRIBUTES---
170
171 //---INNER CLASSES---
172
173 }