Cocoa Thrift binding patches from Andrew McGeachie

Summary: Latest updates to the Cocoa bindings


git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665354 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/cocoa/src/protocol/TBinaryProtocol.m b/lib/cocoa/src/protocol/TBinaryProtocol.m
index 19db55f..7564f5d 100644
--- a/lib/cocoa/src/protocol/TBinaryProtocol.m
+++ b/lib/cocoa/src/protocol/TBinaryProtocol.m
@@ -44,6 +44,18 @@
 }
 
 
+- (int32_t) messageSizeLimit
+{
+  return mMessageSizeLimit;
+}
+
+
+- (void) setMessageSizeLimit: (int32_t) sizeLimit
+{
+  mMessageSizeLimit = sizeLimit;
+}
+
+
 - (void) dealloc
 {
   [mTransport release];
@@ -70,7 +82,7 @@
                                   type: (int *) type
                             sequenceID: (int *) sequenceID
 {
-  int size = [self readI32];
+  int32_t size = [self readI32];
   if (size < 0) {
     int version = size & VERSION_MASK;
     if (version != VERSION_1) {
@@ -93,6 +105,12 @@
       @throw [TProtocolException exceptionWithName: @"TProtocolException"
                                  reason: @"Missing version in readMessageBegin, old client?"];
     }
+    if ([self messageSizeLimit] > 0 && size > [self messageSizeLimit]) {
+      @throw [TProtocolException exceptionWithName: @"TProtocolException"
+                                            reason: [NSString stringWithFormat: @"Message too big.  Size limit is: %d Message size is: %d",
+                                                     mMessageSizeLimit,
+                                                     size]];      
+    }
     NSString * messageName = [self readStringBody: size];
     if (name != NULL) {
       *name = messageName;