示例#1
0
END_TEST

START_TEST(multiple_add_test)
{
  dpl_addrlist_t *addrlist;
  dpl_status_t r;

  /* create the addrlist */
  addrlist = dpl_addrlist_create(NULL);
  dpl_assert_ptr_not_null(addrlist);

  /* add an address */
  r = dpl_addrlist_add_from_str(addrlist, "192.168.1.1:80");
  dpl_assert_int_eq(DPL_SUCCESS, r);
  dpl_assert_int_eq(1, dpl_addrlist_count(addrlist));

  /* adding the same address again is a no-op (well not
   * quite but close enough). */
  r = dpl_addrlist_add_from_str(addrlist, "192.168.1.1:80");
  dpl_assert_int_eq(DPL_SUCCESS, r);
  dpl_assert_int_eq(1, dpl_addrlist_count(addrlist));

  /* an address which is the same IP but a different
   * port counts as a different address */
  r = dpl_addrlist_add_from_str(addrlist, "192.168.1.1:8080");
  dpl_assert_int_eq(DPL_SUCCESS, r);
  dpl_assert_int_eq(2, dpl_addrlist_count(addrlist));

  dpl_addrlist_free(addrlist);
}
示例#2
0
END_TEST

START_TEST(create_from_str_1_test)
{
  dpl_addrlist_t        *addrlist;
  dpl_addr_t            *addrp = NULL;
  dpl_status_t          r;
  char                  *s, ident[INET_ADDRSTRLEN];

  /* create the addrlist */
  addrlist = dpl_addrlist_create_from_str("4244", "192.168.1.1");
  dpl_assert_ptr_not_null(addrlist);

  /* verify length */
  dpl_assert_int_eq(1, dpl_addrlist_count(addrlist));

  /* verify getting elements by index */
  r = dpl_addrlist_get_nth(addrlist, 0, &addrp);
  dpl_assert_int_eq(DPL_SUCCESS, r);
  dpl_assert_ptr_not_null(addrp);
  dpl_assert_str_eq(addrp->host, "192.168.1.1");
  dpl_assert_str_eq(addrp->portstr, "4244");
  dpl_assert_ptr_not_null(addrp->h);
  dpl_assert_int_eq(addrp->h->h_addrtype, AF_INET); 
  inet_ntop(addrp->h->h_addrtype, addrp->h->h_addr, ident, sizeof(ident));
  dpl_assert_str_eq(ident, "192.168.1.1");
  dpl_assert_int_eq(addrp->port, 4244);

  /* indexes wrap modulo the count */
  r = dpl_addrlist_get_nth(addrlist, 1, &addrp);
  dpl_assert_ptr_not_null(addrp);
  dpl_assert_str_eq(addrp->host, "192.168.1.1");
  dpl_assert_str_eq(addrp->portstr, "4244");
  dpl_assert_ptr_not_null(addrp->h);
  dpl_assert_int_eq(addrp->h->h_addrtype, AF_INET); 
  inet_ntop(addrp->h->h_addrtype, addrp->h->h_addr, ident, sizeof(ident));
  dpl_assert_str_eq(ident, "192.168.1.1");
  dpl_assert_int_eq(addrp->port, 4244);

  r = dpl_addrlist_get_nth(addrlist, 347, &addrp);
  dpl_assert_ptr_not_null(addrp);
  dpl_assert_str_eq(addrp->host, "192.168.1.1");
  dpl_assert_str_eq(addrp->portstr, "4244");
  dpl_assert_ptr_not_null(addrp->h);
  dpl_assert_int_eq(addrp->h->h_addrtype, AF_INET); 
  inet_ntop(addrp->h->h_addrtype, addrp->h->h_addr, ident, sizeof(ident));
  dpl_assert_str_eq(ident, "192.168.1.1");
  dpl_assert_int_eq(addrp->port, 4244);

  /* verify the string form of the addrlist */
  s = dpl_addrlist_get(addrlist);
  dpl_assert_str_eq(s, "192.168.1.1:4244");

  free(s);
  dpl_addrlist_free(addrlist);
}
示例#3
0
void
dpl_profile_free(dpl_ctx_t *ctx)
{
  dpl_conn_pool_destroy(ctx);

  dpl_close_event_log(ctx);

  if (NULL != ctx->pricing)
    dpl_pricing_free(ctx);

  if (1 == ctx->use_https)
    {
      SSL_CTX_free(ctx->ssl_ctx);
      BIO_vfree(ctx->ssl_bio_err);
    }

  /*
   * profile
   */
  if (NULL != ctx->addrlist)
    dpl_addrlist_free(ctx->addrlist);
  if (NULL != ctx->base_path)
    free(ctx->base_path);
  if (NULL != ctx->access_key)
    free(ctx->access_key);
  if (NULL != ctx->secret_key)
    free(ctx->secret_key);
  if (NULL != ctx->ssl_cert_file)
    free(ctx->ssl_cert_file);
  if (NULL != ctx->ssl_key_file)
    free(ctx->ssl_key_file);
  if (NULL != ctx->ssl_password)
    free(ctx->ssl_password);
  if (NULL != ctx->ssl_ca_list)
    free(ctx->ssl_ca_list);
  if (NULL != ctx->pricing)
    free(ctx->pricing);
  if (NULL != ctx->encrypt_key)
    free(ctx->encrypt_key);
  if (NULL != ctx->pricing_dir)
    free(ctx->pricing_dir);

  /**/

  if (NULL != ctx->droplet_dir)
    free(ctx->droplet_dir);
  if (NULL != ctx->profile_name)
    free(ctx->profile_name);

  if (NULL != ctx->cwds)
    dpl_dict_free(ctx->cwds);
  if (NULL != ctx->cur_bucket)
    free(ctx->cur_bucket);

}
示例#4
0
END_TEST

