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.5
Committed: Sun Aug 1 10:41:08 2004 UTC (19 years, 8 months ago) by tdb
Branch: MAIN
CVS Tags: HEAD
Changes since 1.4: +3 -3 lines
Log Message:
Catch a lot of old URL's and update them. Also remove a couple of old files
that aren't used.

File Contents

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