21 #include <RCF/GoogleProtobufs.hpp>
23 #include <RCF/RCF.hpp>
24 #include <RCF/ClientStub.hpp>
25 #include <RCF/Exception.hpp>
26 #include <RCF/Export.hpp>
27 #include <RCF/RemoteCallContext.hpp>
29 #if RCF_FEATURE_OPENSSL==1
30 #include <RCF/OpenSslEncryptionFilter.hpp>
36 PemCertificate(
const std::string & pathToCert,
const std::string & password =
"")
38 RCF_THROW(Exception(_RcfError_NotSupportedInThisBuild(
"PemCertificate")));
46 RCF_THROW(Exception(_RcfError_NotSupportedInThisBuild(
"X509Certificate")));
48 std::string getCertificateName() {
return "";}
49 std::string getIssuerName() {
return ""; }
55 #if RCF_FEATURE_SSPI==1
56 #include <RCF/Schannel.hpp>
59 #if RCF_FEATURE_NAMEDPIPE==1
60 #include <RCF/Win32NamedPipeEndpoint.hpp>
63 #if RCF_FEATURE_LOCALSOCKET==1
64 #include <RCF/UnixLocalEndpoint.hpp>
75 UnixLocalEndpoint(
const std::string & socketName) { RCF_THROW(Exception(_RcfError_NotSupportedOnWindows(
"UnixLocalEndpoint"))); }
77 virtual std::auto_ptr<ServerTransport> createServerTransport()
const {
return std::auto_ptr<ServerTransport>(); }
78 virtual std::auto_ptr<ClientTransport> createClientTransport()
const {
return std::auto_ptr<ClientTransport>(); }
79 virtual EndpointPtr clone()
const {
return EndpointPtr(); }
80 virtual std::string asString()
const {
return std::string(); }
90 class RCF_EXPORT LogToDebugWindow :
public LogTarget
95 Exception e(_RcfError_SupportedOnWindowsOnly(
"LogToDebugWindow"));
98 virtual LogTarget * clone()
const {
return NULL; }
99 virtual void write(
const RCF::ByteBuffer & output) {}
102 class RCF_EXPORT LogToEventLog :
public LogTarget
105 LogToEventLog(
const std::string & appName,
int eventLogLevel)
107 Exception e(_RcfError_SupportedOnWindowsOnly(
"LogToEventLog"));
110 virtual LogTarget * clone()
const {
return NULL; }
111 virtual void write(
const RCF::ByteBuffer & output) {}
117 Win32NamedPipeEndpoint(
const tstring & pipeName) { RCF_THROW(Exception(_RcfError_SupportedOnWindowsOnly(
"Win32NamedPipeEndpoint"))); }
119 virtual std::auto_ptr<ServerTransport> createServerTransport()
const {
return std::auto_ptr<ServerTransport>(); }
120 virtual std::auto_ptr<ClientTransport> createClientTransport()
const {
return std::auto_ptr<ClientTransport>(); }
121 virtual EndpointPtr clone()
const {
return EndpointPtr(); }
122 virtual std::string asString()
const {
return std::string(); }
130 Exception e(_RcfError_SupportedOnWindowsOnly(
"Win32Certificate"));
134 virtual CertificateImplementationType _getType()
139 tstring getCertificateName() {
return tstring(); }
140 tstring getIssuerName() {
return tstring(); }
141 void exportToPfx(
const std::string & pfxFilePath) {}
143 Win32CertificatePtr findRootCertificate(
144 Win32CertificateLocation certStoreLocation,
145 Win32CertificateStore certStore) {
return Win32CertificatePtr(); }
155 const std::string & pathToCert,
156 const tstring & password,
157 const tstring & certName)
159 Exception e(_RcfError_SupportedOnWindowsOnly(
"PfxCertificate"));
164 Win32CertificateLocation certStoreLocation,
165 Win32CertificateStore certStore) {}
173 Win32CertificateLocation certStoreLocation,
174 Win32CertificateStore certStore,
175 const tstring & certName)
177 Exception e(_RcfError_SupportedOnWindowsOnly(
"StoreCertificate"));
181 void removeFromStore() {}
190 Win32CertificateLocation certStoreLocation,
191 Win32CertificateStore certStore)
193 Exception e(_RcfError_SupportedOnWindowsOnly(
"StoreCertificateIterator"));
197 bool moveNext() {
return false; }
199 Win32CertificatePtr current() {
return Win32CertificatePtr(); }
204 #endif // ! BOOST_WINDOWS
206 using namespace google::protobuf;
221 virtual void Reset();
226 virtual bool Failed()
const;
229 virtual std::string ErrorText()
const;
234 virtual void StartCancel();
246 virtual void SetFailed(
const std::string& reason);
251 virtual bool IsCanceled()
const;
260 virtual void NotifyOnCancel(Closure* callback);
282 template<
typename T>
class RcfClient;
287 class RCF_EXPORT _SwigCallbackArgs
293 std::string mErrorString;
295 CertificatePtr mCertificatePtr;
301 class RCF_EXPORT _SwigCallback
308 virtual ~_SwigCallback();
314 virtual void ProtoRpcBegin(
315 _SwigCallbackArgs * args,
318 const std::string & serviceName,
322 virtual bool ValidateCertificate(
323 _SwigCallbackArgs * args);
329 class _SwigCallbackCpp :
public _SwigCallback
345 void _CallMethodSwig(
346 const std::string& serviceName,
348 unsigned char * szBuffer,
350 _SwigCallback * closure);
352 int _GetResponseBufferLength()
const;
353 void _GetResponseBuffer(
unsigned char * szBuffer,
int bufferLen)
const;
356 void _CallMethodSwig(
357 const std::string& serviceName,
361 _SwigCallback * closure);
363 void _GetResponseBuffer(
char * szBuffer,
size_t bufferLen)
const;
371 void _CallMethodSwig_WithCopy(
372 const std::string& serviceName,
374 const std::string& strBuffer,
375 _SwigCallback * closure);
377 std::string _GetResponseBuffer_WithCopy()
const;
388 std::string ErrorText();
406 void setRemoteCallTimeoutMs(
unsigned int remoteCallTimeoutMs);
409 unsigned int getRemoteCallTimeoutMs()
const;
412 void setConnectTimeoutMs(
unsigned int connectTimeoutMs);
415 unsigned int getConnectTimeoutMs()
const;
418 void setTransportProtocol(RCF::TransportProtocol protocol);
421 RCF::TransportProtocol getTransportProtocol();
424 void setEnableAsynchronousRpc(
bool enable);
427 bool getEnableAsynchronousRpc();
432 void setPingBackIntervalMs(
int pingBackIntervalMs);
435 int getPingBackIntervalMs();
438 void setHttpProxy(
const std::string & httpProxy);
441 std::string getHttpProxy();
444 void setHttpProxyPort(
int httpProxyPort);
447 int getHttpProxyPort();
450 TransportType getTransportType();
453 void setUsername(
const tstring & username);
456 tstring getUsername();
459 void setPassword(
const tstring & password);
462 tstring getPassword();
465 void setKerberosSpn(
const tstring & kerberosSpn);
468 tstring getKerberosSpn();
471 void setEnableCompression(
bool enableCompression);
474 bool getEnableCompression();
477 void setCertificate(CertificatePtr certificatePtr);
480 CertificatePtr getCertificate();
483 void setCaCertificate(CertificatePtr certificatePtr);
486 CertificatePtr getCaCertificate();
489 void setOpenSslCipherSuite(
const std::string & cipherSuite);
492 std::string getOpenSslCipherSuite()
const;
496 void setEnableSchannelCertificateValidation(
const tstring & peerName);
499 tstring getEnableSchannelCertificateValidation()
const;
501 void _setCertificateValidationCallback(_SwigCallback * pcb);
504 void setSslImplementation(SslImplementation sslImplementation);
507 SslImplementation getSslImplementation()
const;
521 virtual void CallMethod(
522 const MethodDescriptor* method,
523 RpcController* controller,
524 const Message* request,
526 google::protobuf::Closure* done);
529 void CallMethodInternal(
530 const std::string & serviceName,
532 RCF::ByteBuffer requestBuffer,
533 _SwigCallback * closure);
537 friend class _SwigCallbackCpp;
538 _SwigCallbackCpp mSwigCallbackCpp;
540 void onCompletionCpp();
543 boost::shared_ptr< RcfClient<I_Pb> > mRcfClientPtr;
545 const Message * mpRequest;
546 Message * mpResponse;
549 _SwigCallback * mpSwigCallback;
551 boost::function<void()> mCompletionHandlerSwig;
553 RCF::Future<RCF::ByteBuffer> mFuture;
554 RCF::Exception mError;
555 RCF::ByteBuffer mResponseBuffer;
557 std::string mRequestCopy;
559 bool mEnableAsynchronousRpc;
565 typedef RCF::RemoteCallContext<
569 RCF::ByteBuffer> RcfProtoContext;
578 int _GetRequestBufferLength();
581 void _GetRequestBuffer(
unsigned char * szBuffer,
int szBufferLen);
582 void _SetResponseBuffer(
unsigned char * szBuffer,
int szBufferLen);
585 void _GetRequestBuffer(
char * szBuffer,
size_t szBufferLen);
586 void _SetResponseBuffer(
char * szBuffer,
size_t szBufferLen);
595 void SetFailed(
const std::string& reason);
600 bool IsCanceled()
const;
602 void _Commit(
const std::string& errorMsg);
605 std::string _GetRequestBuffer_WithCopy();
607 void _SetResponseBuffer_WithCopy(
const std::string& buffer);
610 tstring getClientUsername();
613 TransportProtocol getTransportProtocol();
616 TransportType getTransportType();
619 bool getEnableCompression();
622 std::size_t getConnectionDuration()
const;
625 std::size_t getRemoteCallCount()
const;
628 boost::uint64_t getTotalBytesReceived()
const;
631 boost::uint64_t getTotalBytesSent()
const;
647 void NotifyOnCancel(Closure* callback);
654 RcfSession & mRcfSession;
656 RcfProtoContext mServerContext;
658 RCF::ByteBuffer mRequestBuffer;
659 RCF::ByteBuffer mResponseBuffer;
704 void _setCallbackTable(_SwigCallback * pCallback);
707 void setThreadPool(ThreadPoolPtr threadPoolPtr) { RcfServer::setThreadPool(threadPoolPtr); }
722 void setSupportedTransportProtocols(
723 const std::vector<TransportProtocol> & protocols) { RcfServer::setSupportedTransportProtocols(protocols); }
726 const std::vector<TransportProtocol> &
731 void setSessionTimeoutMs(boost::uint32_t sessionTimeoutMs) {
return RcfServer::setSessionTimeoutMs(sessionTimeoutMs); }
744 void setCertificate(CertificatePtr certificatePtr) { RcfServer::setCertificate(certificatePtr); }
756 void setCaCertificate(CertificatePtr certificatePtr) { RcfServer::setCaCertificate(certificatePtr); }
769 void setSslImplementation(SslImplementation sslImplementation) { RcfServer::setSslImplementation(sslImplementation); }
783 void bindService(Service & service);
785 RCF::ByteBuffer DoProtoRpc(
786 const std::string & serviceName,
788 RCF::ByteBuffer requestBuffer);
792 void ProtoRpcBeginCpp(
RcfProtoSession * context,
const std::string & serviceName,
int methodId);
795 typedef std::map<std::string, Service *> ProtobufServices;
796 ProtobufServices mProtobufServices;
798 _SwigCallback * mpSwigCallback;
801 class BoostBindClosure :
public Closure
810 BoostBindClosure(
const boost::function<
void()> & func,
bool permanent =
false) :
812 mPermanent(permanent)
816 void assign(
const boost::function<
void()> & func,
bool permanent =
true)
819 mPermanent = permanent;
831 boost::function<void()> mFunc;