summaryrefslogtreecommitdiffstats
path: root/Dozentenmodulserver/src/server/TBinaryProtocolSafe.java
diff options
context:
space:
mode:
authorunknown2014-05-25 17:49:07 +0200
committerunknown2014-05-25 17:49:07 +0200
commitb0b65eca6b6600a57d71c5f63f8e5a066e6accd7 (patch)
tree21b55c6f7ff2c60401ede9f369738b2ae2d5f77f /Dozentenmodulserver/src/server/TBinaryProtocolSafe.java
parent links + encoding (diff)
parentFreigabe Mechanismus implementiert, nun sollte die notwendige Grundlage für d... (diff)
downloadtutor-module-b0b65eca6b6600a57d71c5f63f8e5a066e6accd7.tar.gz
tutor-module-b0b65eca6b6600a57d71c5f63f8e5a066e6accd7.tar.xz
tutor-module-b0b65eca6b6600a57d71c5f63f8e5a066e6accd7.zip
Merge branch 'master' of ssh://git.openslx.org/openslx-ng/tutor-module
Conflicts: ffffDozentenmodul/bin/gui/image/CreateImageTechnisch_GUI.class Dozentenmodul/bin/gui/image/DeleteImage_GUI.class Dozentenmodul/bin/gui/image/EditImageAllgemein_GUI.class Dozentenmodul/bin/gui/image/FTPCreateUploader_GUI$8.class Dozentenmodul/bin/gui/image/FTPCreateUploader_GUI.class Dozentenmodul/bin/gui/image/FTPDownloader_GUI.class Dozentenmodul/bin/gui/image/FTPEditUploader_GUI.class Dozentenmodul/bin/gui/image/SearchEditImage_GUI.class Dozentenmodul/bin/gui/image/SearchImage_GUI.class Dozentenmodul/bin/gui/intro/VmWareLink_GUI.class Dozentenmodul/bin/gui/lecture/CreateLectureAllgemein_GUI.class Dozentenmodul/bin/gui/lecture/EditLectureAllgemein_GUI.class Dozentenmodul/bin/gui/lecture/ExtendedSearchForImages_GUI.class Dozentenmodul/src/gui/lecture/EditLectureLink_GUI.java Dozentenmodul/src/models/Links.java
Diffstat (limited to 'Dozentenmodulserver/src/server/TBinaryProtocolSafe.java')
-rw-r--r--Dozentenmodulserver/src/server/TBinaryProtocolSafe.java123
1 files changed, 123 insertions, 0 deletions
diff --git a/Dozentenmodulserver/src/server/TBinaryProtocolSafe.java b/Dozentenmodulserver/src/server/TBinaryProtocolSafe.java
new file mode 100644
index 00000000..843b58b1
--- /dev/null
+++ b/Dozentenmodulserver/src/server/TBinaryProtocolSafe.java
@@ -0,0 +1,123 @@
+package server;
+
+import java.io.UnsupportedEncodingException;
+import java.nio.ByteBuffer;
+
+import org.apache.thrift.TException;
+import org.apache.thrift.protocol.TBinaryProtocol;
+import org.apache.thrift.protocol.TMessage;
+import org.apache.thrift.protocol.TProtocol;
+import org.apache.thrift.protocol.TProtocolException;
+import org.apache.thrift.protocol.TProtocolFactory;
+import org.apache.thrift.transport.TTransport;
+
+/**
+ * Binary protocol implementation for thrift.
+ * Will not read messages bigger than 12MiB.
+ *
+ */
+public class TBinaryProtocolSafe extends TBinaryProtocol
+{
+ /**
+ * Factory
+ */
+ @SuppressWarnings( "serial" )
+ public static class Factory implements TProtocolFactory
+ {
+
+ protected boolean strictRead_ = false;
+ protected boolean strictWrite_ = true;
+
+ public Factory()
+ {
+ this( false, true );
+ }
+
+ public Factory(boolean strictRead, boolean strictWrite)
+ {
+ strictRead_ = strictRead;
+ strictWrite_ = strictWrite;
+ }
+
+ public TProtocol getProtocol( TTransport trans )
+ {
+ return new TBinaryProtocolSafe( trans, strictRead_, strictWrite_ );
+ }
+ }
+
+ private static final int maxLen = 12 * 1024 * 1024; // 12 MiB
+
+ /**
+ * Constructor
+ */
+ public TBinaryProtocolSafe(TTransport trans)
+ {
+ this( trans, false, true );
+ }
+
+ public TBinaryProtocolSafe(TTransport trans, boolean strictRead, boolean strictWrite)
+ {
+ super( trans );
+ strictRead_ = strictRead;
+ strictWrite_ = strictWrite;
+ }
+
+ /**
+ * Reading methods.
+ */
+
+ public TMessage readMessageBegin() throws TException
+ {
+ int size = readI32();
+ if ( size > maxLen )
+ throw new TProtocolException( TProtocolException.SIZE_LIMIT, "Payload too big." );
+ if ( size < 0 ) {
+ int version = size & VERSION_MASK;
+ if ( version != VERSION_1 ) {
+ throw new TProtocolException( TProtocolException.BAD_VERSION, "Bad version in readMessageBegin" );
+ }
+ return new TMessage( readString(), (byte) ( size & 0x000000ff ), readI32() );
+ } else {
+ if ( strictRead_ ) {
+ throw new TProtocolException( TProtocolException.BAD_VERSION, "Missing version in readMessageBegin, old client?" );
+ }
+ return new TMessage( readStringBody( size ), readByte(), readI32() );
+ }
+ }
+
+ public String readString() throws TException
+ {
+ int size = readI32();
+ if ( size > maxLen )
+ throw new TProtocolException( TProtocolException.SIZE_LIMIT, "Payload too big." );
+ if ( trans_.getBytesRemainingInBuffer() >= size ) {
+ try {
+ String s = new String( trans_.getBuffer(), trans_.getBufferPosition(), size, "UTF-8" );
+ trans_.consumeBuffer( size );
+ return s;
+ } catch ( UnsupportedEncodingException e ) {
+ throw new TException( "JVM DOES NOT SUPPORT UTF-8" );
+ }
+ }
+
+ return readStringBody( size );
+ }
+
+ public ByteBuffer readBinary() throws TException
+ {
+ int size = readI32();
+ if ( size > maxLen )
+ throw new TProtocolException( TProtocolException.SIZE_LIMIT, "Payload too big." );
+ if ( trans_.getBytesRemainingInBuffer() >= size ) {
+ ByteBuffer bb = ByteBuffer.wrap( trans_.getBuffer(), trans_.getBufferPosition(), size );
+ trans_.consumeBuffer( size );
+ return bb;
+ }
+
+ byte[] buf = new byte[ size ];
+ trans_.readAll( buf, 0, size );
+ return ByteBuffer.wrap( buf );
+ }
+
+}
+