Exemplo n.º 1
0
void test_curl_get_() {
	CURLres *res;
	char* hs[] = { "abc:jjj", "jfdd:ss" };
	printf("<--------------test_curl_get_---------------->\n");
	res = curl_get("http://www.baidu.com", 0, 0);
	if (res->ccode) {
		printf("ccode:%d\n", res->ccode);
	} else {
		printf("------------------------------>\n");
		printf("abc:%ld,%d\n", strlen(res->rdata), res->rcode);
		curl_sres_head(res);
	}
	curl_free_res(&res);
	//
	res = curl_get("http://www.baidu.com", hs, 2);
	if (res->ccode) {
		printf("ccode:%d\n", res->ccode);
	} else {
		printf("------------------------------>\n");
		printf("abc:%ld,%d\n", strlen(res->rdata), res->rcode);
		curl_sres_head(res);
	}
	curl_free_res(&res);
	//
	res = curl_get("http://wwk", 0, 0);
	printf("ccode:%d\n", res->ccode);
	curl_free_res(&res);
}
Exemplo n.º 2
0
void t05_server_timeout_threaded_ssl(){
  INIT_LOCAL();
  CURL *curl=prepare_curl("https://localhost:8081");

  ONION_DEBUG("%s",__FUNCTION__);
  o=onion_new(O_THREADED | O_DETACH_LISTEN);
  onion_set_root_handler(o,onion_handler_new((void*)process_request,NULL,NULL));
  FAIL_IF_NOT_EQUAL_INT(onion_set_certificate(o, O_SSL_CERTIFICATE_KEY, "mycert.pem", "mycert.pem"),0);
  onion_set_port(o,"8081");
  onion_set_timeout(o,3000);
  onion_listen(o);
  sleep(1);

  int fd=connect_to("localhost","8081");
  sleep(4);
  // Should have closed the connection
  int w=write(fd,"GET /\n\n",7);
  FAIL_IF_NOT_EQUAL_INT(w,7);
  char data[256];
  FAIL_IF(read(fd, data,sizeof(data))>0);
  close(fd);

  FAIL_IF_NOT(curl_get(curl, "https://localhost:8081"));

	onion_free(o);

	curl_easy_cleanup(curl);
  END_LOCAL();
}
Exemplo n.º 3
0
char *retrieve_public_file_as_buffer (const char *uri, size_t *len,
				      int *err)
{
    char *buf = NULL;

    if (proto_length(uri) == 0) {
	*err = E_DATA;
	return NULL;
    } else {
	urlinfo u;

	urlinfo_init(&u, NULL, SAVE_TO_BUFFER, NULL);
	urlinfo_set_url(&u, uri);
	*err = curl_get(&u);
	urlinfo_finalize(&u, &buf, err);
	*len = (*err)? 0 : u.datalen;
    }

    if (*err) {
	const char *s = gretl_errmsg_get();

	if (*s == '\0') {
	    /* no error message in place */
	    gretl_errmsg_sprintf("%s\ndownload failed", uri);
	}
    }

    return buf;
}
Exemplo n.º 4
0
void t04_server_timeout_threaded(){
  INIT_LOCAL();
  CURL *curl=prepare_curl("http://localhost:8082");

  o=onion_new(O_THREADED | O_DETACH_LISTEN);
  onion_set_root_handler(o,onion_handler_new((void*)process_request,NULL,NULL));
  onion_set_port(o,"8082");
  onion_set_timeout(o,2000);
  onion_listen(o);
  sleep(1);

  int fd=connect_to("localhost","8082");
  sleep(3);
  // Should have closed the connection
  int w=write(fd,"GET /\n\n",7);
  FAIL_IF_NOT_EQUAL_INT(w,7);
  char data[256];
  FAIL_IF(read(fd, data,sizeof(data))>0);
  close(fd);

  FAIL_IF_NOT(curl_get(curl, "http://localhost:8082"));

  onion_free(o);
	curl_easy_cleanup(curl);
  END_LOCAL();
}
Exemplo n.º 5
0
void xbmc_sendkey(uint32_t keysym)
{
    char url[256];

    snprintf(url, 255,
            "http://localhost:%d/xbmcCmds/xbmcHttp?command=SendKey(%d)",
            port, keysym);
    curl_get(url);
}
Exemplo n.º 6
0
void xbmc_sendaction(uint32_t action)
{
    char url[256];

    snprintf(url, 255,
            "http://localhost:%d/xbmcCmds/xbmcHttp?command=Action(%d)",
            port, action);
    curl_get(url);

}
Exemplo n.º 7
0
void
config_load_region(void)
{
	BUFFER *bufResponse = buffer_create();

	if (!curl_get(bufResponse, URL)) {
		buffer_destroy(bufResponse);
		return;
	}

	buffer_substr(bufResponse, 0, -1);

	config_set_region(buffer_data(bufResponse));

	buffer_destroy(bufResponse);
}
Exemplo n.º 8
0
int retrieve_public_file (const char *uri, char *localname)
{
    int pl = proto_length(uri);
    int err = 0;

    if (pl == 0) {
	return E_DATA;
    } else if (*localname == '\0') {
	/* extract the filename from the uri */
	const char *s = strrchr(uri + pl, '/');

	if (s == NULL || *(s+1) == '\0') {
	    err = E_DATA;
	} else {
	    /* save to user's dotdir by default */
	    strcat(localname, gretl_dotdir());
	    strcat(localname, s + 1);
	}
    }

    if (!err) {
	urlinfo u;

	urlinfo_init(&u, NULL, SAVE_TO_FILE, localname);
	urlinfo_set_url(&u, uri);
	if (gretl_in_gui_mode()) {
	    urlinfo_set_show_progress(&u);
	}
	err = curl_get(&u);
	urlinfo_finalize(&u, NULL, &err);
    }

    if (err) {
	const char *s = gretl_errmsg_get();

	if (*s == '\0') {
	    /* no error message in place */
	    gretl_errmsg_sprintf("%s\ndownload failed", uri);
	}
    } else {
	err = check_downloaded_file(localname, uri);
    }

    return err;
}
Exemplo n.º 9
0
void t03_server_https(){
  INIT_LOCAL();
  CURL *curl=prepare_curl("https://localhost:8080");

  o=onion_new(O_ONE_LOOP | O_DETACH_LISTEN);
  onion_set_root_handler(o,onion_handler_new((void*)process_request,NULL,NULL));
  FAIL_IF_NOT_EQUAL_INT(onion_set_certificate(o, O_SSL_CERTIFICATE_KEY, "mycert.pem", "mycert.pem"),0);
  FAIL_IF_NOT_EQUAL_INT(onion_listen(o),0);
  //do_petition_set(1,1,1,1);
  sleep(1);
  //FAIL_IF_EQUAL_INT(  curl_get_to_fail("http://localhost:8080"), HTTP_OK);
  sleep(1);
  FAIL_IF_NOT_EQUAL_INT(  curl_get(curl, "https://localhost:8080"), HTTP_OK);
  sleep(1);
  onion_free(o);

	curl_easy_cleanup(curl);
  END_LOCAL();
}
Exemplo n.º 10
0
int get_update_info (char **saver, int verbose)
{
    urlinfo u;
    int err = 0;

    urlinfo_init(&u, gretlhost, SAVE_TO_BUFFER, NULL);
    strcat(u.url, updatecgi);

    if (verbose) {
	strcat(u.url, "?opt=MANUAL_QUERY");
    } else {
	strcat(u.url, "?opt=QUERY");
    } 

    err = curl_get(&u);
    urlinfo_finalize(&u, saver, &err);

    return err;
}
Exemplo n.º 11
0
void *do_requests(params_t *t){
	const char *url="http://localhost:8080/";
	CURL *curl=prepare_curl(url);

  ONION_DEBUG("Do %d petitions",t->n_requests);
  int i;
  usleep(t->wait_s*1000000);
  for(i=0;i<t->n_requests;i++){
    curl_get(curl, url);
    usleep(t->wait_t*1000000);
  }
  if (t->close_at_n==1){
    usleep(t->wait_s*1000000);
    onion_listen_stop(o);
  }

	curl_easy_cleanup(curl);

  return NULL;
}
Exemplo n.º 12
0
static int retrieve_url (const char *hostname, 
			 CGIOpt opt, 
			 const char *fname, 
			 const char *dbseries, 
			 const char *localfile,
			 int filter,
			 char **getbuf)
{
    int saveopt = SAVE_NONE;
    urlinfo u;
    int err = 0;

    maybe_revise_www_paths();

    if (getbuf != NULL) {
	*getbuf = NULL;
	saveopt = SAVE_TO_BUFFER;
    } else if (localfile != NULL) {
	saveopt = SAVE_TO_FILE;
    }

    urlinfo_init(&u, hostname, saveopt, localfile);

    if (opt == GRAB_FOREIGN || opt == QUERY_SF) {
	strcat(u.url, fname);
    } else if (opt == GRAB_PDF) {
	strcat(u.url, manual_path);
	strcat(u.url, fname);
    } else if (opt == GRAB_PKG) {
	strcat(u.url, dataset_path);
	strcat(u.url, fname);
    } else if (opt == GRAB_FILE) {
	strcat(u.url, updatecgi);
    } else if (opt == LIST_PKGS) {
	strcat(u.url, datapkg_list);
    } else {
	strcat(u.url, datacgi);
    }

    if (opt == LIST_CATS) {
	/* getting gfn tags listing for GUI */
	u.timeout = 8;
    }

    if (strstr(gretlhost, "ricardo") == NULL) {
	fprintf(stderr, "using gretlhost = '%s'\n", gretlhost);
    }

    if (opt != GRAB_PDF && opt != GRAB_FOREIGN &&
	opt != GRAB_PKG && opt != QUERY_SF &&
	opt != LIST_PKGS) {
	/* a gretl-server download */
	urlinfo_set_params(&u, opt, fname, dbseries, filter);
    }

    if (progress_bar_wanted(opt)) {
	urlinfo_set_show_progress(&u);
    }

    err = curl_get(&u);

    urlinfo_finalize(&u, getbuf, &err);

    return err;
}