Advertisement
Guest User

Untitled

a guest
Feb 5th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. boost::shared_ptr<TTransport> transport;
  2. boost::shared_ptr<TProtocol> protocol;
  3.  
  4. boost::shared_ptr<TSocket> socket;
  5. boost::shared_ptr<TSSLSocketFactory> factory;
  6.  
  7. if (ssl) {
  8. factory = boost::shared_ptr<TSSLSocketFactory>(new TSSLSocketFactory());
  9. factory->ciphers("ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
  10. factory->loadTrustedCertificates((dir_path + "../keys/CA.pem").c_str());
  11. factory->authenticate(true);
  12. socket = factory->createSocket(host, port);
  13. } else {
  14. if (domain_socket != "") {
  15. if (abstract_namespace) {
  16. std::string abstract_socket("", 1);
  17. abstract_socket += domain_socket;
  18. socket = boost::shared_ptr<TSocket>(new TSocket(abstract_socket));
  19. } else {
  20. socket = boost::shared_ptr<TSocket>(new TSocket(domain_socket));
  21. }
  22. port = 0;
  23. } else {
  24. socket = boost::shared_ptr<TSocket>(new TSocket(host, port));
  25. }
  26. }
  27.  
  28. if (transport_type.compare("http") == 0) {
  29. boost::shared_ptr<TTransport> httpSocket(new THttpClient(socket, host, "/service"));
  30. transport = httpSocket;
  31. } else if (transport_type.compare("framed") == 0) {
  32. boost::shared_ptr<TFramedTransport> framedSocket(new TFramedTransport(socket));
  33. transport = framedSocket;
  34. } else {
  35. boost::shared_ptr<TBufferedTransport> bufferedSocket(new TBufferedTransport(socket));
  36. transport = bufferedSocket;
  37. }
  38.  
  39. if (protocol_type.compare("json") == 0) {
  40. boost::shared_ptr<TProtocol> jsonProtocol(new TJSONProtocol(transport));
  41. protocol = jsonProtocol;
  42. } else if (protocol_type.compare("compact") == 0) {
  43. boost::shared_ptr<TProtocol> compactProtocol(new TCompactProtocol(transport));
  44. protocol = compactProtocol;
  45. } else if (protocol_type == "header") {
  46. boost::shared_ptr<TProtocol> headerProtocol(new THeaderProtocol(transport));
  47. protocol = headerProtocol;
  48. } else {
  49. boost::shared_ptr<TBinaryProtocol> binaryProtocol(new TBinaryProtocol(transport));
  50. protocol = binaryProtocol;
  51. }
  52.  
  53. // Connection info
  54. cout << "Connecting (" << transport_type << "/" << protocol_type << ") to: ";
  55. if (abstract_namespace) {
  56. cout << '@';
  57. }
  58. cout << domain_socket;
  59. if (port != 0) {
  60. cout << host << ":" << port;
  61. }
  62. cout << endl;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement