Exemplo n.º 1
0
Arquivo: lib1560.c Projeto: curl/curl
static int get_parts(void)
{
  int i;
  CURLUcode rc;
  CURLU *urlp;
  int error = 0;
  for(i = 0; get_parts_list[i].in && !error; i++) {
    urlp = curl_url();
    if(!urlp) {
      error++;
      break;
    }
    rc = curl_url_set(urlp, CURLUPART_URL,
                      get_parts_list[i].in,
                      get_parts_list[i].urlflags);
    if(rc != get_parts_list[i].ucode) {
      fprintf(stderr, "Get parts\nin: %s\nreturned %d (expected %d)\n",
              get_parts_list[i].in, (int)rc, get_parts_list[i].ucode);
      error++;
    }
    else if(get_parts_list[i].ucode) {
      /* the expected error happened */
    }
    else if(checkparts(urlp, get_parts_list[i].in, get_parts_list[i].out,
                       get_parts_list[i].getflags))
      error++;
    curl_url_cleanup(urlp);
  }
  return error;
}
Exemplo n.º 2
0
static int lcurl_url_cleanup(lua_State *L){
  lcurl_url_t *p = lcurl_geturl(L);

  if (p->url){
    curl_url_cleanup(p->url);
    p->url = NULL;
  }

  return 0;
}
Exemplo n.º 3
0
Arquivo: lib1560.c Projeto: curl/curl
static int append(void)
{
  int i;
  CURLUcode rc;
  CURLU *urlp;
  int error = 0;
  for(i = 0; append_list[i].in && !error; i++) {
    urlp = curl_url();
    if(!urlp) {
      error++;
      break;
    }
    rc = curl_url_set(urlp, CURLUPART_URL,
                      append_list[i].in,
                      append_list[i].urlflags);
    if(rc)
      error++;
    else
      rc = curl_url_set(urlp, CURLUPART_QUERY,
                        append_list[i].q,
                        append_list[i].qflags | CURLU_APPENDQUERY);
    if(error)
      ;
    else if(rc != append_list[i].ucode) {
      fprintf(stderr, "Append\nin: %s\nreturned %d (expected %d)\n",
              append_list[i].in, (int)rc, append_list[i].ucode);
      error++;
    }
    else if(append_list[i].ucode) {
      /* the expected error happened */
    }
    else {
      char *url;
      rc = curl_url_get(urlp, CURLUPART_URL, &url, 0);
      if(rc) {
        fprintf(stderr, "%s:%d Get URL returned %d\n",
                __FILE__, __LINE__, (int)rc);
        error++;
      }
      else {
        if(checkurl(url, append_list[i].out)) {
          error++;
        }
        curl_free(url);
      }
    }
    curl_url_cleanup(urlp);
  }
  return error;
}
Exemplo n.º 4
0
Arquivo: lib1560.c Projeto: curl/curl
static int set_parts(void)
{
  int i;
  CURLUcode rc;
  int error = 0;

  for(i = 0; set_parts_list[i].set && !error; i++) {
    char *url = NULL;
    CURLU *urlp = curl_url();
    if(!urlp) {
      error++;
      break;
    }
    if(set_parts_list[i].in)
      rc = curl_url_set(urlp, CURLUPART_URL, set_parts_list[i].in,
                        set_parts_list[i].urlflags);
    else
      rc = CURLUE_OK;
    if(!rc) {
      CURLUcode uc = updateurl(urlp, set_parts_list[i].set,
                               set_parts_list[i].setflags);

      if(uc != set_parts_list[i].pcode) {
        fprintf(stderr, "updateurl\nin: %s\nreturned %d (expected %d)\n",
                set_parts_list[i].set, (int)uc, set_parts_list[i].pcode);
        error++;
      }

      rc = curl_url_get(urlp, CURLUPART_URL, &url, 0);

      if(rc) {
        fprintf(stderr, "%s:%d Get URL returned %d\n",
                __FILE__, __LINE__, (int)rc);
        error++;
      }
      else if(checkurl(url, set_parts_list[i].out)) {
        error++;
      }
    }
    else if(rc != set_parts_list[i].ucode) {
      fprintf(stderr, "Set parts\nin: %s\nreturned %d (expected %d)\n",
              set_parts_list[i].in, (int)rc, set_parts_list[i].ucode);
      error++;
    }
    curl_free(url);
    curl_url_cleanup(urlp);
  }
  return error;
}
Exemplo n.º 5
0
Arquivo: lib1560.c Projeto: curl/curl
static int set_url(void)
{
  int i;
  CURLUcode rc;
  CURLU *urlp;
  int error = 0;

  for(i = 0; set_url_list[i].in && !error; i++) {
    char *url = NULL;
    urlp = curl_url();
    if(!urlp)
      break;
    rc = curl_url_set(urlp, CURLUPART_URL, set_url_list[i].in,
                      set_url_list[i].urlflags);
    if(!rc) {
      rc = curl_url_set(urlp, CURLUPART_URL, set_url_list[i].set,
                        set_url_list[i].setflags);
      if(rc) {
        fprintf(stderr, "%s:%d Set URL %s returned %d\n",
                __FILE__, __LINE__, set_url_list[i].set,
                (int)rc);
        error++;
      }
      else {
        rc = curl_url_get(urlp, CURLUPART_URL, &url, 0);
        if(rc) {
          fprintf(stderr, "%s:%d Get URL returned %d\n",
                  __FILE__, __LINE__, (int)rc);
          error++;
        }
        else {
          if(checkurl(url, set_url_list[i].out)) {
            error++;
          }
        }
      }
      curl_free(url);
    }
    else if(rc != set_url_list[i].ucode) {
      fprintf(stderr, "Set URL\nin: %s\nreturned %d (expected %d)\n",
              set_url_list[i].in, (int)rc, set_url_list[i].ucode);
      error++;
    }
    curl_url_cleanup(urlp);
  }
  return error;
}
Exemplo n.º 6
0
int main(void)
{
  CURLU *h;
  CURLUcode uc;
  char *host;
  char *path;

  h = curl_url(); /* get a handle to work with */
  if(!h)
    return 1;

  /* parse a full URL */
  uc = curl_url_set(h, CURLUPART_URL, "http://example.com/path/index.html", 0);
  if(uc)
    goto fail;

  /* extract host name from the parsed URL */
  uc = curl_url_get(h, CURLUPART_HOST, &host, 0);
  if(!uc) {
    printf("Host name: %s\n", host);
    curl_free(host);
  }

  /* extract the path from the parsed URL */
  uc = curl_url_get(h, CURLUPART_PATH, &path, 0);
  if(!uc) {
    printf("Path: %s\n", path);
    curl_free(path);
  }

  /* redirect with a relative URL */
  uc = curl_url_set(h, CURLUPART_URL, "../another/second.html", 0);
  if(uc)
    goto fail;

  /* extract the new, updated path */
  uc = curl_url_get(h, CURLUPART_PATH, &path, 0);
  if(!uc) {
    printf("Path: %s\n", path);
    curl_free(path);
  }

  fail:
  curl_url_cleanup(h); /* free url handle */
  return 0;
}
Exemplo n.º 7
0
int test(char *URL)
{
  CURL *handle = NULL;
  CURLcode res = 0;
  CURLU *urlp = NULL;
  CURLUcode uc = 0;

  global_init(CURL_GLOBAL_ALL);
  easy_init(handle);

  urlp = curl_url();

  if(!urlp) {
    fprintf(stderr, "problem init URL api.");
    goto test_cleanup;
  }

  uc = curl_url_set(urlp, CURLUPART_URL, URL, 0);
  if(uc) {
    fprintf(stderr, "problem setting CURLUPART_URL.");
    goto test_cleanup;
  }

  /* demonstrate override behavior */
  easy_setopt(handle, CURLOPT_URL, "http://www.example.com");

  easy_setopt(handle, CURLOPT_CURLU, urlp);
  easy_setopt(handle, CURLOPT_VERBOSE, 1L);

  res = curl_easy_perform(handle);

  if(res) {
    fprintf(stderr, "%s:%d curl_easy_perform() failed with code %d (%s)\n",
            __FILE__, __LINE__, res, curl_easy_strerror(res));
    goto test_cleanup;
  }

test_cleanup:

  curl_url_cleanup(urlp);
  curl_easy_cleanup(handle);
  curl_global_cleanup();

  return res;
}
Exemplo n.º 8
0
Arquivo: lib1560.c Projeto: curl/curl
static int scopeid(void)
{
  CURLU *u;
  int error = 0;
  CURLUcode rc;
  char *url;

  u = curl_url();
  rc = curl_url_set(u, CURLUPART_URL,
                    "https://[fe80::20c:29ff:fe9c:409b%25eth0]/hello.html", 0);
  if(rc != CURLUE_OK) {
    fprintf(stderr, "%s:%d curl_url_set returned %d\n",
            __FILE__, __LINE__, (int)rc);
    error++;
  }

  rc = curl_url_get(u, CURLUPART_HOST, &url, 0);
  if(rc != CURLUE_OK) {
    fprintf(stderr, "%s:%d curl_url_get CURLUPART_HOST returned %d\n",
            __FILE__, __LINE__, (int)rc);
    error++;
  }
  else {
    printf("we got %s\n", url);
    curl_free(url);
  }

  rc = curl_url_set(u, CURLUPART_HOST, "[::1]", 0);
  if(rc != CURLUE_OK) {
    fprintf(stderr, "%s:%d curl_url_set CURLUPART_HOST returned %d\n",
            __FILE__, __LINE__, (int)rc);
    error++;
  }

  rc = curl_url_get(u, CURLUPART_URL, &url, 0);
  if(rc != CURLUE_OK) {
    fprintf(stderr, "%s:%d curl_url_get CURLUPART_URL returned %d\n",
            __FILE__, __LINE__, (int)rc);
    error++;
  }
  else {
    printf("we got %s\n", url);
    curl_free(url);
  }

  rc = curl_url_set(u, CURLUPART_HOST, "example.com", 0);
  if(rc != CURLUE_OK) {
    fprintf(stderr, "%s:%d curl_url_set CURLUPART_HOST returned %d\n",
            __FILE__, __LINE__, (int)rc);
    error++;
  }

  rc = curl_url_get(u, CURLUPART_URL, &url, 0);
  if(rc != CURLUE_OK) {
    fprintf(stderr, "%s:%d curl_url_get CURLUPART_URL returned %d\n",
            __FILE__, __LINE__, (int)rc);
    error++;
  }
  else {
    printf("we got %s\n", url);
    curl_free(url);
  }

  rc = curl_url_set(u, CURLUPART_HOST,
                    "[fe80::20c:29ff:fe9c:409b%25eth0]", 0);
  if(rc != CURLUE_OK) {
    fprintf(stderr, "%s:%d curl_url_set CURLUPART_HOST returned %d\n",
            __FILE__, __LINE__, (int)rc);
    error++;
  }

  rc = curl_url_get(u, CURLUPART_URL, &url, 0);
  if(rc != CURLUE_OK) {
    fprintf(stderr, "%s:%d curl_url_get CURLUPART_URL returned %d\n",
            __FILE__, __LINE__, (int)rc);
    error++;
  }
  else {
    printf("we got %s\n", url);
    curl_free(url);
  }

  rc = curl_url_get(u, CURLUPART_HOST, &url, 0);
  if(rc != CURLUE_OK) {
    fprintf(stderr, "%s:%d curl_url_get CURLUPART_HOST returned %d\n",
            __FILE__, __LINE__, (int)rc);
    error++;
  }
  else {
    printf("we got %s\n", url);
    curl_free(url);
  }

  rc = curl_url_get(u, CURLUPART_ZONEID, &url, 0);
  if(rc != CURLUE_OK) {
    fprintf(stderr, "%s:%d curl_url_get CURLUPART_ZONEID returned %d\n",
            __FILE__, __LINE__, (int)rc);
    error++;
  }
  else {
    printf("we got %s\n", url);
    curl_free(url);
  }

  rc = curl_url_set(u, CURLUPART_ZONEID, "clown", 0);
  if(rc != CURLUE_OK) {
    fprintf(stderr, "%s:%d curl_url_set CURLUPART_ZONEID returned %d\n",
            __FILE__, __LINE__, (int)rc);
    error++;
  }

  rc = curl_url_get(u, CURLUPART_URL, &url, 0);
  if(rc != CURLUE_OK) {
    fprintf(stderr, "%s:%d curl_url_get CURLUPART_URL returned %d\n",
            __FILE__, __LINE__, (int)rc);
    error++;
  }
  else {
    printf("we got %s\n", url);
    curl_free(url);
  }

  curl_url_cleanup(u);

  return error;
}