- if(argv(0) == "curl")
- {
- float do_exec;
- string do_cvar;
- float key;
- float i, j;
- string url;
- float buf;
- float r;
-
- do_exec = FALSE;
- do_cvar = string_null;
- key = -1;
-
- for(i = 1; i+1 < argc; ++i)
- {
- if(argv(i) == "--cvar" && i+2 < argc)
- {
- ++i;
- do_cvar = strzone(argv(i));
- continue;
- }
- if(argv(i) == "--exec")
- {
- do_exec = TRUE;
- continue;
- }
- if(argv(i) == "--key" && i+2 < argc)
- {
- ++i;
- key = stof(argv(i));
- continue;
- }
- break;
- }
-
- // now, argv(i) is the URL
- // following args may be POST parameters
- url = argv(i);
- ++i;
- buf = buf_create();
- j = 0;
- for(; i+1 < argc; i += 2)
- bufstr_set(buf, ++j, sprintf("%s=%s", uri_escape(argv(i)), uri_escape(argv(i+1))));
- if(i < argc)
- bufstr_set(buf, ++j, sprintf("submit=%s", uri_escape(argv(i))));
-
- if(j == 0) // no args: GET
- r = crypto_uri_postbuf(url, URI_GET_CURL + curl_uri_get_pos, string_null, string_null, -1, key);
- else // with args: POST
- r = crypto_uri_postbuf(url, URI_GET_CURL + curl_uri_get_pos, "application/x-www-form-urlencoded", "&", buf, key);
-
- if(r)
- {
- curl_uri_get_exec[curl_uri_get_pos] = do_exec;
- curl_uri_get_cvar[curl_uri_get_pos] = do_cvar;
- curl_uri_get_pos = mod(curl_uri_get_pos + 1, URI_GET_CURL_END - URI_GET_CURL + 1);
- }
- else
- print(_("error creating curl handle\n"));
-
- buf_del(buf);
-