aboutsummaryrefslogtreecommitdiff
path: root/src/com/wilko/jaim/flap
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/wilko/jaim/flap')
-rw-r--r--src/com/wilko/jaim/flap/FLAPDataFrame.java73
-rw-r--r--src/com/wilko/jaim/flap/FLAPErrorFrame.java51
-rw-r--r--src/com/wilko/jaim/flap/FLAPFrame.java109
-rw-r--r--src/com/wilko/jaim/flap/FLAPFrameException.java51
-rw-r--r--src/com/wilko/jaim/flap/FLAPFrameFactory.java68
-rw-r--r--src/com/wilko/jaim/flap/FLAPInputFrame.java69
-rw-r--r--src/com/wilko/jaim/flap/FLAPKeepAliveFrame.java55
-rw-r--r--src/com/wilko/jaim/flap/FLAPSignoffFrame.java52
-rw-r--r--src/com/wilko/jaim/flap/FLAPSignonFrame.java82
9 files changed, 610 insertions, 0 deletions
diff --git a/src/com/wilko/jaim/flap/FLAPDataFrame.java b/src/com/wilko/jaim/flap/FLAPDataFrame.java
new file mode 100644
index 0000000..78bea1f
--- /dev/null
+++ b/src/com/wilko/jaim/flap/FLAPDataFrame.java
@@ -0,0 +1,73 @@
+/*
+ * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+/*
+ * FlapDataFrame.java
+ *
+ * Created on 3 May 2002, 14:54
+ */
+
+package com.wilko.jaim.flap;
+
+/**
+ * @author paulw
+ * @version $Revision: 1.3 $
+ */
+public class FLAPDataFrame extends FLAPFrame {
+
+ private int frameLen;
+
+ /**
+ * Creates new FlapDataFrame
+ */
+ public FLAPDataFrame() {
+ frame[1] = FLAP_FRAME_DATA;
+ frameLen = 1;
+ frame[FLAP_DATA_OFFSET] = 0;
+ }
+
+ public FLAPDataFrame(byte[] frameData) {
+ frame[1] = FLAP_FRAME_DATA;
+ frameLen = 1;
+ frame[FLAP_DATA_OFFSET] = 0;
+ setFrameData(frameData);
+ }
+
+
+ public int getFLAPFrameType() {
+ return (FLAPFrame.FLAP_FRAME_DATA);
+ }
+
+ public void addString(String s) {
+ frameLen--; // Backspace over '0'
+ for (int i = 0; i < s.length(); i++) {
+ frame[FLAP_DATA_OFFSET + frameLen++] = (byte) s.charAt(i);
+ }
+ frame[FLAP_DATA_OFFSET + frameLen++] = 0;
+ setLength(frameLen);
+ }
+
+ public byte[] getContent() {
+ byte[] retarray = new byte[getLength()];
+
+ System.arraycopy(frame, FLAPFrame.FLAP_DATA_OFFSET, retarray, 0, getLength());
+ return (retarray);
+ }
+
+}
diff --git a/src/com/wilko/jaim/flap/FLAPErrorFrame.java b/src/com/wilko/jaim/flap/FLAPErrorFrame.java
new file mode 100644
index 0000000..4ac5c2d
--- /dev/null
+++ b/src/com/wilko/jaim/flap/FLAPErrorFrame.java
@@ -0,0 +1,51 @@
+/*
+ * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+/*
+ * FlapErrorFrame.java
+ *
+ * Created on 3 May 2002, 14:54
+ */
+
+package com.wilko.jaim.flap;
+
+/**
+ * @author paulw
+ * @version $Revision: 1.3 $
+ */
+public class FLAPErrorFrame extends FLAPFrame {
+
+ /**
+ * Creates new FLAPErrorFrame
+ */
+ public FLAPErrorFrame() {
+ frame[1] = FLAP_FRAME_ERROR;
+
+ }
+
+ public FLAPErrorFrame(byte[] frameData) {
+ frame[1] = FLAP_FRAME_ERROR;
+ setFrameData(frameData);
+ }
+
+
+ public int getFLAPFrameType() {
+ return FLAPFrame.FLAP_FRAME_ERROR;
+ }
+
+}
diff --git a/src/com/wilko/jaim/flap/FLAPFrame.java b/src/com/wilko/jaim/flap/FLAPFrame.java
new file mode 100644
index 0000000..2f4a4e2
--- /dev/null
+++ b/src/com/wilko/jaim/flap/FLAPFrame.java
@@ -0,0 +1,109 @@
+/*
+ * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+/*
+ * FLAPFrame.java
+ *
+ * Created on 3 May 2002, 14:51
+ */
+
+package com.wilko.jaim.flap;
+
+/**
+ * @author paulw
+ * @version $Revision: 1.4 $
+ */
+public abstract class FLAPFrame {
+
+ public static final int FLAP_FRAME_SIGNON = 1;
+ public static final int FLAP_FRAME_DATA = 2;
+ public static final int FLAP_FRAME_ERROR = 3;
+ public static final int FLAP_FRAME_SIGNOFF = 4;
+ public static final int FLAP_FRAME_KEEP_ALIVE = 5;
+ public static final int FLAP_DATA_OFFSET = 6;
+
+ protected byte[] frame;
+ protected int fLen;
+
+ /**
+ * Creates new FLAPFrame
+ */
+ public FLAPFrame() {
+ initialise();
+ }
+
+ protected void initialise() {
+ frame = new byte[8192];
+ frame[0] = (byte) '*';
+ frame[1] = 0;
+ frame[2] = 0;
+ frame[3] = 0;
+ frame[4] = 0;
+ frame[5] = 0;
+ fLen = 6;
+
+ }
+
+ public int getSequence() {
+ return ((frame[2] & 0xff) * 256 + (frame[3] & 0xff));
+ }
+
+ public void setSequence(int sequence) {
+ frame[2] = (byte) ((sequence / 256) & 0xff);
+ frame[3] = (byte) (sequence & 0xff);
+ }
+
+ public int getLength() {
+ return ((frame[4] & 0xff) * 256 + (frame[5] & 0xff));
+ }
+
+ public void setLength(int length) {
+ frame[4] = (byte) (length / 256);
+ frame[5] = (byte) (length & 0xff);
+ fLen = length + FLAP_DATA_OFFSET;
+ }
+
+ public byte[] getFrameData() {
+ byte[] b = new byte[fLen];
+ System.arraycopy(frame, 0, b, 0, fLen);
+ return (b);
+ }
+
+ protected void setFrameData(byte[] b) {
+ frame = new byte[b.length];
+ fLen = b.length;
+ System.arraycopy(b, 0, frame, 0, b.length);
+ }
+
+ public String toString() {
+ StringBuffer temp = new StringBuffer();
+ for (int i = 0; i < fLen; i++) {
+ int k = frame[i] & 0xff;
+ if (k < 16) {
+ temp.append("0" + Integer.toHexString(k) + " ");
+ } else {
+ temp.append(Integer.toHexString(k) + " ");
+ }
+ }
+ return (temp.toString());
+ }
+
+ public abstract int getFLAPFrameType();
+
+}
diff --git a/src/com/wilko/jaim/flap/FLAPFrameException.java b/src/com/wilko/jaim/flap/FLAPFrameException.java
new file mode 100644
index 0000000..6269c78
--- /dev/null
+++ b/src/com/wilko/jaim/flap/FLAPFrameException.java
@@ -0,0 +1,51 @@
+/*
+ * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+/*
+ * FLAPFrameException.java
+ *
+ * Created on 3 May 2002, 15:05
+ */
+
+package com.wilko.jaim.flap;
+
+/**
+ * @author paulw
+ * @version $Revision: 1.3 $
+ */
+public class FLAPFrameException extends java.lang.Exception {
+
+ /**
+ * Creates new <code>FLAPFrameException</code> without detail message.
+ */
+ public FLAPFrameException() {
+ }
+
+
+ /**
+ * Constructs an <code>FLAPFrameException</code> with the specified detail message.
+ *
+ * @param msg the detail message.
+ */
+ public FLAPFrameException(String msg) {
+ super(msg);
+ }
+}
+
+
diff --git a/src/com/wilko/jaim/flap/FLAPFrameFactory.java b/src/com/wilko/jaim/flap/FLAPFrameFactory.java
new file mode 100644
index 0000000..f6b864b
--- /dev/null
+++ b/src/com/wilko/jaim/flap/FLAPFrameFactory.java
@@ -0,0 +1,68 @@
+/*
+ * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+/*
+ * FLAPFrameFactory.java
+ *
+ * Created on 3 May 2002, 15:04
+ */
+
+package com.wilko.jaim.flap;
+
+/**
+ * @author paulw
+ * @version $Revision: 1.3 $
+ */
+public abstract class FLAPFrameFactory {
+
+ /**
+ * Creates new FLAPFrameFactory
+ */
+ public FLAPFrameFactory() {
+ }
+
+ public static FLAPFrame createFLAPFrame(byte[] frameData) throws FLAPFrameException {
+ FLAPFrame f = null;
+ if (frameData[0] != '*') {
+ throw new FLAPFrameException("Frame does not start with '*'");
+ }
+
+ switch (frameData[1]) {
+ case FLAPFrame.FLAP_FRAME_SIGNON:
+ f = new FLAPSignonFrame(frameData);
+ break;
+ case FLAPFrame.FLAP_FRAME_DATA:
+ f = new FLAPDataFrame(frameData);
+ break;
+ case FLAPFrame.FLAP_FRAME_ERROR:
+ f = new FLAPErrorFrame(frameData);
+ break;
+ case FLAPFrame.FLAP_FRAME_SIGNOFF:
+ f = new FLAPSignoffFrame(frameData);
+ break;
+ case FLAPFrame.FLAP_FRAME_KEEP_ALIVE:
+ f = new FLAPKeepAliveFrame(frameData);
+ break;
+ default:
+ throw new FLAPFrameException("Illegal FLAP Frame type: " + Integer.toString(frameData[1]));
+ }
+ return (f);
+ }
+
+}
diff --git a/src/com/wilko/jaim/flap/FLAPInputFrame.java b/src/com/wilko/jaim/flap/FLAPInputFrame.java
new file mode 100644
index 0000000..cb9a0f6
--- /dev/null
+++ b/src/com/wilko/jaim/flap/FLAPInputFrame.java
@@ -0,0 +1,69 @@
+/*
+ * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+/*
+ * FLAPInputFrame.java
+ *
+ * Created on 3 May 2002, 15:52
+ */
+
+package com.wilko.jaim.flap;
+
+/**
+ * @author paulw
+ * @version $Revision: 1.3 $
+ */
+public class FLAPInputFrame extends FLAPFrame {
+
+ /**
+ * Creates new FLAPInputFrame
+ */
+ private int frameLen;
+
+ public FLAPInputFrame() {
+ frameLen = 0;
+ super.initialise();
+ }
+
+ public void addFrameData(byte b) {
+ frame[frameLen++] = b;
+ }
+
+ public byte[] getFrameData() {
+ byte[] b = new byte[frameLen];
+ System.arraycopy(frame, 0, b, 0, frameLen);
+ return (b);
+ }
+
+ public void resetInputFrame() {
+ frameLen = 0;
+ }
+
+ public boolean completeFrameRead() {
+ if (frameLen > 5) {
+ return frameLen - 6 == getLength();
+ }
+ return (false);
+ }
+
+ public int getFLAPFrameType() {
+ return (-1);
+ }
+
+}
diff --git a/src/com/wilko/jaim/flap/FLAPKeepAliveFrame.java b/src/com/wilko/jaim/flap/FLAPKeepAliveFrame.java
new file mode 100644
index 0000000..841e6b3
--- /dev/null
+++ b/src/com/wilko/jaim/flap/FLAPKeepAliveFrame.java
@@ -0,0 +1,55 @@
+/*
+ * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+/*
+ * FLAPKeepAliveFrame.java
+ *
+ * Created on 3 May 2002, 14:54
+ */
+
+package com.wilko.jaim.flap;
+
+/**
+ * @author paulw
+ * @version $Revision: 1.4 $
+ */
+public class FLAPKeepAliveFrame extends FLAPFrame {
+
+ /**
+ * Creates new FLAPKeepAliveFrame
+ */
+ public FLAPKeepAliveFrame() {
+ this.initialise();
+ }
+
+ public FLAPKeepAliveFrame(byte[] frameData) {
+ initialise();
+ setFrameData(frameData);
+ }
+
+ protected void initialise() {
+ super.initialise();
+ frame[1] = FLAP_FRAME_KEEP_ALIVE;
+ }
+
+ public int getFLAPFrameType() {
+ return (FLAPFrame.FLAP_FRAME_KEEP_ALIVE);
+ }
+
+}
diff --git a/src/com/wilko/jaim/flap/FLAPSignoffFrame.java b/src/com/wilko/jaim/flap/FLAPSignoffFrame.java
new file mode 100644
index 0000000..9715ee9
--- /dev/null
+++ b/src/com/wilko/jaim/flap/FLAPSignoffFrame.java
@@ -0,0 +1,52 @@
+/*
+ * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+/*
+ * FLAPSignoffFrame.java
+ *
+ * Created on 3 May 2002, 14:54
+ */
+
+package com.wilko.jaim.flap;
+
+/**
+ * @author paulw
+ * @version $Revision: 1.3 $
+ */
+public class FLAPSignoffFrame extends FLAPFrame {
+
+ /**
+ * Creates new FlapSignonFrame
+ */
+ public FLAPSignoffFrame() {
+
+ frame[1] = FLAP_FRAME_SIGNOFF;
+ }
+
+ public FLAPSignoffFrame(byte[] frameData) {
+ frame[1] = FLAP_FRAME_SIGNOFF;
+ setFrameData(frameData);
+ }
+
+
+ public int getFLAPFrameType() {
+ return (FLAPFrame.FLAP_FRAME_SIGNOFF);
+ }
+
+}
diff --git a/src/com/wilko/jaim/flap/FLAPSignonFrame.java b/src/com/wilko/jaim/flap/FLAPSignonFrame.java
new file mode 100644
index 0000000..b3e9a31
--- /dev/null
+++ b/src/com/wilko/jaim/flap/FLAPSignonFrame.java
@@ -0,0 +1,82 @@
+/*
+ * (C) 2002 Paul Wilkinson wilko@users.sourceforge.net
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+/*
+ * FlapSignonFrame.java
+ *
+ * Created on 3 May 2002, 14:54
+ */
+
+package com.wilko.jaim.flap;
+
+/**
+ * @author paulw
+ * @version $Revision: 1.3 $
+ */
+public class FLAPSignonFrame extends FLAPFrame {
+
+ /**
+ * Creates new FlapSignonFrame
+ */
+ public FLAPSignonFrame() {
+ frame[1] = FLAP_FRAME_SIGNON;
+ }
+
+ public FLAPSignonFrame(byte[] frameData) {
+ frame[1] = FLAP_FRAME_SIGNON;
+ setFrameData(frameData);
+ }
+
+ public int getFLAPVersion() {
+ return (((frame[6] & 0xff) * 16777216) + ((frame[7] & 0xff) * 65536) + ((frame[8] & 0xff) * 256) + (frame[9] & 0xff));
+ }
+
+ public void setFLAPVersion(int version) {
+ for (int i = 3; i >= 0; i--) {
+ frame[6 + i] = (byte) (version & 0xff);
+ version = version >> 8;
+ }
+ }
+
+ public void setTLVTag(int tag) {
+ for (int i = 1; i >= 0; i--) {
+ frame[10 + i] = (byte) (tag & 0xff);
+ tag = tag >> 8;
+ }
+ }
+
+ public void setUserName(String name) {
+
+ int len = 0;
+ for (int i = 0; i < name.length(); i++) {
+ char c = name.charAt(i);
+ if (c != ' ') {
+ frame[FLAP_DATA_OFFSET + 8 + len++] = (byte) c;
+ }
+ }
+ setLength(8 + len);
+ frame[FLAP_DATA_OFFSET + 6] = (byte) (len / 256);
+ frame[FLAP_DATA_OFFSET + 7] = (byte) (len & 0xff);
+ }
+
+ public int getFLAPFrameType() {
+ return (FLAPFrame.FLAP_FRAME_SIGNON);
+ }
+
+}