Skip to content

Commit

Permalink
Add customized impersonate function
Browse files Browse the repository at this point in the history
  • Loading branch information
perklet committed Jan 9, 2024
1 parent 2d06ce8 commit 2c199f1
Showing 1 changed file with 53 additions and 11 deletions.
64 changes: 53 additions & 11 deletions lib/easy.c
Original file line number Diff line number Diff line change
Expand Up @@ -343,25 +343,19 @@ CURLsslset curl_global_sslset(curl_sslbackend id, const char *name,
return rc;
}


/*
* curl-impersonate:
* Call curl_easy_setopt() with all the needed options as defined in the
* 'impersonations' array.
* Actually call curl_easy_setopt() with all the needed options
* */
CURLcode curl_easy_impersonate(struct Curl_easy *data, const char *target,
int default_headers)
CURLcode _do_impersonate(struct Curl_easy *data,
const struct impersonate_opts *opts,
int default_headers)
{
int i;
int ret;
const struct impersonate_opts *opts = NULL;
struct curl_slist *headers = NULL;

for(opts = impersonations; opts->target != NULL; opts++) {
if (strcasecompare(target, opts->target)) {
break;
}
}

if(opts->target == NULL) {
DEBUGF(fprintf(stderr, "Error: unknown impersonation target '%s'\n",
target));
Expand Down Expand Up @@ -483,6 +477,54 @@ CURLcode curl_easy_impersonate(struct Curl_easy *data, const char *target,
return CURLE_OK;
}


/*
* curl-impersonate:
* Call curl_easy_setopt() with all the needed options as defined by the target
* */
CURLcode curl_easy_impersonate_customized(struct Curl_easy *data,
const struct impersonate_opts *opts,
int default_headers)
{
int ret;

ret = _do_impersonate(data, opts, default_headers)
if(ret)
return ret;

return CURLE_OK;
}

/*
* curl-impersonate:
* Call curl_easy_setopt() with all the needed options as defined in the
* 'impersonations' array.
* */
CURLcode curl_easy_impersonate(struct Curl_easy *data, const char *target,
int default_headers)
{
int ret;
const struct impersonate_opts *opts = NULL;

for(opts = impersonations; opts->target != NULL; opts++) {
if (strcasecompare(target, opts->target)) {
break;
}
}

if(opts->target == NULL) {
DEBUGF(fprintf(stderr, "Error: unknown impersonation target '%s'\n",
target));
return CURLE_BAD_FUNCTION_ARGUMENT;
}

ret = _do_impersonate(data, opts, default_headers)
if(ret)
return ret;

return CURLE_OK;
}

/*
* curl_easy_init() is the external interface to alloc, setup and init an
* easy handle that is returned. If anything goes wrong, NULL is returned.
Expand Down

0 comments on commit 2c199f1

Please sign in to comment.