use of de.janrufmonitor.framework.IMsn in project janrufmonitor by tbrandt77.
the class IncomingCall method handleWithException.
public void handleWithException(IHttpRequest req, IMutableHttpResponse resp) throws HandlerException {
IPhonenumber pn = null;
try {
String phone = req.getParameter(IncomingCall.PARAMETER_NUMBER);
if (phone == null || phone.length() == 0)
pn = PIMRuntime.getInstance().getCallerFactory().createPhonenumber(true);
else
pn = PIMRuntime.getInstance().getCallerFactory().createPhonenumber(phone);
IName name = PIMRuntime.getInstance().getCallerFactory().createName("", "");
ICaller c = PIMRuntime.getInstance().getCallerFactory().createCaller(name, pn);
ICip cip = PIMRuntime.getInstance().getCallFactory().createCip(req.getParameter(IncomingCall.PARAMETER_CIP), "");
IMsn msn = PIMRuntime.getInstance().getCallFactory().createMsn(req.getParameter(IncomingCall.PARAMETER_MSN), "");
Date date = new Date(Long.parseLong(req.getParameter(IncomingCall.PARAMETER_DATE)));
ICall call = PIMRuntime.getInstance().getCallFactory().createCall(c, msn, cip, date);
call.setAttribute(this.getRuntime().getCallFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_STARTRING, Long.toString(new Date().getTime())));
ClientCallMap.getInstance().setCall((pn.isClired() ? IJAMConst.CLIRED_CALL : pn.getTelephoneNumber()) + "/" + msn.getMSN(), call);
Thread sender = new Thread(new HandlerThread(call, this));
sender.start();
resp.getContentStreamForWrite().close();
} catch (Exception e) {
throw new HandlerException(e.getMessage(), 500);
}
}
use of de.janrufmonitor.framework.IMsn in project janrufmonitor by tbrandt77.
the class GetCallListCount method getAllowedMsnFilter.
private IFilter[] getAllowedMsnFilter(IHttpRequest req) throws HandlerException {
try {
boolean allowedForAllMsns = (SecurityManager.getInstance().getAllowedMSNs(req.getInetAddress().getHostName()) == null && SecurityManager.getInstance().getAllowedMSNs(req.getInetAddress().getHostAddress()) == null);
if (!allowedForAllMsns) {
String[] allowedMSNs = SecurityManager.getInstance().getAllowedMSNs(req.getInetAddress().getHostName());
if (allowedMSNs == null)
allowedMSNs = SecurityManager.getInstance().getAllowedMSNs(req.getInetAddress().getHostAddress());
if (allowedMSNs != null) {
IFilter[] allowedMsnFilter = new IFilter[allowedMSNs.length];
IMsn msn = null;
for (int i = 0; i < allowedMSNs.length; i++) {
msn = getRuntime().getMsnManager().createMsn(allowedMSNs[i]);
allowedMsnFilter[i] = new MsnFilter(msn);
m_logger.info("Adding allowed MSN filter for client: " + allowedMsnFilter[i].toString());
}
return allowedMsnFilter;
}
}
} catch (Exception e) {
m_logger.log(Level.SEVERE, e.getMessage(), e);
throw new HandlerException(e.getMessage(), 500);
}
return new IFilter[0];
}
use of de.janrufmonitor.framework.IMsn in project janrufmonitor by tbrandt77.
the class Server method sendRequest.
private synchronized void sendRequest(IEvent event, IHttpRequest request) {
List clients = ClientRegistry.getInstance().getAllClients();
Client c = null;
for (int i = 0; i < clients.size(); i++) {
c = (Client) clients.get(i);
Object call = event.getData();
if (call != null && call instanceof ICall) {
IMsn msn = ((ICall) call).getMSN();
if (!SecurityManager.getInstance().isAllowedForMSN(c.getClientIP(), msn.getMSN()) || !SecurityManager.getInstance().isAllowedForMSN(c.getClientName(), msn.getMSN())) {
this.m_logger.info("Client " + c + " is blocked for MSN " + msn.getMSN() + ".");
continue;
}
}
if (this.isEventClient(c.getEvents(), event.getType())) {
this.m_logger.info("Sending event #" + event + " to client " + c + ".");
try {
if (request.getContent() != null)
c.setByteReceived(request.getContent().length);
IRequester r = null;
if (c.getClientName().trim().length() > 0)
r = RequesterFactory.getInstance().getRequester(c.getClientName(), c.getClientPort());
else
r = RequesterFactory.getInstance().getRequester(c.getClientIP(), c.getClientPort());
r.setRequest(request);
Thread s = new Thread(new SenderThread(r));
s.setName("JAM-" + SenderThread.class.getName() + "#" + i + "-Thread-(non-deamon)");
s.start();
} catch (Exception e) {
this.m_logger.severe(e.getMessage());
}
}
}
}
use of de.janrufmonitor.framework.IMsn in project janrufmonitor by tbrandt77.
the class Serializer method toCall.
/**
* Deserializes a byte array stream into an call object.
*
* @param call call as a byte array representation.
* @param runtime runtime to used
* @return call object
* @throws SerializerException
*/
public static ICall toCall(byte[] call, IRuntime runtime) throws SerializerException {
if (runtime == null)
throw new SerializerException("Runtime object is not set but required.");
String callString = new String(call);
if (callString.indexOf(m_ctoken) < 0)
throw new SerializerException("Call format is invalid. Call is set <" + callString + ">");
// tokenize the whole input
StringTokenizer st = new StringTokenizer(callString, m_ctoken);
if (st.countTokens() != 2)
throw new SerializerException("Call format is invalid. Found " + st.countTokens() + " tokens, but required are exactly 2.");
ICaller caller = toCaller(st.nextToken().getBytes(), runtime);
if (!st.hasMoreTokens())
throw new SerializerException("Call format is invalid. Second token is empty.");
// tokenize to call data
callString = st.nextToken();
st = new StringTokenizer(callString, m_token);
if (st.countTokens() < 7)
throw new SerializerException("Call format is invalid. Token count < 7.");
// build MSN
IMsn msn = runtime.getCallFactory().createMsn(// token 1
decode(st.nextToken().trim()), // token 2
decode(st.nextToken().trim()));
if (msn.getMSN().equalsIgnoreCase("*")) {
msn.setMSN("0");
}
// build CIP
ICip cip = runtime.getCallFactory().createCip(// token 3
decode(st.nextToken().trim()), // token 4
decode(st.nextToken().trim()));
// token 5
String uuid = decode(st.nextToken().trim());
// token 6
Date date = new Date(Long.parseLong(decode(st.nextToken().trim())));
// build attributes
String attString = decode(st.nextToken().trim());
IAttributeMap attList = runtime.getCallFactory().createAttributeMap();
if (attString.length() > 0) {
StringTokenizer ast = new StringTokenizer(attString, m_atoken);
String attrib = null;
while (ast.hasMoreTokens()) {
attrib = ast.nextToken().trim();
if (attrib.indexOf(EQUAL) > -1) {
IAttribute att = runtime.getCallFactory().createAttribute(decode(attrib.substring(0, attrib.indexOf(EQUAL))), decodeAttributeValue(attrib.substring(attrib.indexOf(EQUAL) + EQUAL.length())));
attList.add(att);
}
}
}
return runtime.getCallFactory().createCall(uuid, caller, msn, cip, date, attList);
}
use of de.janrufmonitor.framework.IMsn in project janrufmonitor by tbrandt77.
the class XTapiCall method toCall.
public ICall toCall() {
if (this.m_call == null) {
IRuntime r = PIMRuntime.getInstance();
IPhonenumber phone = PhonenumberAnalyzer.getInstance(r).toClirPhonenumber(this.m_number);
if (phone == null)
phone = PhonenumberAnalyzer.getInstance(r).toInternalPhonenumber(this.m_number, this.m_msn);
if (phone == null)
phone = PhonenumberAnalyzer.getInstance(r).toPhonenumber(this.m_number, this.m_msn);
ICaller c = r.getCallerFactory().createCaller(phone);
IMsn msn = null;
if (this.m_msn == null) {
msn = r.getCallFactory().createMsn(getFestnetzAlias(), "");
} else {
msn = r.getCallFactory().createMsn(this.m_msn, "");
}
msn.setAdditional(r.getMsnManager().getMsnLabel(msn));
if (this.m_name != null && this.m_name.length() > 0) {
c.setName(r.getCallerFactory().createName("", this.m_name));
}
ICip cip = r.getCallFactory().createCip(getDefaultCip(), "");
cip.setAdditional(r.getCipManager().getCipLabel(cip, ""));
// create attributes
IAttributeMap am = r.getCallFactory().createAttributeMap();
am.add(r.getCallFactory().createAttribute("tapi.device", Integer.toString(this.m_device)));
am.add(r.getCallFactory().createAttribute("tapi.instance", Integer.toString(this.m_instance)));
am.add(r.getCallFactory().createAttribute("tapi.key", getKey(this.m_device, this.m_instance)));
am.add(r.getCallFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_CALLSTATUS, IJAMConst.ATTRIBUTE_VALUE_MISSED));
this.m_call = r.getCallFactory().createCall(c, msn, cip, new Date());
this.m_call.setAttributes(am);
}
return this.m_call;
}
Aggregations