static void parse_success(const char *url,
                          const char *user,
                          const char *password,
                          const char *host,
                          int port,
                          const char *vhost)
{
  char *s = strdup(url);
  struct amqp_connection_info ci;
  int res;

  amqp_default_connection_info(&ci);
  res = amqp_parse_url(s, &ci);
  if (res) {
    fprintf(stderr,
            "Expected to successfully parse URL, but didn't: %s (%s)\n",
            url, amqp_error_string2(res));
    abort();
  }

  match_string("user", user, ci.user);
  match_string("password", password, ci.password);
  match_string("host", host, ci.host);
  match_int("port", port, ci.port);
  match_string("vhost", vhost, ci.vhost);

  free(s);
}
Example #2
0
Channel::ptr_t Channel::CreateFromUri(const std::string &uri, int frame_max) {
  amqp_connection_info info;
  amqp_default_connection_info(&info);

  boost::shared_ptr<char> uri_dup =
      boost::shared_ptr<char>(strdup(uri.c_str()), free);

  if (0 != amqp_parse_url(uri_dup.get(), &info)) {
    throw BadUriException();
  }

  return Create(std::string(info.host), info.port, std::string(info.user),
                std::string(info.password), std::string(info.vhost), frame_max);
}
static void parse_fail(const char *url)
{
  char *s = strdup(url);
  struct amqp_connection_info ci;

  amqp_default_connection_info(&ci);
  if (amqp_parse_url(s, &ci) >= 0) {
    fprintf(stderr,
            "Expected to fail parsing URL, but didn't: %s\n",
            url);
    abort();
  }

  free(s);
}
Example #4
0
Channel::ptr_t Channel::CreateSecureFromUri(
    const std::string &uri, const std::string &path_to_ca_cert,
    const std::string &path_to_client_key,
    const std::string &path_to_client_cert, bool verify_hostname,
    int frame_max) {
  amqp_connection_info info;
  amqp_default_connection_info(&info);

  boost::shared_ptr<char> uri_dup =
      boost::shared_ptr<char>(strdup(uri.c_str()), free);

  if (0 != amqp_parse_url(uri_dup.get(), &info)) {
    throw BadUriException();
  }

  if (info.ssl) {
    return CreateSecure(path_to_ca_cert, std::string(info.host),
                        path_to_client_key, path_to_client_cert, info.port,
                        std::string(info.user), std::string(info.password),
                        std::string(info.vhost), frame_max, verify_hostname);
  }
  throw std::runtime_error(
      "CreateSecureFromUri only supports SSL-enabled URIs.");
}
Example #5
0
static void init_connection_info(struct amqp_connection_info *ci)
{
  ci->user = NULL;
  ci->password = NULL;
  ci->host = NULL;
  ci->port = -1;
  ci->vhost = NULL;
  ci->user = NULL;

  amqp_default_connection_info(ci);

  if (amqp_url)
    die_amqp_error(amqp_parse_url(strdup(amqp_url), ci),
                   "Parsing URL '%s'", amqp_url);

  if (amqp_server) {
    char *colon;
    if (ci->host)
      die("both --server and --url options specify"
          " server host");

    /* parse the server string into a hostname and a port */
    colon = strchr(amqp_server, ':');
    if (colon) {
      char *port_end;
      size_t host_len;

      /* Deprecate specifying the port number with the
         --server option, because it is not ipv6 friendly.
         --url now allows connection options to be
         specificied concisely. */
      fprintf(stderr, "Specifying the port number with"
              " --server is deprecated\n");

      host_len = colon - amqp_server;
      ci->host = malloc(host_len + 1);
      memcpy(ci->host, amqp_server, host_len);
      ci->host[host_len] = 0;

      if (ci->port >= 0)
        die("both --server and --url options specify"
            " server port");
      if (amqp_port >= 0)
        die("both --server and --port options specify"
            " server port");

      ci->port = strtol(colon+1, &port_end, 10);
      if (ci->port < 0
          || ci->port > 65535
          || port_end == colon+1
          || *port_end != 0)
        die("bad server port number in '%s'",
            amqp_server);
    }

#if WITH_SSL
    if (amqp_ssl && !ci->ssl) {
      die("the --ssl option specifies an SSL connection"
          " but the --server option does not");
    }
#endif
  }

  if (amqp_port >= 0) {
    if (ci->port >= 0)
      die("both --port and --url options specify"
          " server port");

    ci->port = amqp_port;
  }

  if (amqp_username) {
    if (ci->user)
      die("both --username and --url options specify"
          " AMQP username");

    ci->user = amqp_username;
  }

  if (amqp_password) {
    if (ci->password)
      die("both --password and --url options specify"
          " AMQP password");

    ci->password = amqp_password;
  }

  if (amqp_vhost) {
    if (ci->vhost)
      die("both --vhost and --url options specify"
          " AMQP vhost");

    ci->vhost = amqp_vhost;
  }

  if (amqp_heartbeat < 0) {
    die("--heartbeat must be a positive value");
  }
}