コード例 #1
0
ファイル: test_gns_proxy.c プロジェクト: tg-x/gnunet
static void
curl_task (void *cls,
	  const struct GNUNET_SCHEDULER_TaskContext *tc)
{
  curl_task_id = NULL;
  curl_main ();
}
コード例 #2
0
ファイル: test_gns_proxy.c プロジェクト: tg-x/gnunet
static void
start_curl (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
  GNUNET_asprintf (&url,
		   "http://%s:%d/hello_world",
		   TEST_DOMAIN, PORT);
  curl = curl_easy_init ();
  curl_easy_setopt (curl, CURLOPT_URL, url);
  curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, &copy_buffer);
  curl_easy_setopt (curl, CURLOPT_WRITEDATA, &cbc);
  curl_easy_setopt (curl, CURLOPT_FAILONERROR, 1);
  curl_easy_setopt (curl, CURLOPT_TIMEOUT, 150L);
  curl_easy_setopt (curl, CURLOPT_CONNECTTIMEOUT, 15L);
  curl_easy_setopt (curl, CURLOPT_NOSIGNAL, 1);
  curl_easy_setopt (curl, CURLOPT_PROXY, "socks5h://127.0.0.1:7777");

  multi = curl_multi_init ();
  GNUNET_assert (multi != NULL);
  GNUNET_assert (CURLM_OK == curl_multi_add_handle (multi, curl));
  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Beginning HTTP download from `%s'\n", url);
  curl_main ();
}
コード例 #3
0
static int scp_convert(int argc, char* argv[]) {
    int argc2 = 0;
    int i = 1;
    char** argv2 = (char**) malloc((argc + 2) * sizeof(char*));
    char* localFileName = NULL;
    char* distantFileName = NULL;
    char* protocol = argv[0];
    argv2[0] = strdup("curl");
    for (i = 1, argc2 = 1; i < argc; i++, argc2++) {
        // it's just a flag:
        if ((argv[i][0] == '-') || (distantFileName && localFileName)) { argv2[argc2] = strdup(argv[i]); continue; } 
        char* position;
        if ((position = strstr(argv[i], ":")) != NULL) {
            // distant file
            distantFileName = position + 1; // after the ":"
            *position = 0; // split argv[i] into "user@host" and distantFileName
            asprintf(argv2 + argc2, "%s://%s/%s", protocol, argv[i], distantFileName);
            // get the actual filename
            while ((position = strstr(distantFileName, "/")) != NULL) distantFileName = position + 1;
        } else {
            // Not beginning with "-", not containing ":", must be a local filename
            // if it's ".", replace with -O
            // if it's a directory, add name of file from previous argument at the end.
            localFileName = argv[i];
            if (!distantFileName) {
                // local file before remote file: upload
                argv2[argc2] = strdup("-T"); argc2++;
                argv2[argc2] = strdup(argv[i]);
            } else { // download
                if ((strlen(argv[i]) == 1) && (strcmp(argv[i], ".") == 0)) argv2[argc2] = strdup("-O");
                else {
                    argv2[argc2] = strdup("-o"); argc2++;
                    if (argv[i][strlen(argv[i]) - 1] == '/') {
                        // if localFileName ends with '/' we assume it's a directory
                        asprintf(argv2 + argc2, "%s%s", localFileName, distantFileName);
                    } else {
                        struct stat localFileBuf;
                        bool localFileExists = (stat(localFileName, &localFileBuf) == 0);
                        int localFileIsDir = S_ISDIR(localFileBuf.st_mode);
                        if (localFileExists && localFileIsDir) {
                            // localFileName exists *and* is a directory: concatenate distantFileName to directory
                            asprintf(argv2 + argc2, "%s/%s", localFileName, distantFileName);
                        } else {
                            // all other cases: localFileName is name of output
                            argv2[argc2] = strdup(argv[i]);
                        }
                    }
                }
            }
        }
    }
    argv2[argc2] = NULL;
#ifdef BLINKSHELL
    int returnValue = curl_static_main(argc2, argv2);
#else
    int returnValue = curl_main(argc2, argv2);
#endif
    for (int i = 0; i < argc2; i++) free(argv2[i]);
    free(argv2);
    return returnValue;
}