/* Passing addrlist=null to various functions fails cleanly */
START_TEST(null_test)
{
  char *s;

  /* dpl_addrlist_get() has an odd return for this corner case, but whatever */
  s = dpl_addrlist_get(NULL);
  dpl_assert_str_eq(s, "");
  free(s);

  dpl_assert_int_eq(0, dpl_addrlist_count(NULL));
  dpl_addrlist_free(NULL);
  dpl_assert_int_eq(DPL_FAILURE, dpl_addrlist_blacklist(NULL, "192.168.1.32", "80", 30));
  dpl_assert_int_eq(DPL_FAILURE, dpl_addrlist_unblacklist(NULL, "192.168.1.32", "80"));
  dpl_assert_int_eq(DPL_FAILURE, dpl_addrlist_set_from_str(NULL, "192.168.1.32"));
  dpl_assert_ptr_null(dpl_addrlist_create_from_str(NULL, NULL));
  dpl_addrlist_lock(NULL);
  dpl_addrlist_unlock(NULL);
  dpl_assert_int_eq(DPL_ENOENT, dpl_addrlist_get_nth(NULL, 1, &s, &s, NULL, NULL));
  dpl_assert_int_eq(DPL_FAILURE, dpl_addrlist_add(NULL, "192.168.1.32", "80"));
}
示例#5
0
END_TEST

START_TEST(default_default_port_test)
{
  dpl_addrlist_t *addrlist;
  dpl_status_t r;
  char *s;

  /* create the addrlist */
  addrlist = dpl_addrlist_create(NULL);
  dpl_assert_ptr_not_null(addrlist);

  r = dpl_addrlist_add_from_str(addrlist, "192.168.1.1");
  dpl_assert_int_eq(DPL_SUCCESS, r);
  dpl_assert_int_eq(1, dpl_addrlist_count(addrlist));

  /* verify the string form of the addrlist */
  s = dpl_addrlist_get(addrlist);
  dpl_assert_str_eq(s, "192.168.1.1:80");

  free(s);
  dpl_addrlist_free(addrlist);
}
示例#6
0
END_TEST

