1 | package com.bowman.cardserv.web;
|
---|
2 |
|
---|
3 | import com.bowman.cardserv.*;
|
---|
4 | import com.bowman.cardserv.interfaces.*;
|
---|
5 | import com.bowman.cardserv.session.GHttpSession;
|
---|
6 | import com.bowman.cardserv.util.*;
|
---|
7 | import com.bowman.httpd.*;
|
---|
8 |
|
---|
9 | import java.io.*;
|
---|
10 | import java.net.*;
|
---|
11 | import java.util.*;
|
---|
12 |
|
---|
13 | /**
|
---|
14 | * Created by IntelliJ IDEA.
|
---|
15 | * User: bowman
|
---|
16 | * Date: 2011-06-07
|
---|
17 | * Time: 22:03
|
---|
18 | */
|
---|
19 | public class GHttpBackend implements XmlConfigurable, HttpRequestListener {
|
---|
20 |
|
---|
21 | private static final int RECORD_SIZE = 28;
|
---|
22 |
|
---|
23 | protected static final String API_PREFIX = "/api";
|
---|
24 |
|
---|
25 | protected static final String API_CACHE_GET = API_PREFIX + "/c/";
|
---|
26 | protected static final String API_ECM_POST = API_PREFIX + "/e/";
|
---|
27 | protected static final String API_FEEDER_POST = API_PREFIX + "/f/";
|
---|
28 | protected static final String API_CAPMT = API_PREFIX + "/p/";
|
---|
29 |
|
---|
30 | private WebBackend parent;
|
---|
31 | private CacheHandler cache;
|
---|
32 | private ProxyConfig config;
|
---|
33 | private boolean enabled;
|
---|
34 | private int alternatePort;
|
---|
35 | private PseudoHttpd httpd;
|
---|
36 | private ProxyLogger ghttpdLogger;
|
---|
37 | private String accessPasswd, feederPasswd;
|
---|
38 |
|
---|
39 | private Map sessions = new HashMap();
|
---|
40 | private Map sessionsByUser = new HashMap();
|
---|
41 | private Map contexts = Collections.synchronizedMap(new LinkedHashMap());
|
---|
42 |
|
---|
43 | private StatusCommand contextsCmd;
|
---|
44 |
|
---|
45 | public GHttpBackend(WebBackend parent) {
|
---|
46 | this.parent = parent;
|
---|
47 | this.config = ProxyConfig.getInstance();
|
---|
48 | }
|
---|
49 |
|
---|
50 | public void configUpdated(ProxyXmlConfig xml) throws ConfigException {
|
---|
51 | if(xml == null) enabled = true;
|
---|
52 | else enabled = "true".equalsIgnoreCase(xml.getStringValue("enabled", "true"));
|
---|
53 |
|
---|
54 | if(enabled) {
|
---|
55 | if(xml == null) alternatePort = -1;
|
---|
56 | else {
|
---|
57 | try {
|
---|
58 | xml.getStringValue("alternate-port");
|
---|
59 | } catch (ConfigException e) {
|
---|
60 | alternatePort = -1;
|
---|
61 | if(httpd != null) {
|
---|
62 | httpd.stop();
|
---|
63 | httpd = null;
|
---|
64 | }
|
---|
65 | }
|
---|
66 | if(alternatePort != -1) {
|
---|
67 | InetAddress bindAddr = null; String bindIp = null;
|
---|
68 | try {
|
---|
69 | bindIp = xml.getStringValue("alternate-bind-ip");
|
---|
70 | bindAddr = InetAddress.getByName(bindIp);
|
---|
71 | } catch(ConfigException e) {
|
---|
72 | } catch(UnknownHostException e) {
|
---|
73 | throw new ConfigException(xml.getFullName(), "alternate-bind-ip", "Invalid ghttp bind-ip: " + bindIp);
|
---|
74 | }
|
---|
75 | alternatePort = xml.getPortValue("alternate-port");
|
---|
76 | if(alternatePort == parent.httpd.getListenPort())
|
---|
77 | throw new ConfigException(xml.getFullName(), "alternate-port", "Port in use: " + alternatePort);
|
---|
78 | if(httpd != null && httpd.getListenPort() != alternatePort) {
|
---|
79 | httpd.stop();
|
---|
80 | httpd = null;
|
---|
81 | }
|
---|
82 | if(httpd == null) httpd = new PseudoHttpd(alternatePort, bindAddr);
|
---|
83 | httpd.addHttpRequestListener(API_PREFIX + "/*", this);
|
---|
84 | httpd.setSilent(true);
|
---|
85 | httpd.setV11(true);
|
---|
86 | try {
|
---|
87 | httpd.start();
|
---|
88 | } catch (IOException e) {
|
---|
89 | httpd = null;
|
---|
90 | throw new ConfigException(xml.getFullName(), "Unable to start alternate httpd for ghttp: " + e, e);
|
---|
91 | }
|
---|
92 | }
|
---|
93 | }
|
---|
94 | if(xml == null) {
|
---|
95 | accessPasswd = null;
|
---|
96 | feederPasswd = null;
|
---|
97 | } else {
|
---|
98 | try {
|
---|
99 | accessPasswd = xml.getStringValue("open-access-password");
|
---|
100 | } catch (ConfigException e) {
|
---|
101 | accessPasswd = null;
|
---|
102 | }
|
---|
103 | try {
|
---|
104 | feederPasswd = xml.getStringValue("feeder-password");
|
---|
105 | } catch (ConfigException e) {
|
---|
106 | feederPasswd = null;
|
---|
107 | }
|
---|
108 |
|
---|
109 | if(feederPasswd != null && accessPasswd != null && accessPasswd.equals(feederPasswd))
|
---|
110 | throw new ConfigException(xml.getFullName(), "Passwords must be different.");
|
---|
111 |
|
---|
112 | if(httpd != null) {
|
---|
113 | String logFile = null; int count = 0; int limit = 0;
|
---|
114 | try {
|
---|
115 | ProxyXmlConfig logXml = xml.getSubConfig("log-file");
|
---|
116 | count = logXml.getIntValue("rotate-count");
|
---|
117 | if(count < 1) count = 0;
|
---|
118 | limit = logXml.getIntValue("rotate-max-size");
|
---|
119 | if(limit < 1) limit = 0;
|
---|
120 | } catch(ConfigException e) {}
|
---|
121 | try {
|
---|
122 | if(ghttpdLogger != null) ghttpdLogger.close();
|
---|
123 | logFile = xml.getFileValue("log-file", true);
|
---|
124 | if(count > 0 && limit > 0)
|
---|
125 | if(!new File(logFile).delete()) { /* ignore */ }
|
---|
126 | ghttpdLogger = ProxyLogger.getFileLogger("GHttpBackend", new File(logFile), "FINER", count, limit, true);
|
---|
127 | httpd.setLogger(ghttpdLogger.getWrappedLogger());
|
---|
128 | } catch(ConfigException e) {
|
---|
129 | httpd.setLogger(null);
|
---|
130 | } catch(IOException e) {
|
---|
131 | throw new ConfigException(xml.getSubConfig("log-file").getFullName(), "Unable to assign log-file: " + logFile, e);
|
---|
132 | }
|
---|
133 | }
|
---|
134 |
|
---|
135 | }
|
---|
136 |
|
---|
137 | if(contextsCmd == null) {
|
---|
138 | try {
|
---|
139 | contextsCmd = new StatusCommand("ca-contexts", "Show ca-contexts map", "List all known ca-contexts and associated ecm pids.", true);
|
---|
140 | contextsCmd.register(this);
|
---|
141 | } catch(NoSuchMethodException e) {
|
---|
142 | e.printStackTrace();
|
---|
143 | }
|
---|
144 | }
|
---|
145 |
|
---|
146 | } else {
|
---|
147 | if(httpd != null) {
|
---|
148 | httpd.stop();
|
---|
149 | httpd = null;
|
---|
150 | }
|
---|
151 | if(contextsCmd != null) {
|
---|
152 | contextsCmd.unregister();
|
---|
153 | contextsCmd = null;
|
---|
154 | }
|
---|
155 | }
|
---|
156 |
|
---|
157 | }
|
---|
158 |
|
---|
159 | public void runStatusCmdCaContexts(XmlStringBuffer xb, Map params) {
|
---|
160 | xb.appendElement("ca-contexts", "count", contexts.size());
|
---|
161 | String key; CaContext cc; EcmPid pid;
|
---|
162 | for(Iterator iter = new ArrayList(contexts.keySet()).iterator(); iter.hasNext();) {
|
---|
163 | key = (String)iter.next();
|
---|
164 | cc = (CaContext)contexts.get(key);
|
---|
165 | xb.appendElement("ca-context", "key", key);
|
---|
166 | xb.appendAttr("name-space", Long.toHexString(cc.nameSpace));
|
---|
167 | if(!cc.ecmPids.isEmpty()) {
|
---|
168 | xb.appendAttr("pids", cc.ecmPids.size());
|
---|
169 | xb.endElement(false);
|
---|
170 | for(Iterator i = cc.iterator(); i.hasNext(); ) {
|
---|
171 | pid = (EcmPid)i.next();
|
---|
172 | xb.appendElement("ecm-pid", "pid", Integer.toHexString(pid.pid));
|
---|
173 | xb.appendAttr("caid", Integer.toHexString(pid.caId));
|
---|
174 | xb.appendAttr("provider-ident", Integer.toHexString(pid.provId));
|
---|
175 | if(!pid.lengths.isEmpty()) xb.appendAttr("lengths", pid.getLengths());
|
---|
176 | xb.closeElement();
|
---|
177 | }
|
---|
178 | xb.closeElement("ca-context");
|
---|
179 | } else xb.endElement(true);
|
---|
180 | }
|
---|
181 | xb.closeElement("ca-contexts");
|
---|
182 | }
|
---|
183 |
|
---|
184 | public boolean isEnabled() {
|
---|
185 | return enabled;
|
---|
186 | }
|
---|
187 |
|
---|
188 | public boolean hasAlternatePort() {
|
---|
189 | return httpd != null;
|
---|
190 | }
|
---|
191 |
|
---|
192 | private CamdNetMessage waitForReply(CamdNetMessage request) {
|
---|
193 | CamdNetMessage reply = cache.peekReply(request);
|
---|
194 | if(reply != null) return reply;
|
---|
195 | else reply = cache.processRequest(-1, request, true, request.getMaxWait() * 3); // todo
|
---|
196 | return reply;
|
---|
197 | }
|
---|
198 |
|
---|
199 | private String generateSessionId(String seed) {
|
---|
200 | String sessionId = Integer.toString(Math.abs(seed.hashCode()), Character.MAX_RADIX);
|
---|
201 | while(sessionId.length() < 6) sessionId = "0" + sessionId;
|
---|
202 | return sessionId;
|
---|
203 | }
|
---|
204 |
|
---|
205 | private GHttpSession newSession(String user, String ip) {
|
---|
206 | String id = generateSessionId(user + parent.createSession(user) + ip);
|
---|
207 | GHttpSession gs = new GHttpSession(id, user, ip);
|
---|
208 | sessions.put(id, gs);
|
---|
209 | if(!user.startsWith(WebBackend.anonPrefix)) sessionsByUser.put(user, gs);
|
---|
210 | return gs;
|
---|
211 | }
|
---|
212 |
|
---|
213 | private GHttpSession getSession(String id, String ip) {
|
---|
214 | GHttpSession gs = (GHttpSession)sessions.get(id);
|
---|
215 | if(gs != null && gs.isExpired()) {
|
---|
216 | sessionsByUser.remove(gs.getUser());
|
---|
217 | sessions.remove(id);
|
---|
218 | gs = null;
|
---|
219 | }
|
---|
220 | if(gs != null && ip.equals(gs.getRemoteAddress())) return gs;
|
---|
221 | else return null;
|
---|
222 | }
|
---|
223 |
|
---|
224 | private GHttpSession findSession(String user, String ip) {
|
---|
225 | GHttpSession gs = (GHttpSession)sessionsByUser.get(user);
|
---|
226 | if(gs != null && gs.isExpired()) {
|
---|
227 | sessionsByUser.remove(user);
|
---|
228 | sessions.remove(gs.getGhttpSessionId());
|
---|
229 | gs = null;
|
---|
230 | }
|
---|
231 | if(gs != null && ip.equals(gs.getRemoteAddress())) return gs;
|
---|
232 | else return null;
|
---|
233 | }
|
---|
234 |
|
---|
235 | private synchronized GHttpSession doGhttpAuth(HttpRequest req, String[] s) throws GHttpAuthException {
|
---|
236 | GHttpSession gs = null;
|
---|
237 | if(s[3].length() >= 6) { // session id included
|
---|
238 | gs = getSession(s[3], req.getRemoteAddress());
|
---|
239 | }
|
---|
240 | if(gs == null) { // no session id in query string (or invalid/expired session), check for auth
|
---|
241 | String user = parent.checkBasicAuth(req, accessPasswd);
|
---|
242 | if(user == null) throw new GHttpAuthException(getErrorResponse(401, "Authorization required"));
|
---|
243 | if(!user.startsWith(WebBackend.anonPrefix)) {
|
---|
244 | HttpResponse error = parent.doIpCheck(req, user);
|
---|
245 | if(error != null) throw new GHttpAuthException(getErrorResponse(403, "IP check failed"));
|
---|
246 | gs = findSession(user, req.getRemoteAddress()); // reuse when identified, one session per user
|
---|
247 | }
|
---|
248 | if(gs == null) gs = newSession(user, req.getRemoteAddress());
|
---|
249 | }
|
---|
250 | if(gs != null) gs.touch();
|
---|
251 | return gs;
|
---|
252 | }
|
---|
253 |
|
---|
254 | public HttpResponse doGet(String urlPattern, HttpRequest req) {
|
---|
255 | if(!enabled) return getErrorResponse(403, "Disabled");
|
---|
256 | else {
|
---|
257 | String q = req.getQueryString();
|
---|
258 | if(q.startsWith(API_CACHE_GET)) {
|
---|
259 | return doCacheGet(req);
|
---|
260 | } else if(q.startsWith(API_CAPMT)) {
|
---|
261 | return doPmtGetOrPost(req);
|
---|
262 | } else return HttpResponse.getErrorResponse(404);
|
---|
263 | }
|
---|
264 | }
|
---|
265 |
|
---|
266 | private HttpResponse doCacheGet(HttpRequest req) {
|
---|
267 | if(cache == null) cache = config.getCacheHandler();
|
---|
268 | try {
|
---|
269 | String[] s = req.getQueryString().split("/");
|
---|
270 | GHttpSession gs = doGhttpAuth(req, s);
|
---|
271 | if(gs == null) throw new GHttpAuthException(getErrorResponse(401, "Authorization required"));
|
---|
272 | CamdNetMessage request = CamdNetMessage.parseGHttpReq(s, req.getRemoteAddress(), null);
|
---|
273 | CamdNetMessage reply = waitForReply(request);
|
---|
274 | if(reply == null) reply = cache.peekReply(request);
|
---|
275 | HttpResponse res;
|
---|
276 | if(reply == null) {
|
---|
277 | res = getErrorResponse(503, "Cache timeout");
|
---|
278 | } else {
|
---|
279 | res = new HttpResponse(200, "OK", reply.getCustomData(), "application/octet-stream");
|
---|
280 | }
|
---|
281 | if(s.length < 6) res.setCookie("GSSID", gs.getGhttpSessionId());
|
---|
282 | return res;
|
---|
283 | } catch (GHttpAuthException e) {
|
---|
284 | return e.getResponse();
|
---|
285 | } catch (Exception e) {
|
---|
286 | parent.logger.throwing("Bad ghttp cache request: " + req.getQueryString(), e);
|
---|
287 | return HttpResponse.getErrorResponse(400, req.getQueryString());
|
---|
288 | }
|
---|
289 | }
|
---|
290 |
|
---|
291 | public HttpResponse doPost(String urlPattern, HttpRequest req) {
|
---|
292 | if(!enabled) return getErrorResponse(403, "Disabled");
|
---|
293 | else {
|
---|
294 | String q = req.getQueryString();
|
---|
295 | if(q.startsWith(API_ECM_POST)) {
|
---|
296 | return doEcmPost(req);
|
---|
297 | } else if(q.startsWith(API_CAPMT)) {
|
---|
298 | return doPmtGetOrPost(req);
|
---|
299 | } else if(q.startsWith(API_FEEDER_POST)) {
|
---|
300 | // todo
|
---|
301 | }
|
---|
302 | return getErrorResponse(503, "Not implemented"); // todo
|
---|
303 | }
|
---|
304 | }
|
---|
305 |
|
---|
306 | private HttpResponse doEcmPost(HttpRequest req) {
|
---|
307 | if(cache == null) cache = config.getCacheHandler();
|
---|
308 | try {
|
---|
309 | String[] s = req.getQueryString().split("/");
|
---|
310 | GHttpSession gs = doGhttpAuth(req, s);
|
---|
311 | if(gs == null) throw new GHttpAuthException(HttpResponse.getAuthReqResponse("GHttp"));
|
---|
312 | CamdNetMessage ecmReq = CamdNetMessage.parseGHttpReq(s, req.getRemoteAddress(), req.getContent());
|
---|
313 |
|
---|
314 | CamdNetMessage reply = cache.peekReply(ecmReq);
|
---|
315 | boolean instant = false;
|
---|
316 | if(reply == null) {
|
---|
317 | if(ProxyConfig.getInstance().getProfileById(ecmReq.getNetworkId(), ecmReq.getCaId()) == null)
|
---|
318 | return getErrorResponse(503, "Unknown system: " + CaProfile.getKeyStr(ecmReq.getNetworkId(), ecmReq.getCaId()));
|
---|
319 | gs.fireCamdMessage(ecmReq, false);
|
---|
320 | reply = gs.waitForReply(ecmReq);
|
---|
321 | } else instant = true;
|
---|
322 |
|
---|
323 | if(reply == null) cache.peekReply(ecmReq);
|
---|
324 | if(reply == null) return getErrorResponse(503, "Ecm timeout");
|
---|
325 | else {
|
---|
326 | CaContext cc = new CaContext(ecmReq.getNetworkId(), ecmReq.getTid(), ecmReq.getServiceId());
|
---|
327 | cc = (CaContext)contexts.get(cc.toString());
|
---|
328 | if(cc != null) cc.addLength(ecmReq.getPid(), ecmReq.getDataLength());
|
---|
329 | HttpResponse res = new HttpResponse(200, "OK", reply.getCustomData(), "application/octet-stream");
|
---|
330 | if(instant) res.setHeader("Pragma", "cached");
|
---|
331 | if(s.length < 10) res.setCookie("GSSID", gs.getGhttpSessionId());
|
---|
332 | return res;
|
---|
333 | }
|
---|
334 | } catch (GHttpAuthException e) {
|
---|
335 | return e.getResponse();
|
---|
336 | } catch (Exception e) {
|
---|
337 | parent.logger.throwing("Bad ghttp ecm request: " + req.getQueryString(), e);
|
---|
338 | return HttpResponse.getErrorResponse(400, req.getQueryString());
|
---|
339 | }
|
---|
340 | }
|
---|
341 |
|
---|
342 | private HttpResponse doPmtGetOrPost(HttpRequest req) {
|
---|
343 | try {
|
---|
344 | String[] s = req.getQueryString().split("/");
|
---|
345 | GHttpSession gs = doGhttpAuth(req, s);
|
---|
346 | if(gs == null) throw new GHttpAuthException(HttpResponse.getAuthReqResponse("GHttp"));
|
---|
347 | int offs = (s[3].length() >= 6)?4:3;
|
---|
348 |
|
---|
349 | CaContext cc = new CaContext();
|
---|
350 | cc.networkId = Integer.parseInt(s[offs++], 16);
|
---|
351 | cc.tsId = Integer.parseInt(s[offs++], 16);
|
---|
352 | cc.serviceId = Integer.parseInt(s[offs++], 16);
|
---|
353 | int pidCount = Integer.parseInt(s[offs++], 16);
|
---|
354 | cc.nameSpace = 0;
|
---|
355 | if(s.length > offs) cc.nameSpace = Long.parseLong(s[offs], 16);
|
---|
356 |
|
---|
357 | String key = cc.toString();
|
---|
358 | if(contexts.containsKey(key)) cc = (CaContext)contexts.get(key);
|
---|
359 | else contexts.put(key, cc);
|
---|
360 |
|
---|
361 | EcmPid pid;
|
---|
362 | if(pidCount > 0) {
|
---|
363 | if(!"POST".equalsIgnoreCase(req.getMethod()))
|
---|
364 | return HttpResponse.getErrorResponse(400, req.getQueryString() + " (expected post)");
|
---|
365 | DataInputStream dis = new DataInputStream(new ByteArrayInputStream(req.getContent()));
|
---|
366 | for(int i = 0; i < pidCount; i++) {
|
---|
367 | pid = new EcmPid();
|
---|
368 | pid.pid = dis.readUnsignedShort();
|
---|
369 | pid.caId = dis.readUnsignedShort();
|
---|
370 | pid.provId = dis.readInt();
|
---|
371 | cc.addPid(pid);
|
---|
372 | }
|
---|
373 | }
|
---|
374 |
|
---|
375 | ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
---|
376 | DataOutputStream daos = new DataOutputStream(baos);
|
---|
377 | for(Iterator iter = cc.iterator(); iter.hasNext();) {
|
---|
378 | pid = (EcmPid)iter.next();
|
---|
379 | if(config.getProfileById(cc.networkId, pid.caId) == null)
|
---|
380 | daos.writeShort(pid.pid);
|
---|
381 | }
|
---|
382 | HttpResponse res;
|
---|
383 | byte[] pids = baos.toByteArray();
|
---|
384 | if(pids.length == 0) res = new HttpResponse(204, "No Content");
|
---|
385 | else res = new HttpResponse(200, "OK", pids, "application/octet-stream");
|
---|
386 | if(s[3].length() < 6) res.setCookie("GSSID", gs.getGhttpSessionId());
|
---|
387 | res.setHeader("Pragma", "context-ignore=" + key);
|
---|
388 | return res;
|
---|
389 |
|
---|
390 | } catch (GHttpAuthException e) {
|
---|
391 | return e.getResponse();
|
---|
392 | } catch (Exception e) {
|
---|
393 | parent.logger.throwing("Bad ghttp pmt request: " + req.getQueryString(), e);
|
---|
394 | return HttpResponse.getErrorResponse(400, req.getQueryString());
|
---|
395 | }
|
---|
396 | }
|
---|
397 |
|
---|
398 | public HttpResponse doConnect(String urlPattern, HttpRequest req) {
|
---|
399 | return HttpResponse.getErrorResponse(405, req.getMethod());
|
---|
400 | }
|
---|
401 |
|
---|
402 | private HttpResponse getErrorResponse(int code, String msg) {
|
---|
403 | HttpResponse error = HttpResponse.getErrorResponse(code);
|
---|
404 | error.setContent(msg.getBytes(), "application/octet-stream");
|
---|
405 | return error;
|
---|
406 | }
|
---|
407 |
|
---|
408 | static class GHttpAuthException extends Exception {
|
---|
409 | HttpResponse response;
|
---|
410 |
|
---|
411 | GHttpAuthException(HttpResponse response) {
|
---|
412 | this.response = response;
|
---|
413 | }
|
---|
414 |
|
---|
415 | public HttpResponse getResponse() {
|
---|
416 | return response;
|
---|
417 | }
|
---|
418 | }
|
---|
419 |
|
---|
420 | static class CaContext {
|
---|
421 | int networkId, tsId, serviceId;
|
---|
422 | long nameSpace;
|
---|
423 |
|
---|
424 | CaContext() {}
|
---|
425 |
|
---|
426 | CaContext(int networkId, int tsId, int serviceId) {
|
---|
427 | this.networkId = networkId;
|
---|
428 | this.tsId = tsId;
|
---|
429 | this.serviceId = serviceId;
|
---|
430 | }
|
---|
431 |
|
---|
432 | private Map ecmPids = new LinkedHashMap();
|
---|
433 |
|
---|
434 | void addPid(EcmPid pid) {
|
---|
435 | ecmPids.put(String.valueOf(pid.pid), pid);
|
---|
436 | }
|
---|
437 |
|
---|
438 | void addLength(int pid, int len) {
|
---|
439 | EcmPid ecmPid = (EcmPid)ecmPids.get(String.valueOf(pid));
|
---|
440 | if(ecmPid != null) ecmPid.addLength(len);
|
---|
441 | }
|
---|
442 |
|
---|
443 | Iterator iterator() {
|
---|
444 | return ecmPids.values().iterator();
|
---|
445 | }
|
---|
446 |
|
---|
447 | public boolean equals(Object o) {
|
---|
448 | if(this == o) return true;
|
---|
449 | if(o == null || getClass() != o.getClass()) return false;
|
---|
450 | CaContext caContext = (CaContext)o;
|
---|
451 | // if(nameSpace != caContext.nameSpace) return false;
|
---|
452 | if(networkId != caContext.networkId) return false;
|
---|
453 | if(serviceId != caContext.serviceId) return false;
|
---|
454 | if(tsId != caContext.tsId) return false;
|
---|
455 | return true;
|
---|
456 | }
|
---|
457 |
|
---|
458 | public int hashCode() {
|
---|
459 | int result = networkId;
|
---|
460 | result = 31 * result + tsId;
|
---|
461 | result = 31 * result + serviceId;
|
---|
462 | // result = 31 * result + (int)(nameSpace ^ (nameSpace >>> 32));
|
---|
463 | return result;
|
---|
464 | }
|
---|
465 |
|
---|
466 | public String toString() {
|
---|
467 | StringBuffer sb = new StringBuffer();
|
---|
468 | sb.append(Integer.toHexString(networkId)).append('-');
|
---|
469 | sb.append(Integer.toHexString(tsId)).append('-');
|
---|
470 | sb.append(Integer.toHexString(serviceId));
|
---|
471 | // sb.append(Long.toHexString(nameSpace));
|
---|
472 | return sb.toString();
|
---|
473 | }
|
---|
474 | }
|
---|
475 |
|
---|
476 | static class EcmPid {
|
---|
477 | int pid, caId, provId;
|
---|
478 |
|
---|
479 | private Set lengths = new HashSet();
|
---|
480 |
|
---|
481 | void addLength(int len) {
|
---|
482 | lengths.add(new Integer(len));
|
---|
483 | }
|
---|
484 |
|
---|
485 | String getLengths() {
|
---|
486 | return lengths.toString();
|
---|
487 | }
|
---|
488 |
|
---|
489 | }
|
---|
490 | }
|
---|