예제 #1
0
 /**
  * Create the SSL context; clean-up existing context if exists
  */
 void create_ssl_context() {
   if (ssl_) {
     cass_ssl_free(ssl_);
     ssl_ = NULL;
   }
   ssl_ = cass_ssl_new();
 }
예제 #2
0
SingleSessionTest::~SingleSessionTest() {
  if (session) {
    CassFuturePtr close_future(cass_session_close(session));
    cass_future_wait(close_future.get());
  }
  if (ssl) {
    cass_ssl_free(ssl);
  }
}
예제 #3
0
  /**
   * Cleanup the driver connection
   */
  void cleanup() {
    if (session_) {
      cass_session_free(session_);
      session_ = NULL;
    }

    if (cluster_) {
      cass_cluster_free(cluster_);
      cluster_ = NULL;
    }

    if (connect_future_) {
      cass_future_free(connect_future_);
      connect_future_ = NULL;
    }

    if (ssl_) {
      cass_ssl_free(ssl_);
      ssl_ = NULL;
    }
  }
예제 #4
0
파일: ssl.c 프로젝트: PlexChat/cpp-driver
int main(int argc, char* argv[]) {
  /* Setup and connect to cluster */
  CassFuture* connect_future = NULL;
  CassCluster* cluster = cass_cluster_new();
  CassSession* session = cass_session_new();
  CassSsl* ssl = cass_ssl_new();
  char* hosts = "127.0.0.1";
  if (argc > 1) {
    hosts = argv[1];
  }

  cass_cluster_set_contact_points(cluster, hosts);

  /* Only verify the certification and not the identity */
  cass_ssl_set_verify_flags(ssl, CASS_SSL_VERIFY_PEER_CERT);

  if (!load_trusted_cert_file("cert.pem", ssl)) {
    fprintf(stderr, "Failed to load certificate disabling peer verification\n");
    cass_ssl_set_verify_flags(ssl, CASS_SSL_VERIFY_NONE);
  }

  cass_cluster_set_ssl(cluster, ssl);

  connect_future = cass_session_connect(session, cluster);

  if (cass_future_error_code(connect_future) == CASS_OK) {
    CassFuture* close_future = NULL;

    /* Build statement and execute query */
    const char* query = "SELECT release_version FROM system.local";
    CassStatement* statement = cass_statement_new(query, 0);

    CassFuture* result_future = cass_session_execute(session, statement);

    if (cass_future_error_code(result_future) == CASS_OK) {
      /* Retrieve result set and get the first row */
      const CassResult* result = cass_future_get_result(result_future);
      const CassRow* row = cass_result_first_row(result);

      if (row) {
        const CassValue* value = cass_row_get_column_by_name(row, "release_version");

        const char* release_version;
        size_t release_version_length;
        cass_value_get_string(value, &release_version, &release_version_length);
        printf("release_version: '%.*s'\n", (int)release_version_length,
               release_version);
      }

      cass_result_free(result);
    } else {
      /* Handle error */
      const char* message;
      size_t message_length;
      cass_future_error_message(result_future, &message, &message_length);
      fprintf(stderr, "Unable to run query: '%.*s'\n", (int)message_length,
                                                            message);
    }

    cass_statement_free(statement);
    cass_future_free(result_future);

    /* Close the session */
    close_future = cass_session_close(session);
    cass_future_wait(close_future);
    cass_future_free(close_future);
  } else {
      /* Handle error */
      const char* message;
      size_t message_length;
      cass_future_error_message(connect_future, &message, &message_length);
      fprintf(stderr, "Unable to connect: '%.*s'\n", (int)message_length,
                                                          message);
  }

  cass_future_free(connect_future);
  cass_cluster_free(cluster);
  cass_session_free(session);
  cass_ssl_free(ssl);

  return 0;
}