Browse Source

use std::string instead of const char* in rmq struct

Grant Limberg 5 years ago
parent
commit
cc79ec6179
3 changed files with 11 additions and 9 deletions
  1. 3 2
      controller/RabbitMQ.cpp
  2. 5 4
      controller/RabbitMQ.hpp
  3. 3 3
      service/OneService.cpp

+ 3 - 2
controller/RabbitMQ.cpp

@@ -51,13 +51,14 @@ void RabbitMQ::init()
 		throw std::runtime_error("Can't create socket for RabbitMQ");
 		throw std::runtime_error("Can't create socket for RabbitMQ");
 	}
 	}
 
 
-	_status = amqp_socket_open_noblock(_socket, _mqc->host, _mqc->port, &tval);
+	fprintf(stderr, "RabbitMQ: amqp://%s:%s@%s:%d\n", _mqc->username.c_str(), _mqc->password.c_str(), _mqc->host.c_str(), _mqc->port);
+	_status = amqp_socket_open_noblock(_socket, _mqc->host.c_str(), _mqc->port, &tval);
 	if (_status) {
 	if (_status) {
 		throw std::runtime_error("Can't connect to RabbitMQ");
 		throw std::runtime_error("Can't connect to RabbitMQ");
 	}
 	}
 
 
 	amqp_rpc_reply_t r = amqp_login(_conn, "/", 0, 131072, 0, AMQP_SASL_METHOD_PLAIN,
 	amqp_rpc_reply_t r = amqp_login(_conn, "/", 0, 131072, 0, AMQP_SASL_METHOD_PLAIN,
-		_mqc->username, _mqc->password);
+		_mqc->username.c_str(), _mqc->password.c_str());
 	if (r.reply_type != AMQP_RESPONSE_NORMAL) {
 	if (r.reply_type != AMQP_RESPONSE_NORMAL) {
 		throw std::runtime_error("RabbitMQ Login Error");
 		throw std::runtime_error("RabbitMQ Login Error");
 	}
 	}

+ 5 - 4
controller/RabbitMQ.hpp

@@ -15,14 +15,15 @@
 #define ZT_CONTROLLER_RABBITMQ_HPP
 #define ZT_CONTROLLER_RABBITMQ_HPP
 
 
 #include "DB.hpp"
 #include "DB.hpp"
+#include <string>
 
 
 namespace ZeroTier
 namespace ZeroTier
 {
 {
 struct MQConfig {
 struct MQConfig {
-	const char *host;
+	std::string host;
 	int port;
 	int port;
-	const char *username;
-	const char *password;
+	std::string username;
+	std::string password;
 };
 };
 }
 }
 
 
@@ -32,7 +33,7 @@ struct MQConfig {
 
 
 #include <amqp.h>
 #include <amqp.h>
 #include <amqp_tcp_socket.h>
 #include <amqp_tcp_socket.h>
-#include <string>
+
 
 
 namespace ZeroTier
 namespace ZeroTier
 {
 {

+ 3 - 3
service/OneService.cpp

@@ -990,9 +990,9 @@ public:
 				fprintf(stderr, "Reading RabbitMQ Config\n");
 				fprintf(stderr, "Reading RabbitMQ Config\n");
 				_mqc = new MQConfig;
 				_mqc = new MQConfig;
 				_mqc->port = rmq["port"];
 				_mqc->port = rmq["port"];
-				_mqc->host = OSUtils::jsonString(rmq["host"], "").c_str();
-				_mqc->username = OSUtils::jsonString(rmq["username"], "").c_str();
-				_mqc->password = OSUtils::jsonString(rmq["password"], "").c_str();
+				_mqc->host = OSUtils::jsonString(rmq["host"], "");
+				_mqc->username = OSUtils::jsonString(rmq["username"], "");
+				_mqc->password = OSUtils::jsonString(rmq["password"], "");
 			}
 			}
 
 
 			// Bind to wildcard instead of to specific interfaces (disables full tunnel capability)
 			// Bind to wildcard instead of to specific interfaces (disables full tunnel capability)