START_TEST(create_from_str_1_test)
{
  dpl_addrlist_t *addrlist;
  char *hoststr = NULL;
  char *portstr = NULL;
  struct in_addr ipaddr;
  u_short port;
  dpl_status_t r;
  char *s;

  /* create the addrlist */
  addrlist = dpl_addrlist_create_from_str("4244", "192.168.1.1");
  dpl_assert_ptr_not_null(addrlist);

  /* verify length */
  dpl_assert_int_eq(1, dpl_addrlist_count(addrlist));

  /* verify getting elements by index */

  hoststr = portstr = NULL;
  memset(&ipaddr, 0, sizeof(ipaddr));
  port = 0;
  r = dpl_addrlist_get_nth(addrlist, 0, &hoststr, &portstr, &ipaddr, &port);
  dpl_assert_int_eq(DPL_SUCCESS, r);
  dpl_assert_str_eq(hoststr, "192.168.1.1");
  dpl_assert_str_eq(portstr, "4244");
  dpl_assert_str_eq(inet_ntoa(ipaddr), "192.168.1.1");
  dpl_assert_int_eq(port, 4244);

  /* indexes wrap modulo the count */

  hoststr = portstr = NULL;
  memset(&ipaddr, 0, sizeof(ipaddr));
  port = 0;
  r = dpl_addrlist_get_nth(addrlist, 1, &hoststr, &portstr, &ipaddr, &port);
  dpl_assert_int_eq(DPL_SUCCESS, r);
  dpl_assert_str_eq(hoststr, "192.168.1.1");
  dpl_assert_str_eq(portstr, "4244");
  dpl_assert_str_eq(inet_ntoa(ipaddr), "192.168.1.1");
  dpl_assert_int_eq(port, 4244);


  hoststr = portstr = NULL;
  memset(&ipaddr, 0, sizeof(ipaddr));
  port = 0;
  r = dpl_addrlist_get_nth(addrlist, 347, &hoststr, &portstr, &ipaddr, &port);
  dpl_assert_int_eq(DPL_SUCCESS, r);
  dpl_assert_str_eq(hoststr, "192.168.1.1");
  dpl_assert_str_eq(portstr, "4244");
  dpl_assert_str_eq(inet_ntoa(ipaddr), "192.168.1.1");
  dpl_assert_int_eq(port, 4244);

  /* verify the string form of the addrlist */
  s = dpl_addrlist_get(addrlist);
  dpl_assert_str_eq(s, "192.168.1.1:4244");

  free(s);
  dpl_addrlist_free(addrlist);
}
示例#7
0
END_TEST

START_TEST(create_from_str_3_test)
{
  dpl_addrlist_t *addrlist;
  char *hoststr = NULL;
  char *portstr = NULL;
  struct in_addr ipaddr;
  u_short port;
  dpl_status_t r;
  int i;
  char *s;
  int port_position[3] = { 0, 0, 0 };
  int port_counts[3] = { 0, 0, 0 };
  char expstr[256] = "";

  /* create the addrlist */
  addrlist = dpl_addrlist_create_from_str("4244",
					  "192.168.1.1:4242,192.168.1.2:4243,192.168.1.3");
  dpl_assert_ptr_not_null(addrlist);

  /* verify length */
  dpl_assert_int_eq(3, dpl_addrlist_count(addrlist));

  /* verify getting elements by index */
  /* indexes wrap modulo the count */

  for (i = 0 ; i < 12 ; i++)
    {
      hoststr = portstr = NULL;
      memset(&ipaddr, 0, sizeof(ipaddr));
      port = 0;
      r = dpl_addrlist_get_nth(addrlist, i, &hoststr, &portstr, &ipaddr, &port);
      dpl_assert_int_eq(DPL_SUCCESS, r);

      fail_unless(port >= 4242, NULL);
      fail_unless(port <= 4244, NULL);
      if (port == 4242)
	{
	  dpl_assert_str_eq(hoststr, "192.168.1.1");
	  dpl_assert_str_eq(portstr, "4242");
	  dpl_assert_str_eq(inet_ntoa(ipaddr), "192.168.1.1");
	  port_counts[0]++;
	}
      else if (port == 4243)
	{
	  dpl_assert_str_eq(hoststr, "192.168.1.2");
	  dpl_assert_str_eq(portstr, "4243");
	  dpl_assert_str_eq(inet_ntoa(ipaddr), "192.168.1.2");
	  port_counts[1]++;
	}
      else /* 4244 */
	{
	  dpl_assert_str_eq(hoststr, "192.168.1.3");
	  dpl_assert_str_eq(portstr, "4244");
	  dpl_assert_str_eq(inet_ntoa(ipaddr), "192.168.1.3");
	  port_counts[2]++;
	}

      if (port_position[i % 3])
	dpl_assert_int_eq(port_position[i % 3], port);
      else
	port_position[i % 3] = port;
    }
  dpl_assert_int_eq(port_counts[0], 4);
  dpl_assert_int_eq(port_counts[1], 4);
  dpl_assert_int_eq(port_counts[2], 4);

  /* verify the string form of the addrlist */
  /* this is tough because the list is randomised internally */

  for (i = 0 ; i < 3 ; i++)
    {
      if (i)
	strcat(expstr, ",");
      if (port_position[i] == 4242)
	strcat(expstr, "192.168.1.1:4242");
      else if (port_position[i] == 4243)
	strcat(expstr, "192.168.1.2:4243");
      else if (port_position[i] == 4244)
	strcat(expstr, "192.168.1.3:4244");
    }

  s = dpl_addrlist_get(addrlist);
  dpl_assert_str_eq(s, expstr);

  free(s);
  dpl_addrlist_free(addrlist);
}
示例#8
0
END_TEST

