aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/objective-c
diff options
context:
space:
mode:
Diffstat (limited to 'src/objective-c')
-rw-r--r--src/objective-c/GRPCClient/GRPCCall.h6
-rw-r--r--src/objective-c/GRPCClient/GRPCCall.m2
-rw-r--r--src/objective-c/GRPCClient/private/GRPCChannel.h1
-rw-r--r--src/objective-c/GRPCClient/private/GRPCChannel.m23
-rw-r--r--src/objective-c/GRPCClient/private/GRPCHost.h1
-rw-r--r--src/objective-c/GRPCClient/private/GRPCHost.m3
-rw-r--r--src/objective-c/GRPCClient/private/GRPCWrappedCall.h1
-rw-r--r--src/objective-c/GRPCClient/private/GRPCWrappedCall.m9
-rw-r--r--src/objective-c/tests/PluginTest/imported-with-dash.proto22
-rw-r--r--src/objective-c/tests/PluginTest/test-dash-filename.proto27
-rwxr-xr-xsrc/objective-c/tests/build_tests.sh1
-rwxr-xr-xsrc/objective-c/tests/run_tests.sh32
12 files changed, 118 insertions, 10 deletions
diff --git a/src/objective-c/GRPCClient/GRPCCall.h b/src/objective-c/GRPCClient/GRPCCall.h
index 8c5bcf1c8b..178a446c8b 100644
--- a/src/objective-c/GRPCClient/GRPCCall.h
+++ b/src/objective-c/GRPCClient/GRPCCall.h
@@ -164,6 +164,12 @@ extern id const kGRPCTrailersKey;
@interface GRPCCall : GRXWriter
/**
+ * The authority for the RPC. If nil, the default authority will be used. This property must be nil
+ * when Cronet transport is enabled.
+ */
+@property (atomic, readwrite) NSString *serverName;
+
+/**
* The container of the request headers of an RPC conforms to this protocol, which is a subset of
* NSMutableDictionary's interface. It will become a NSMutableDictionary later on.
* The keys of this container are the header names, which per the HTTP standard are case-
diff --git a/src/objective-c/GRPCClient/GRPCCall.m b/src/objective-c/GRPCClient/GRPCCall.m
index 6ba401def4..872362419e 100644
--- a/src/objective-c/GRPCClient/GRPCCall.m
+++ b/src/objective-c/GRPCClient/GRPCCall.m
@@ -425,7 +425,7 @@ static NSMutableDictionary *callFlags;
_responseWriteable = [[GRXConcurrentWriteable alloc] initWithWriteable:writeable
dispatchQueue:_responseQueue];
- _wrappedCall = [[GRPCWrappedCall alloc] initWithHost:_host path:_path];
+ _wrappedCall = [[GRPCWrappedCall alloc] initWithHost:_host serverName:_serverName path:_path];
NSAssert(_wrappedCall, @"Error allocating RPC objects. Low memory?");
[self sendHeaders:_requestHeaders];
diff --git a/src/objective-c/GRPCClient/private/GRPCChannel.h b/src/objective-c/GRPCClient/private/GRPCChannel.h
index e4dfbca38d..e2aa5bd036 100644
--- a/src/objective-c/GRPCClient/private/GRPCChannel.h
+++ b/src/objective-c/GRPCClient/private/GRPCChannel.h
@@ -62,5 +62,6 @@ struct grpc_channel_credentials;
channelArgs:(nullable NSDictionary *)channelArgs;
- (nullable grpc_call *)unmanagedCallWithPath:(nonnull NSString *)path
+ serverName:(nonnull NSString *)serverName
completionQueue:(nonnull GRPCCompletionQueue *)queue;
@end
diff --git a/src/objective-c/GRPCClient/private/GRPCChannel.m b/src/objective-c/GRPCClient/private/GRPCChannel.m
index 79fe7c6e05..52dbc70b99 100644
--- a/src/objective-c/GRPCClient/private/GRPCChannel.m
+++ b/src/objective-c/GRPCClient/private/GRPCChannel.m
@@ -181,13 +181,24 @@ static grpc_channel_args *BuildChannelArgs(NSDictionary *dictionary) {
}
- (grpc_call *)unmanagedCallWithPath:(NSString *)path
+ serverName:(NSString *)serverName
completionQueue:(GRPCCompletionQueue *)queue {
- return grpc_channel_create_call(_unmanagedChannel,
- NULL, GRPC_PROPAGATE_DEFAULTS,
- queue.unmanagedQueue,
- grpc_slice_from_copied_string(path.UTF8String),
- NULL, // Passing NULL for host
- gpr_inf_future(GPR_CLOCK_REALTIME), NULL);
+ grpc_slice host_slice;
+ if (serverName) {
+ host_slice = grpc_slice_from_copied_string(serverName.UTF8String);
+ }
+ grpc_slice path_slice = grpc_slice_from_copied_string(path.UTF8String);
+ grpc_call *call = grpc_channel_create_call(_unmanagedChannel,
+ NULL, GRPC_PROPAGATE_DEFAULTS,
+ queue.unmanagedQueue,
+ path_slice,
+ serverName ? &host_slice : NULL,
+ gpr_inf_future(GPR_CLOCK_REALTIME), NULL);
+ if (serverName) {
+ grpc_slice_unref(host_slice);
+ }
+ grpc_slice_unref(path_slice);
+ return call;
}
@end
diff --git a/src/objective-c/GRPCClient/private/GRPCHost.h b/src/objective-c/GRPCClient/private/GRPCHost.h
index 4b1f780dd2..0c1d715240 100644
--- a/src/objective-c/GRPCClient/private/GRPCHost.h
+++ b/src/objective-c/GRPCClient/private/GRPCHost.h
@@ -54,6 +54,7 @@ struct grpc_channel_credentials;
/** Create a grpc_call object to the provided path on this host. */
- (nullable struct grpc_call *)unmanagedCallWithPath:(NSString *)path
+ serverName:(NSString *)serverName
completionQueue:(GRPCCompletionQueue *)queue;
// TODO: There's a race when a new RPC is coming through just as an existing one is getting
diff --git a/src/objective-c/GRPCClient/private/GRPCHost.m b/src/objective-c/GRPCClient/private/GRPCHost.m
index 5b4d647a1a..23794c1fed 100644
--- a/src/objective-c/GRPCClient/private/GRPCHost.m
+++ b/src/objective-c/GRPCClient/private/GRPCHost.m
@@ -120,6 +120,7 @@ static GRPCConnectivityMonitor *connectivityMonitor = nil;
}
- (nullable grpc_call *)unmanagedCallWithPath:(NSString *)path
+ serverName:(NSString *)serverName
completionQueue:(GRPCCompletionQueue *)queue {
GRPCChannel *channel;
// This is racing -[GRPCHost disconnect].
@@ -129,7 +130,7 @@ static GRPCConnectivityMonitor *connectivityMonitor = nil;
}
channel = _channel;
}
- return [channel unmanagedCallWithPath:path completionQueue:queue];
+ return [channel unmanagedCallWithPath:path serverName:serverName completionQueue:queue];
}
- (BOOL)setTLSPEMRootCerts:(nullable NSString *)pemRootCerts
diff --git a/src/objective-c/GRPCClient/private/GRPCWrappedCall.h b/src/objective-c/GRPCClient/private/GRPCWrappedCall.h
index ed245ff7ed..64075591a3 100644
--- a/src/objective-c/GRPCClient/private/GRPCWrappedCall.h
+++ b/src/objective-c/GRPCClient/private/GRPCWrappedCall.h
@@ -75,6 +75,7 @@
@interface GRPCWrappedCall : NSObject
- (instancetype)initWithHost:(NSString *)host
+ serverName:(NSString *)serverName
path:(NSString *)path NS_DESIGNATED_INITIALIZER;
- (void)startBatchWithOperations:(NSArray *)ops errorHandler:(void(^)())errorHandler;
diff --git a/src/objective-c/GRPCClient/private/GRPCWrappedCall.m b/src/objective-c/GRPCClient/private/GRPCWrappedCall.m
index 8c8b0b2570..9802465001 100644
--- a/src/objective-c/GRPCClient/private/GRPCWrappedCall.m
+++ b/src/objective-c/GRPCClient/private/GRPCWrappedCall.m
@@ -75,6 +75,10 @@
}
- (void)dealloc {
+ for (int i = 0; i < _op.data.send_initial_metadata.count; i++) {
+ grpc_slice_unref(_op.data.send_initial_metadata.metadata[i].key);
+ grpc_slice_unref(_op.data.send_initial_metadata.metadata[i].value);
+ }
gpr_free(_op.data.send_initial_metadata.metadata);
}
@@ -232,10 +236,11 @@
}
- (instancetype)init {
- return [self initWithHost:nil path:nil];
+ return [self initWithHost:nil serverName:nil path:nil];
}
- (instancetype)initWithHost:(NSString *)host
+ serverName:(NSString *)serverName
path:(NSString *)path {
if (!path || !host) {
[NSException raise:NSInvalidArgumentException
@@ -248,7 +253,7 @@
// queue. Currently we use a singleton queue.
_queue = [GRPCCompletionQueue completionQueue];
- _call = [[GRPCHost hostWithAddress:host] unmanagedCallWithPath:path completionQueue:_queue];
+ _call = [[GRPCHost hostWithAddress:host] unmanagedCallWithPath:path serverName:serverName completionQueue:_queue];
if (_call == NULL) {
return nil;
}
diff --git a/src/objective-c/tests/PluginTest/imported-with-dash.proto b/src/objective-c/tests/PluginTest/imported-with-dash.proto
new file mode 100644
index 0000000000..c01bbecc07
--- /dev/null
+++ b/src/objective-c/tests/PluginTest/imported-with-dash.proto
@@ -0,0 +1,22 @@
+// Copyright 2017 gRPC authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+syntax = "proto3";
+
+package grpc.testing;
+
+option objc_class_prefix = "RMT";
+
+message TestMessageImported {
+ int32 dummy = 1;
+}
diff --git a/src/objective-c/tests/PluginTest/test-dash-filename.proto b/src/objective-c/tests/PluginTest/test-dash-filename.proto
new file mode 100644
index 0000000000..afbb6035df
--- /dev/null
+++ b/src/objective-c/tests/PluginTest/test-dash-filename.proto
@@ -0,0 +1,27 @@
+// Copyright 2017 gRPC authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+syntax = "proto3";
+
+package grpc.testing;
+
+option objc_class_prefix = "RMT";
+
+import "imported-with-dash.proto";
+
+message TestMessage {
+ int32 dummy = 1;
+}
+
+service DummyService {
+}
diff --git a/src/objective-c/tests/build_tests.sh b/src/objective-c/tests/build_tests.sh
index 711a9cc8e4..340044f322 100755
--- a/src/objective-c/tests/build_tests.sh
+++ b/src/objective-c/tests/build_tests.sh
@@ -37,3 +37,4 @@ rm -f RemoteTestClient/*.{h,m}
echo "TIME: $(date)"
pod install
+
diff --git a/src/objective-c/tests/run_tests.sh b/src/objective-c/tests/run_tests.sh
index 6f27d1c462..8fa9439284 100755
--- a/src/objective-c/tests/run_tests.sh
+++ b/src/objective-c/tests/run_tests.sh
@@ -23,6 +23,38 @@ cd $(dirname $0)
# Run the tests server.
BINDIR=../../../bins/$CONFIG
+PROTOC=$BINDIR/protobuf/protoc
+PLUGIN=$BINDIR/grpc_objective_c_plugin
+
+rm -rf PluginTest/*pb*
+
+# Verify the output proto filename
+eval $PROTOC \
+ --plugin=protoc-gen-grpc=$PLUGIN \
+ --objc_out=PluginTest \
+ --grpc_out=PluginTest \
+ -I PluginTest \
+ -I ../../../third_party/protobuf/src \
+ PluginTest/*.proto
+
+[ -e ./PluginTest/TestDashFilename.pbrpc.h ] || {
+ echo >&2 "protoc outputs wrong filename."
+ exit 1
+}
+
+# Verify names of the imported protos in generated code
+[ "`cat PluginTest/TestDashFilename.pbrpc.h |
+ egrep '#import ".*\.pb(objc|rpc)\.h"$' |
+ egrep '-'`" ] && {
+ echo >&2 "protoc generated import with wrong filename."
+ exit 1
+}
+[ "`cat PluginTest/TestDashFilename.pbrpc.m |
+ egrep '#import ".*\.pb(objc|rpc)\.m"$' |
+ egrep '-'`" ] && {
+ echo >&2 "protoc generated import with wrong filename."
+ exit 1
+}
[ -f $BINDIR/interop_server ] || {
echo >&2 "Can't find the test server. Make sure run_tests.py is making" \