Esempio n. 1
0
struct curl_hash*
Curl_hash_alloc(int slots,
                hash_function hfunc,
                comp_function comparator,
                curl_hash_dtor dtor)
{
    struct curl_hash *h;

    if (!slots || !hfunc || !comparator || !dtor)
    {
        return NULL; /* failure */
    }

    h = malloc(sizeof(struct curl_hash));
    if (h)
    {
        if (Curl_hash_init(h, slots, hfunc, comparator, dtor))
        {
            /* failure */
            free(h);
            h = NULL;
        }
    }

    return h;
}
Esempio n. 2
0
void Curl_global_host_cache_init(void)
{
  if (!host_cache_initialized) {
    Curl_hash_init(&hostname_cache, 7, Curl_freednsinfo);
    host_cache_initialized = 1;
  }
}
Esempio n. 3
0
/*
 * Curl_global_host_cache_init() initializes and sets up a global DNS cache.
 * Global DNS cache is general badness. Do not use. This will be removed in
 * a future version. Use the share interface instead!
 */
void Curl_global_host_cache_init(void)
{
  if (!host_cache_initialized) {
    Curl_hash_init(&hostname_cache, 7, Curl_hash_str, Curl_str_key_compare,
                   freednsentry);
    host_cache_initialized = 1;
  }
}
Esempio n. 4
0
/*
 * Curl_global_host_cache_init() initializes and sets up a global DNS cache.
 * Global DNS cache is general badness. Do not use. This will be removed in
 * a future version. Use the share interface instead!
 *
 * Returns a struct curl_hash pointer on success, NULL on failure.
 */
struct curl_hash *Curl_global_host_cache_init(void)
{
  int rc = 0;
  if(!host_cache_initialized) {
    rc = Curl_hash_init(&hostname_cache, 7, Curl_hash_str,
                        Curl_str_key_compare, freednsentry);
    if(!rc)
      host_cache_initialized = 1;
  }
  return rc?NULL:&hostname_cache;
}
Esempio n. 5
0
File: hash.c Progetto: B-Rich/CMake
struct curl_hash *
Curl_hash_alloc(int slots, curl_hash_dtor dtor)
{
    struct curl_hash *h;

    h = (struct curl_hash *) malloc(sizeof(struct curl_hash));
    if (h) {
        if(Curl_hash_init(h, slots, dtor)) {
            /* failure */
            free(h);
            h = NULL;
        }
    }

    return h;
}
Esempio n. 6
0
int Curl_conncache_init(struct conncache *connc, int size)
{
  int rc;

  /* allocate a new easy handle to use when closing cached connections */
  connc->closure_handle = curl_easy_init();
  if(!connc->closure_handle)
    return 1; /* bad */

  rc = Curl_hash_init(&connc->hash, size, Curl_hash_str,
                      Curl_str_key_compare, free_bundle_hash_entry);
  if(rc) {
    Curl_close(connc->closure_handle);
    connc->closure_handle = NULL;
  }
  else
    connc->closure_handle->state.conn_cache = connc;

  return rc;
}
Esempio n. 7
0
static CURLcode unit_setup(void)
{
  return Curl_hash_init(&hash_static, 7, Curl_hash_str,
                        Curl_str_key_compare, mydtor);
}
Esempio n. 8
0
int Curl_conncache_init(struct conncache *connc, int size)
{
  return Curl_hash_init(&connc->hash, size, Curl_hash_str,
                        Curl_str_key_compare, free_bundle_hash_entry);
}
Esempio n. 9
0
File: hostip.c Progetto: 54chen/curl
/*
 * Curl_mk_dnscache() inits a new DNS cache and returns success/failure.
 */
int Curl_mk_dnscache(struct curl_hash *hash)
{
  return Curl_hash_init(hash, 7, Curl_hash_str, Curl_str_key_compare,
                        freednsentry);
}
Esempio n. 10
0
/*
 * Initialize nghttp2 for a Curl connection
 */
CURLcode Curl_http2_init(struct connectdata *conn)
{
  if(!conn->proto.httpc.h2) {
    int rc;
    nghttp2_session_callbacks *callbacks;

    conn->proto.httpc.inbuf = malloc(H2_BUFSIZE);
    if(conn->proto.httpc.inbuf == NULL)
      return CURLE_OUT_OF_MEMORY;

    rc = nghttp2_session_callbacks_new(&callbacks);

    if(rc) {
      failf(conn->data, "Couldn't initialize nghttp2 callbacks!");
      return CURLE_OUT_OF_MEMORY; /* most likely at least */
    }

    /* nghttp2_send_callback */
    nghttp2_session_callbacks_set_send_callback(callbacks, send_callback);
    /* nghttp2_on_frame_recv_callback */
    nghttp2_session_callbacks_set_on_frame_recv_callback
      (callbacks, on_frame_recv);
    /* nghttp2_on_invalid_frame_recv_callback */
    nghttp2_session_callbacks_set_on_invalid_frame_recv_callback
      (callbacks, on_invalid_frame_recv);
    /* nghttp2_on_data_chunk_recv_callback */
    nghttp2_session_callbacks_set_on_data_chunk_recv_callback
      (callbacks, on_data_chunk_recv);
    /* nghttp2_before_frame_send_callback */
    nghttp2_session_callbacks_set_before_frame_send_callback
      (callbacks, before_frame_send);
    /* nghttp2_on_frame_send_callback */
    nghttp2_session_callbacks_set_on_frame_send_callback
      (callbacks, on_frame_send);
    /* nghttp2_on_frame_not_send_callback */
    nghttp2_session_callbacks_set_on_frame_not_send_callback
      (callbacks, on_frame_not_send);
    /* nghttp2_on_stream_close_callback */
    nghttp2_session_callbacks_set_on_stream_close_callback
      (callbacks, on_stream_close);
    /* nghttp2_on_begin_headers_callback */
    nghttp2_session_callbacks_set_on_begin_headers_callback
      (callbacks, on_begin_headers);
    /* nghttp2_on_header_callback */
    nghttp2_session_callbacks_set_on_header_callback(callbacks, on_header);

    /* The nghttp2 session is not yet setup, do it */
    rc = nghttp2_session_client_new(&conn->proto.httpc.h2, callbacks, conn);

    nghttp2_session_callbacks_del(callbacks);

    if(rc) {
      failf(conn->data, "Couldn't initialize nghttp2!");
      return CURLE_OUT_OF_MEMORY; /* most likely at least */
    }

    rc = Curl_hash_init(&conn->proto.httpc.streamsh, 7, Curl_hash_str,
                        Curl_str_key_compare, freestreamentry);
    if(rc) {
      failf(conn->data, "Couldn't init stream hash!");
      return CURLE_OUT_OF_MEMORY; /* most likely at least */
    }
  }
  return CURLE_OK;
}
Esempio n. 11
0
{
  int *ptr = (int*)p;
  free(ptr);
}

UNITTEST_START
  int *value;
  int *value2;
  size_t klen = sizeof(int);

  struct curl_hash hash_static;
  int key = 20;
  int key2 = 25;
  int rc = 0;

  rc = Curl_hash_init(&hash_static, 7, Curl_hash_str,
                        Curl_str_key_compare, mydtor);

  if(rc)
  {
    fail("Curl_hash_init failed to initialize static hash!");
    goto unit_test_abort;
  }

  value = malloc(sizeof(int));
  value2 = malloc(sizeof(int));

  *value = 199;
  *value2 = 204;
  Curl_hash_add(&hash_static, &key, klen, value);
  
  Curl_hash_clean(&hash_static);