1 | package com.bowman.cardserv.rmi;
|
---|
2 |
|
---|
3 | import com.bowman.cardserv.util.ProxyLogger;
|
---|
4 | import com.bowman.cardserv.*;
|
---|
5 | import com.bowman.cardserv.cws.ServiceMapping;
|
---|
6 | import com.bowman.cardserv.crypto.DESUtil;
|
---|
7 | import com.bowman.cardserv.session.*;
|
---|
8 | import com.bowman.cardserv.tv.TvService;
|
---|
9 | import com.bowman.cardserv.interfaces.*;
|
---|
10 |
|
---|
11 | import java.rmi.server.UnicastRemoteObject;
|
---|
12 | import java.rmi.RemoteException;
|
---|
13 | import java.util.*;
|
---|
14 | import java.util.logging.Level;
|
---|
15 |
|
---|
16 | /**
|
---|
17 | * Created by IntelliJ IDEA.
|
---|
18 | * User: bowman
|
---|
19 | * Date: Oct 23, 2005
|
---|
20 | * Time: 10:54:23 PM
|
---|
21 | */
|
---|
22 | public class RemoteHandler extends UnicastRemoteObject implements RemoteProxy, UserStatusListener, CwsListener,
|
---|
23 | EcmTransactionListener, LogListener, Runnable
|
---|
24 | {
|
---|
25 | private static final long EVENT_START_DELAY = 15 * 1000;
|
---|
26 |
|
---|
27 | private Map listeners = new HashMap();
|
---|
28 |
|
---|
29 | private CardServProxy proxy;
|
---|
30 | private ProxyConfig config;
|
---|
31 | private ProxyLogger logger;
|
---|
32 | private SessionManager sm;
|
---|
33 |
|
---|
34 | private List eventQueue = Collections.synchronizedList(new ArrayList());
|
---|
35 | private Thread eventThread;
|
---|
36 | private String name;
|
---|
37 |
|
---|
38 | public RemoteHandler(int port, CardServProxy proxy) throws RemoteException {
|
---|
39 | super(port);
|
---|
40 | this.proxy = proxy;
|
---|
41 | this.config = ProxyConfig.getInstance();
|
---|
42 | this.logger = ProxyLogger.getLabeledLogger(getClass().getName());
|
---|
43 | this.sm = SessionManager.getInstance();
|
---|
44 | ProxyLogger.setLogListener(this);
|
---|
45 | }
|
---|
46 |
|
---|
47 | public void start() {
|
---|
48 | eventThread = new Thread(this, "RemoteEventDispatcherThread");
|
---|
49 | eventThread.start();
|
---|
50 |
|
---|
51 | sm.addUserStatusListener(this);
|
---|
52 | config.getConnManager().addCwsListener(this);
|
---|
53 |
|
---|
54 | fireRemoteEvent(new RemoteEvent(RemoteEvent.PROXY_STARTUP, name, "Proxy node started.", null));
|
---|
55 | }
|
---|
56 |
|
---|
57 | private synchronized void fireRemoteEvent(RemoteEvent event) {
|
---|
58 | if(eventThread == null) return; // rmi has been disabled
|
---|
59 | if(event.getType() == RemoteEvent.CWS_CONNECTED &&
|
---|
60 | System.currentTimeMillis() - proxy.getStartTime() < EVENT_START_DELAY) return; // filter events on startup
|
---|
61 | eventQueue.add(event);
|
---|
62 | notify();
|
---|
63 | }
|
---|
64 |
|
---|
65 | public void addRemoteListener(RemoteListener listener) {
|
---|
66 | addRemoteListener(listener, null);
|
---|
67 | }
|
---|
68 |
|
---|
69 | public void addRemoteListener(RemoteListener listener, String profileName) {
|
---|
70 | listeners.put(listener, profileName);
|
---|
71 | logger.fine("RemoteListener added: " + listener + " profile: " + profileName);
|
---|
72 | }
|
---|
73 |
|
---|
74 | public void removeRemoteListener(RemoteListener listener) {
|
---|
75 | if(listeners.remove(listener) != null) logger.fine("RemoteListener removed: " + listener);
|
---|
76 | }
|
---|
77 |
|
---|
78 | private Map getConnectors(String[] profiles) {
|
---|
79 | if(profiles == null) return new HashMap(config.getConnManager().getConnectors());
|
---|
80 | else {
|
---|
81 | Map connectors = new HashMap();
|
---|
82 | for(int i = 0; i < profiles.length; i++) {
|
---|
83 | if(profileExists(profiles[i]))
|
---|
84 | connectors.putAll(config.getConnManager().getConnectors(profiles[i]));
|
---|
85 | }
|
---|
86 | return connectors;
|
---|
87 | }
|
---|
88 | }
|
---|
89 |
|
---|
90 | private List getSessions(String[] profiles, boolean activeOnly) {
|
---|
91 | if(profiles == null) return activeOnly?sm.getActiveSessions():sm.getSessions();
|
---|
92 | else {
|
---|
93 | List sessions = new ArrayList();
|
---|
94 | for(int i = 0; i < profiles.length; i++) {
|
---|
95 | if(profileExists(profiles[i]))
|
---|
96 | sessions.addAll(activeOnly?sm.getActiveSessions(profiles[i]):sm.getSessions(profiles[i]));
|
---|
97 | }
|
---|
98 | return sessions;
|
---|
99 | }
|
---|
100 | }
|
---|
101 |
|
---|
102 | private List getSeenData(String[] profiles, boolean failures) {
|
---|
103 | if(failures) return sm.getFailData(); // not per profile
|
---|
104 | if(profiles == null) return sm.getSeenData(null);
|
---|
105 | else {
|
---|
106 | List entries = new ArrayList();
|
---|
107 | for(int i = 0; i < profiles.length; i++) {
|
---|
108 | if(profileExists(profiles[i]))
|
---|
109 | entries.addAll(sm.getSeenData(profiles[i]));
|
---|
110 | }
|
---|
111 | return entries;
|
---|
112 | }
|
---|
113 | }
|
---|
114 |
|
---|
115 | public int getCwsCount(String[] profiles) {
|
---|
116 | return getConnectors(profiles).size();
|
---|
117 | }
|
---|
118 |
|
---|
119 | public int getSessionCount(String[] profiles, boolean activeOnly) {
|
---|
120 | if(profiles == null) return activeOnly?sm.getActiveSessions().size():sm.getSessionCount();
|
---|
121 | else {
|
---|
122 | int count = 0;
|
---|
123 | if(activeOnly) return getSessions(profiles, true).size();
|
---|
124 | else for(int i = 0; i < profiles.length; i++) {
|
---|
125 | if(profileExists(profiles[i]))
|
---|
126 | count += sm.getSessionCount(profiles[i]);
|
---|
127 | }
|
---|
128 | return count;
|
---|
129 | }
|
---|
130 | }
|
---|
131 |
|
---|
132 | public int getCwsCapacity(String[] profiles) throws RemoteException {
|
---|
133 | Map connectors = getConnectors(profiles);
|
---|
134 | int total = 0;
|
---|
135 | CwsConnector cws;
|
---|
136 | for(Iterator iter = connectors.values().iterator(); iter.hasNext(); ) {
|
---|
137 | cws = (CwsConnector)iter.next();
|
---|
138 | if(cws.getCapacity() != -1) total += cws.getCapacity();
|
---|
139 | }
|
---|
140 | return total;
|
---|
141 | }
|
---|
142 |
|
---|
143 | public long getProxyStartTime() {
|
---|
144 | return proxy.getStartTime();
|
---|
145 | }
|
---|
146 |
|
---|
147 | public CwsStatus getCwsStatus(String name) {
|
---|
148 | CwsConnector cws = config.getConnManager().getCwsConnectorByName(name);
|
---|
149 | if(cws == null) return null;
|
---|
150 | else return new CwsStatus(cws);
|
---|
151 | }
|
---|
152 |
|
---|
153 | public CwsStatus[] getMultiCwsStatus(String[] profiles) {
|
---|
154 | Map connectors = getConnectors(profiles);
|
---|
155 | CwsStatus[] result = new CwsStatus[connectors.size()];
|
---|
156 | CwsConnector cws; int i = 0;
|
---|
157 | for(Iterator iter = connectors.values().iterator(); iter.hasNext(); ) {
|
---|
158 | cws = (CwsConnector)iter.next();
|
---|
159 | result[i++] = new CwsStatus(cws);
|
---|
160 | }
|
---|
161 | return result;
|
---|
162 | }
|
---|
163 |
|
---|
164 | public UserStatus[] getUsersStatus(String[] profiles, boolean activeOnly) {
|
---|
165 | UserManager um = config.getUserManager();
|
---|
166 | List sessions = getSessions(profiles, activeOnly);
|
---|
167 | Map users = new TreeMap();
|
---|
168 | ProxySession session; UserStatus user;
|
---|
169 | for(Iterator iter = sessions.iterator(); iter.hasNext(); ) {
|
---|
170 | session = (ProxySession)iter.next();
|
---|
171 | String name = session.getUser();
|
---|
172 | if(users.containsKey(name)) {
|
---|
173 | user = (UserStatus)users.get(name);
|
---|
174 | user.addSession(session);
|
---|
175 | } else {
|
---|
176 | String displayName = session.isTempUser()?session.getLoginName():um.getDisplayName(name);
|
---|
177 | user = new UserStatus(name, displayName, um.getStartDate(name), um.getExpireDate(name), um.getMaxConnections(name), false);
|
---|
178 | user.addSession(session);
|
---|
179 | users.put(name, user);
|
---|
180 | }
|
---|
181 | }
|
---|
182 | return (UserStatus[])users.values().toArray(new UserStatus[users.size()]);
|
---|
183 | }
|
---|
184 |
|
---|
185 | public SeenEntry[] getSeenUsers(String[] profiles, String userName, boolean failures) throws RemoteException {
|
---|
186 | List entries = getSeenData(profiles, failures);
|
---|
187 | if(userName != null) {
|
---|
188 | SeenEntry se;
|
---|
189 | for(Iterator iter = entries.iterator(); iter.hasNext(); ) {
|
---|
190 | se = (SeenEntry)iter.next();
|
---|
191 | if(!se.getName().equalsIgnoreCase(userName)) iter.remove();
|
---|
192 | }
|
---|
193 | }
|
---|
194 | Collections.sort(entries);
|
---|
195 | return (SeenEntry[])entries.toArray(new SeenEntry[entries.size()]);
|
---|
196 | }
|
---|
197 |
|
---|
198 | public UserStatus getUserStatus(String userName, boolean activeOnly) {
|
---|
199 | UserManager um = config.getUserManager();
|
---|
200 | List sessions = getSessions(null, activeOnly);
|
---|
201 | ProxySession session; UserStatus user = null;
|
---|
202 | for(Iterator iter = sessions.iterator(); iter.hasNext(); ) {
|
---|
203 | session = (ProxySession)iter.next();
|
---|
204 | if(userName.equalsIgnoreCase(session.getUser())) {
|
---|
205 | if(user == null) {
|
---|
206 | String displayName = session.isTempUser()?session.getLoginName():um.getDisplayName(userName);
|
---|
207 | user = new UserStatus(userName, displayName,um.getStartDate(userName),um.getExpireDate(userName), um.getMaxConnections(userName), um.isAdmin(userName));
|
---|
208 | }
|
---|
209 | user.addSession(session);
|
---|
210 | }
|
---|
211 | }
|
---|
212 | return user;
|
---|
213 | }
|
---|
214 |
|
---|
215 | private boolean profileExists(String profileName) {
|
---|
216 | return config.getProfile(profileName) != null;
|
---|
217 | }
|
---|
218 |
|
---|
219 | public String getUserPasswd(String userName) {
|
---|
220 | return config.getUserManager().getPassword(userName);
|
---|
221 | }
|
---|
222 |
|
---|
223 | public ProfileStatus[] getUserProfiles(String userName) throws RemoteException {
|
---|
224 | Set profiles = config.getUserManager().getAllowedProfiles(userName);
|
---|
225 | if(profiles.isEmpty()) return getProfiles();
|
---|
226 | else {
|
---|
227 | List ps = new ArrayList();
|
---|
228 | ps.add(new ProfileStatus(CaProfile.MULTIPLE));
|
---|
229 | CaProfile profile;
|
---|
230 | for(Iterator iter = profiles.iterator(); iter.hasNext(); ) {
|
---|
231 | profile = config.getProfile((String)iter.next());
|
---|
232 | if(profile != null) ps.add(new ProfileStatus(profile));
|
---|
233 | }
|
---|
234 | return (ProfileStatus[])ps.toArray(new ProfileStatus[ps.size()]);
|
---|
235 | }
|
---|
236 | }
|
---|
237 |
|
---|
238 | public boolean authenticateUser(String userName, String pass) {
|
---|
239 | return config.getUserManager() != null && config.getUserManager().authenticate(userName, pass);
|
---|
240 | }
|
---|
241 |
|
---|
242 | public boolean isAdmin(String userName) throws RemoteException {
|
---|
243 | return config.getUserManager().isAdmin(userName);
|
---|
244 | }
|
---|
245 |
|
---|
246 | public String getEmailAddress(String userName) {
|
---|
247 | return config.getUserManager().getEmailAddress(userName);
|
---|
248 | }
|
---|
249 |
|
---|
250 | public String[] getLocalUsers() {
|
---|
251 | return getLocalUsers(null);
|
---|
252 | }
|
---|
253 |
|
---|
254 | public String[] getLocalUsers(String profileName) {
|
---|
255 | String[] names = config.getUserManager().getUserNames();
|
---|
256 | if(profileName != null) {
|
---|
257 | List profileUsers = new ArrayList();
|
---|
258 | Set profiles;
|
---|
259 | for(int i = 0; i < names.length; i++) {
|
---|
260 | profiles = config.getUserManager().getAllowedProfiles(names[i]);
|
---|
261 | if(profiles == null || profiles.isEmpty()) profileUsers.add(names[i]);
|
---|
262 | else if(profiles.contains(profileName)) profileUsers.add(names[i]);
|
---|
263 | }
|
---|
264 | return (String[])profileUsers.toArray(new String[profileUsers.size()]);
|
---|
265 | } else return names;
|
---|
266 | }
|
---|
267 |
|
---|
268 | public TvService[] getServices(String name, boolean merge) {
|
---|
269 | List services = config.getConnManager().getServicesForConnector(name, true, false);
|
---|
270 | if(services == null) return null;
|
---|
271 | if(!merge) return (TvService[])services.toArray(new TvService[services.size()]);
|
---|
272 | else {
|
---|
273 | Map map = new HashMap(); TvService service;
|
---|
274 | for(Iterator iter = services.iterator(); iter.hasNext(); ) {
|
---|
275 | service = (TvService)iter.next();
|
---|
276 | map.put(new Integer(service.getId()), service);
|
---|
277 | }
|
---|
278 | return (TvService[])map.values().toArray(new TvService[map.size()]);
|
---|
279 | }
|
---|
280 | }
|
---|
281 |
|
---|
282 | public TvService[] getCannotDecodeServices(String name) {
|
---|
283 | List services = config.getConnManager().getServicesForConnector(name, false, false);
|
---|
284 | if(services == null) return null;
|
---|
285 | else return (TvService[])services.toArray(new TvService[services.size()]);
|
---|
286 | }
|
---|
287 |
|
---|
288 | public synchronized TvService[] getWatchedServices(String[] profiles) throws RemoteException {
|
---|
289 | List activeSessions = getSessions(profiles, true);
|
---|
290 | Set p = profiles==null?Collections.EMPTY_SET:new HashSet(Arrays.asList(profiles));
|
---|
291 | if(!p.contains(CaProfile.MULTIPLE.getName())) activeSessions.addAll(sm.getActiveSessions(CaProfile.MULTIPLE.getName()));
|
---|
292 | Map services = new TreeMap();
|
---|
293 | ProxySession session; TvService service;
|
---|
294 | for(Iterator iter = activeSessions.iterator(); iter.hasNext(); ) {
|
---|
295 | session = (ProxySession)iter.next();
|
---|
296 | service = session.getCurrentService();
|
---|
297 | if(service.getId() != -1) {
|
---|
298 | if(p.isEmpty() || p.contains(service.getProfileName()))
|
---|
299 | if(services.containsKey(service)) services.put(service, new Integer(((Integer)services.get(service)).intValue() + 1));
|
---|
300 | else services.put(service, new Integer(1));
|
---|
301 | }
|
---|
302 | }
|
---|
303 | TvService[] result = new TvService[services.size()];
|
---|
304 | Iterator iter = services.keySet().iterator();
|
---|
305 | for(int i = 0; i < result.length; i++) {
|
---|
306 | result[i] = (TvService)iter.next();
|
---|
307 | result[i].setWatchers(((Integer)services.get(result[i])).intValue());
|
---|
308 | }
|
---|
309 | return result;
|
---|
310 | }
|
---|
311 |
|
---|
312 | public ProfileStatus[] getProfiles() {
|
---|
313 | Collection profiles = config.getProfiles().values();
|
---|
314 | ProfileStatus[] ps = new ProfileStatus[profiles.size()]; int i = 0;
|
---|
315 | for(Iterator iter = profiles.iterator(); iter.hasNext(); )
|
---|
316 | ps[i++] = new ProfileStatus((CaProfile)iter.next());
|
---|
317 | return ps;
|
---|
318 | }
|
---|
319 |
|
---|
320 | public CacheStatus getCacheStatus() {
|
---|
321 | CacheHandler ch = config.getCacheHandler();
|
---|
322 | return new CacheStatus(ch.getClass().getName(), ch.getUsageStats());
|
---|
323 | }
|
---|
324 |
|
---|
325 | public PluginStatus[] getPlugins() throws RemoteException {
|
---|
326 | Map plugins = config.getProxyPlugins();
|
---|
327 | PluginStatus[] status = new PluginStatus[plugins.size()];
|
---|
328 | ProxyPlugin plugin; int i = 0;
|
---|
329 | for(Iterator iter = plugins.values().iterator(); iter.hasNext(); ) {
|
---|
330 | plugin = (ProxyPlugin)iter.next();
|
---|
331 | status[i++] = new PluginStatus(plugin);
|
---|
332 | }
|
---|
333 | return status;
|
---|
334 | }
|
---|
335 |
|
---|
336 | public boolean resetStatus(String profileName, int serviceId, long customData) {
|
---|
337 | if(profileExists(profileName)) {
|
---|
338 | ServiceMapping sm = new ServiceMapping(serviceId, customData);
|
---|
339 | if(!config.getConnManager().resetStatus(profileName, sm)) {
|
---|
340 | if(customData <= 0) {
|
---|
341 | sm.setProviderIdent(ServiceMapping.NO_PROVIDER);
|
---|
342 | return config.getConnManager().resetStatus(profileName, sm);
|
---|
343 | } else return false;
|
---|
344 | } else return true;
|
---|
345 | }
|
---|
346 | else return false;
|
---|
347 | }
|
---|
348 |
|
---|
349 | public int resetStatus(String cwsName, boolean full) {
|
---|
350 | return config.getConnManager().resetStatus(cwsName, full);
|
---|
351 | }
|
---|
352 |
|
---|
353 | public int kickUser(String userName) {
|
---|
354 | List sessions = sm.getSessions();
|
---|
355 | ProxySession session; int count = 0;
|
---|
356 | for(Iterator iter = sessions.iterator(); iter.hasNext(); ) {
|
---|
357 | session = (ProxySession)iter.next();
|
---|
358 | if(userName.equalsIgnoreCase(session.getUser())) {
|
---|
359 | logger.info("Closing session, user kicked: " + session);
|
---|
360 | session.close();
|
---|
361 | count++;
|
---|
362 | }
|
---|
363 | }
|
---|
364 | return count;
|
---|
365 | }
|
---|
366 |
|
---|
367 | public void shutdown() {
|
---|
368 | logger.warning("Remote shutdown requested, stopping proxy in 3 secs...");
|
---|
369 | new Thread("RemoteShutdownThread") {
|
---|
370 | public void run() {
|
---|
371 | try {
|
---|
372 | config.getConnManager().saveServiceMaps();
|
---|
373 | Thread.sleep(3000);
|
---|
374 | System.exit(0);
|
---|
375 | } catch(InterruptedException e) {
|
---|
376 | e.printStackTrace();
|
---|
377 | }
|
---|
378 | }
|
---|
379 | }.start();
|
---|
380 | }
|
---|
381 |
|
---|
382 | public int sendOsdMessage(String userName, String message) {
|
---|
383 | List activeSessions = getSessions(null, true);
|
---|
384 | ProxySession session; int count = 0;
|
---|
385 |
|
---|
386 | if(userName == null) logger.info("Sending newcamd OSD message to all eligible active sessions...");
|
---|
387 | else logger.info("Sending newcamd OSD message to all eligible sessions for user '" + userName + "'...");
|
---|
388 |
|
---|
389 | for(Iterator iter = activeSessions.iterator(); iter.hasNext(); ) {
|
---|
390 | session = (ProxySession)iter.next();
|
---|
391 | if(session instanceof NewcamdSession) {
|
---|
392 | if(userName != null) {
|
---|
393 | if(userName.equalsIgnoreCase(session.getUser()))
|
---|
394 | if(((NewcamdSession)session).sendOsdMessage(message)) count++;
|
---|
395 | } else if(((NewcamdSession)session).sendOsdMessage(message)) count++;
|
---|
396 | }
|
---|
397 | }
|
---|
398 |
|
---|
399 | logger.info("Newcamd OSD message sucessfully sent to " + count + " sessions.");
|
---|
400 |
|
---|
401 | return count;
|
---|
402 | }
|
---|
403 |
|
---|
404 | public void retryConnector(String cwsName) throws RemoteException {
|
---|
405 | CwsConnector conn = (CwsConnector)config.getConnManager().getConnectors().get(cwsName);
|
---|
406 |
|
---|
407 | conn.close();
|
---|
408 | conn.setEnabled(true);
|
---|
409 | }
|
---|
410 |
|
---|
411 | public void disableConnector(String cwsName) throws RemoteException {
|
---|
412 | CwsConnector conn = (CwsConnector)config.getConnManager().getConnectors().get(cwsName);
|
---|
413 |
|
---|
414 | conn.setEnabled(false);
|
---|
415 | conn.close();
|
---|
416 | }
|
---|
417 |
|
---|
418 | public void setConnectorMetric(String cwsName, int metric) throws RemoteException {
|
---|
419 | CwsConnector conn = (CwsConnector)config.getConnManager().getConnectors().get(cwsName);
|
---|
420 |
|
---|
421 | conn.setMetric(metric);
|
---|
422 | }
|
---|
423 |
|
---|
424 | public boolean setAuUser(String cwsName, String user) throws RemoteException {
|
---|
425 | return config.getConnManager().setTempAuUser(cwsName, user);
|
---|
426 | }
|
---|
427 |
|
---|
428 | public void setProfileDebug(boolean debug, String profileName) throws RemoteException {
|
---|
429 | CaProfile profile;
|
---|
430 | if(profileName != null) {
|
---|
431 | profile = config.getProfile(profileName);
|
---|
432 | profile.setDebug(debug);
|
---|
433 | } else {
|
---|
434 | for(Iterator iter = config.getProfiles().values().iterator(); iter.hasNext(); ) {
|
---|
435 | profile = (CaProfile)iter.next();
|
---|
436 | profile.setDebug(debug);
|
---|
437 | }
|
---|
438 | }
|
---|
439 | }
|
---|
440 |
|
---|
441 | public boolean setUserDebug(boolean debug, String userName) throws RemoteException {
|
---|
442 | UserManager um = config.getUserManager();
|
---|
443 | if(!um.exists(userName)) return false;
|
---|
444 | um.setDebug(userName, debug);
|
---|
445 | return true;
|
---|
446 | }
|
---|
447 |
|
---|
448 | public void setName(String name) {
|
---|
449 | this.name = name;
|
---|
450 | }
|
---|
451 |
|
---|
452 | public String getName() {
|
---|
453 | return name;
|
---|
454 | }
|
---|
455 |
|
---|
456 | public int[] getCounters() {
|
---|
457 | return new int[] {
|
---|
458 | proxy.getEcmCount(), proxy.getEcmForwards(), proxy.getEcmCacheHits(), proxy.getEcmFailures(), proxy.getEmmCount(),
|
---|
459 | proxy.getEcmDenied(), proxy.getEcmFiltered(), proxy.getEcmRate(), proxy.getProbeQueue()
|
---|
460 | };
|
---|
461 | }
|
---|
462 |
|
---|
463 | public int removeSeenUser(String name) throws RemoteException {
|
---|
464 | return SessionManager.getInstance().removeSeenUser(name);
|
---|
465 | }
|
---|
466 |
|
---|
467 | public int removeLoginFailure(String mask) throws RemoteException {
|
---|
468 | return SessionManager.getInstance().removeLoginFailure(mask);
|
---|
469 | }
|
---|
470 |
|
---|
471 | public void userStatusChanged(String userName, TvService service, String profile, String sessionId) {
|
---|
472 | if(service != null) {
|
---|
473 | RemoteEvent re = new RemoteEvent(RemoteEvent.USER_STATUS_CHANGED, userName, service.getName(), profile);
|
---|
474 | re.setProperty("service", service.getName() + " (" + profile + ":" + Integer.toHexString(service.getId()) + ")");
|
---|
475 | re.setProperty("sid", Integer.toHexString(service.getId()));
|
---|
476 | re.setProperty("id", sessionId);
|
---|
477 | fireRemoteEvent(re);
|
---|
478 | }
|
---|
479 | }
|
---|
480 |
|
---|
481 | public void userLogin(String userName, String profile, String ip, String sessionId) {
|
---|
482 | RemoteEvent re = new RemoteEvent(RemoteEvent.USER_LOGIN, userName, ip, profile);
|
---|
483 | re.setProperty("ip-address", ip);
|
---|
484 | re.setProperty("id", sessionId);
|
---|
485 | fireRemoteEvent(re);
|
---|
486 | }
|
---|
487 |
|
---|
488 | public void userLogout(String userName, String profile, String sessionId) {
|
---|
489 | RemoteEvent re = new RemoteEvent(RemoteEvent.USER_LOGOUT, userName, null, profile);
|
---|
490 | re.setProperty("id", sessionId);
|
---|
491 | fireRemoteEvent(re);
|
---|
492 | }
|
---|
493 |
|
---|
494 | public void userLoginFailed(String userName, String profile, String ip, String reason) {
|
---|
495 | RemoteEvent re = new RemoteEvent(RemoteEvent.USER_LOGINFAIL, userName, reason, profile);
|
---|
496 | re.setProperty("ip-address", ip);
|
---|
497 | fireRemoteEvent(re);
|
---|
498 | }
|
---|
499 |
|
---|
500 | public void cwsConnected(CwsConnector cws) {
|
---|
501 | fireRemoteEvent(new RemoteEvent(RemoteEvent.CWS_CONNECTED, cws.getLabel(), cws.toString(), cws.getProfileName()));
|
---|
502 | }
|
---|
503 |
|
---|
504 | public void cwsDisconnected(CwsConnector cws) {
|
---|
505 | fireRemoteEvent(new RemoteEvent(RemoteEvent.CWS_DISCONNECTED, cws.getLabel(), cws.toString(), cws.getProfileName()));
|
---|
506 | }
|
---|
507 |
|
---|
508 | public void cwsConnectionFailed(CwsConnector cws, String message) {
|
---|
509 | fireRemoteEvent(new RemoteEvent(RemoteEvent.CWS_CONNECTION_FAILED, cws.getLabel(), message, cws.getProfileName()));
|
---|
510 | }
|
---|
511 |
|
---|
512 | public void cwsEcmTimeout(CwsConnector cws, String message, int failureCount) {
|
---|
513 | if(failureCount >= config.getEtMinCount())
|
---|
514 | fireRemoteEvent(new RemoteEvent(RemoteEvent.CWS_WARNING, cws.getLabel(), message, cws.getProfileName()));
|
---|
515 | }
|
---|
516 |
|
---|
517 | public void cwsLostService(CwsConnector cws, TvService service, boolean show) {
|
---|
518 | if(service != null && show)
|
---|
519 | fireRemoteEvent(new RemoteEvent(RemoteEvent.CWS_LOST_SERVICE, cws.getLabel(), service.toString(), service.getProfileName()));
|
---|
520 | }
|
---|
521 |
|
---|
522 | public void cwsFoundService(CwsConnector cws, TvService service, boolean show) {
|
---|
523 | if(service != null && show) {
|
---|
524 | String label = cws==null?"Internal[SidCacheLinker]":cws.getLabel();
|
---|
525 | fireRemoteEvent(new RemoteEvent(RemoteEvent.CWS_FOUND_SERVICE, label, service.toString(), service.getProfileName()));
|
---|
526 | }
|
---|
527 | }
|
---|
528 |
|
---|
529 | public void cwsInvalidCard(CwsConnector cws, String message) {
|
---|
530 | fireRemoteEvent(new RemoteEvent(RemoteEvent.CWS_INVALID_CARD, cws.getLabel(), message, cws.getProfileName()));
|
---|
531 | }
|
---|
532 |
|
---|
533 | public void cwsProfileChanged(CaProfile profile, boolean added) {
|
---|
534 | // ignore for now - todo
|
---|
535 | }
|
---|
536 |
|
---|
537 | public void transactionCompleted(EcmTransaction transaction, ProxySession session) {
|
---|
538 | RemoteEvent re = new RemoteEvent(RemoteEvent.ECM_TRANSACTION, session.getLabel(), session.getUser(),
|
---|
539 | session.getProfileName());
|
---|
540 | String cw = transaction.getReplyData();
|
---|
541 | int sid = transaction.getServiceId();
|
---|
542 | re.setProperty("id", SessionManager.getSessionIdStr(session));
|
---|
543 | re.setProperty("request-hash", transaction.getRequest().hashCodeStr());
|
---|
544 | re.setProperty("ecm-size", String.valueOf(transaction.getRequest().getDataLength()));
|
---|
545 | if(cw != null && cw.length() > 0) re.setProperty("cw", cw);
|
---|
546 | re.setProperty("timestamp", String.valueOf(transaction.getReadTime()));
|
---|
547 | re.setProperty("time", String.valueOf(transaction.getDuration()));
|
---|
548 | re.setProperty("flags", transaction.getFlags());
|
---|
549 | re.setProperty("filtered-by", transaction.getFilteredBy());
|
---|
550 | re.setProperty("service", transaction.getService().getName() + " (" + transaction.getService().getProfileName() +
|
---|
551 | ":" + Integer.toHexString(sid) + ")");
|
---|
552 | re.setProperty("sid", Integer.toHexString(sid));
|
---|
553 | if(transaction.getReplyServiceId() != -1 && transaction.getReplyServiceId() != sid)
|
---|
554 | re.setProperty("reply-sid", Integer.toHexString(transaction.getReplyServiceId()));
|
---|
555 | if(transaction.getConnectorName() != null) re.setProperty("cws-name", transaction.getConnectorName());
|
---|
556 |
|
---|
557 | int pi = transaction.getRequest().getProviderIdent();
|
---|
558 | if(pi != -1) re.setProperty("provider-ident", DESUtil.intToByteString(pi, 3));
|
---|
559 |
|
---|
560 | if(session.getProfile() == CaProfile.MULTIPLE) {
|
---|
561 | re.setProperty("ca-id", DESUtil.intToHexString(transaction.getRequest().getCaId(), 4));
|
---|
562 | re.setProperty("network-id", DESUtil.intToHexString(transaction.getRequest().getNetworkId(), 4));
|
---|
563 | }
|
---|
564 | if(session instanceof CspSession) re.setProperty("origin-id", Integer.toHexString(transaction.getRequest().getOriginId()));
|
---|
565 |
|
---|
566 | if("Newcamd".equals(transaction.getRequest().getProtocol())) {
|
---|
567 | StringBuffer unknown = new StringBuffer(">");
|
---|
568 | unknown.append(DESUtil.bytesToString(transaction.getRequest().getFixedData(), 4, 6));
|
---|
569 | unknown.append(" (").append(transaction.getRequest().getUpperBits() >> 4).append(")");
|
---|
570 | if("Newcamd".equals(transaction.getReply().getProtocol())) {
|
---|
571 | unknown.append(" <").append(DESUtil.bytesToString(transaction.getReply().getFixedData(), 4, 6));
|
---|
572 | unknown.append(" (").append(transaction.getReply().getUpperBits() >> 4).append(")");
|
---|
573 | }
|
---|
574 | re.setProperty("ext-newcamd", unknown.toString());
|
---|
575 | }
|
---|
576 |
|
---|
577 | boolean warning = config.isTransactionWarning(transaction.getFlags(), transaction.getDuration());
|
---|
578 | re.setProperty("warning", String.valueOf(warning));
|
---|
579 | if(warning) re.setProperties(transaction.getTimings());
|
---|
580 |
|
---|
581 | fireRemoteEvent(re);
|
---|
582 | }
|
---|
583 |
|
---|
584 | public void onLog(Level l, String label, String message) {
|
---|
585 | if(l == Level.SEVERE || l == Level.WARNING) {
|
---|
586 | if(config.isIncludeFileEvents()) {
|
---|
587 | RemoteEvent re = new RemoteEvent(RemoteEvent.LOG_EVENT, label, message, null);
|
---|
588 | re.setProperty("log-level", l.getName());
|
---|
589 | fireRemoteEvent(re);
|
---|
590 | }
|
---|
591 | }
|
---|
592 | }
|
---|
593 |
|
---|
594 | public synchronized void destroy() {
|
---|
595 | eventQueue.clear();
|
---|
596 | listeners.clear();
|
---|
597 | sm.removeUserStatusListener(this);
|
---|
598 | config.getConnManager().removeCwsListener(this);
|
---|
599 | eventThread = null;
|
---|
600 | notify();
|
---|
601 | }
|
---|
602 |
|
---|
603 | public void run() {
|
---|
604 |
|
---|
605 | while(Thread.currentThread() == eventThread) {
|
---|
606 | synchronized(this) {
|
---|
607 | try {
|
---|
608 | wait();
|
---|
609 | } catch(InterruptedException e) {
|
---|
610 | eventQueue.clear();
|
---|
611 | break;
|
---|
612 | }
|
---|
613 | }
|
---|
614 |
|
---|
615 | while(!eventQueue.isEmpty()) {
|
---|
616 | RemoteEvent event = (RemoteEvent)eventQueue.remove(0);
|
---|
617 | logger.finer("Firing remote event: " + event + " " + listeners);
|
---|
618 | RemoteListener listener;
|
---|
619 | for(Iterator iter = new ArrayList(listeners.keySet()).iterator(); iter.hasNext(); ) {
|
---|
620 | listener = (RemoteListener)iter.next();
|
---|
621 | try {
|
---|
622 | if(listeners.get(listener) == null || listeners.get(listener).equals(event.getProfile()))
|
---|
623 | listener.eventRaised(event);
|
---|
624 | } catch(RuntimeException e) {
|
---|
625 | logger.warning("Exception in remote event handling: " + e);
|
---|
626 | logger.throwing(e);
|
---|
627 | e.printStackTrace();
|
---|
628 | } catch(RemoteException e) {
|
---|
629 | logger.warning("Exception in remote event handling: " + e.getCause());
|
---|
630 | logger.throwing(e);
|
---|
631 | listeners.remove(listener);
|
---|
632 | } catch(Exception e) {
|
---|
633 | logger.severe("Exception in remote event handling: " + e, e);
|
---|
634 | listeners.remove(listener);
|
---|
635 | }
|
---|
636 | }
|
---|
637 | }
|
---|
638 |
|
---|
639 | }
|
---|
640 |
|
---|
641 | }
|
---|
642 |
|
---|
643 | }
|
---|