START_TEST(create_from_str_3_test)
{
  dpl_addrlist_t        *addrlist;
  dpl_addr_t            *addrp = NULL;
  dpl_status_t          r;
  int                   i;
  char                  *s, ident[INET_ADDRSTRLEN];
  int                   port_position[3] = { 0, 0, 0 };
  int                   port_counts[3] = { 0, 0, 0 };
  char                  expstr[256] = "";

  /* create the addrlist */
  addrlist = dpl_addrlist_create_from_str("4244",
					  "192.168.1.1:4242,192.168.1.2:4243,192.168.1.3");
  dpl_assert_ptr_not_null(addrlist);

  /* verify length */
  dpl_assert_int_eq(3, dpl_addrlist_count(addrlist));

  /* verify getting elements by index */
  /* indexes wrap modulo the count */

  for (i = 0; i < 12; i++)
    {
      r = dpl_addrlist_get_nth(addrlist, i, &addrp);
      dpl_assert_int_eq(DPL_SUCCESS, r);
      dpl_assert_ptr_not_null(addrp);
      dpl_assert_ptr_not_null(addrp->h);

      fail_unless(addrp->port >= 4242, NULL);
      fail_unless(addrp->port <= 4244, NULL);

      inet_ntop(addrp->h->h_addrtype, addrp->h->h_addr, ident, sizeof(ident));

      if (addrp->port == 4242)
	{
	  dpl_assert_str_eq(addrp->host, "192.168.1.1");
	  dpl_assert_str_eq(addrp->portstr, "4242");
	  dpl_assert_str_eq(ident, "192.168.1.1");
	  port_counts[0]++;
	}
      else if (addrp->port == 4243)
	{
	  dpl_assert_str_eq(addrp->host, "192.168.1.2");
	  dpl_assert_str_eq(addrp->portstr, "4243");
	  dpl_assert_str_eq(ident, "192.168.1.2");
	  port_counts[1]++;
	}
      else /* 4244 */
	{
	  dpl_assert_str_eq(addrp->host, "192.168.1.3");
	  dpl_assert_str_eq(addrp->portstr, "4244");
	  dpl_assert_str_eq(ident, "192.168.1.3");
	  port_counts[2]++;
	}

      if (port_position[i % 3])
	dpl_assert_int_eq(port_position[i % 3], addrp->port);
      else
	port_position[i % 3] = addrp->port;
    }
  dpl_assert_int_eq(port_counts[0], 4);
  dpl_assert_int_eq(port_counts[1], 4);
  dpl_assert_int_eq(port_counts[2], 4);

  /* verify the string form of the addrlist */
  /* this is tough because the list is randomised internally */

  for (i = 0 ; i < 3 ; i++)
    {
      if (i)
	strcat(expstr, ",");
      if (port_position[i] == 4242)
	strcat(expstr, "192.168.1.1:4242");
      else if (port_position[i] == 4243)
	strcat(expstr, "192.168.1.2:4243");
      else if (port_position[i] == 4244)
	strcat(expstr, "192.168.1.3:4244");
    }

  s = dpl_addrlist_get(addrlist);
  dpl_assert_str_eq(s, expstr);

  free(s);
  dpl_addrlist_free(addrlist);
}