mirror of
https://github.com/curl/curl.git
synced 2026-04-11 12:01:42 +08:00
lib: add a Curl_bufref_uptr() function and use it
Function Curl_bufref_ptr() now returns a const char *. New function Curl_bufref_uptr() returns a const unsigned char *. Usage and doc updated. Closes #19827
This commit is contained in:
parent
39d1976b7f
commit
f39b8a1174
@ -72,7 +72,15 @@ Returns `CURLE_OK` if successful, else `CURLE_OUT_OF_MEMORY`.
|
||||
## `ptr`
|
||||
|
||||
```c
|
||||
const unsigned char *Curl_bufref_ptr(const struct bufref *br);
|
||||
const char *Curl_bufref_ptr(const struct bufref *br);
|
||||
```
|
||||
|
||||
Returns a `const char *` to the referenced buffer.
|
||||
|
||||
## `uptr`
|
||||
|
||||
```c
|
||||
const unsigned char *Curl_bufref_uptr(const struct bufref *br);
|
||||
```
|
||||
|
||||
Returns a `const unsigned char *` to the referenced buffer.
|
||||
|
||||
14
lib/bufref.c
14
lib/bufref.c
@ -84,7 +84,7 @@ void Curl_bufref_set(struct bufref *br, const void *ptr, size_t len,
|
||||
/*
|
||||
* Get a pointer to the referenced buffer.
|
||||
*/
|
||||
const unsigned char *Curl_bufref_ptr(const struct bufref *br)
|
||||
const unsigned char *Curl_bufref_uptr(const struct bufref *br)
|
||||
{
|
||||
DEBUGASSERT(br);
|
||||
DEBUGASSERT(br->signature == SIGNATURE);
|
||||
@ -93,6 +93,18 @@ const unsigned char *Curl_bufref_ptr(const struct bufref *br)
|
||||
return br->ptr;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get a pointer to the referenced string.
|
||||
*/
|
||||
const char *Curl_bufref_ptr(const struct bufref *br)
|
||||
{
|
||||
DEBUGASSERT(br);
|
||||
DEBUGASSERT(br->signature == SIGNATURE);
|
||||
DEBUGASSERT(br->ptr || !br->len);
|
||||
|
||||
return (const char *) br->ptr;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the length of the referenced buffer data.
|
||||
*/
|
||||
|
||||
@ -39,7 +39,8 @@ struct bufref {
|
||||
void Curl_bufref_init(struct bufref *br);
|
||||
void Curl_bufref_set(struct bufref *br, const void *ptr, size_t len,
|
||||
void (*dtor)(void *));
|
||||
const unsigned char *Curl_bufref_ptr(const struct bufref *br);
|
||||
const char *Curl_bufref_ptr(const struct bufref *br);
|
||||
const unsigned char *Curl_bufref_uptr(const struct bufref *br);
|
||||
size_t Curl_bufref_len(const struct bufref *br);
|
||||
CURLcode Curl_bufref_memdup(struct bufref *br, const void *ptr, size_t len);
|
||||
void Curl_bufref_free(struct bufref *br);
|
||||
|
||||
@ -235,7 +235,7 @@ static CURLcode get_server_message(struct SASL *sasl, struct Curl_easy *data,
|
||||
if(!result && (sasl->params->flags & SASL_FLAG_BASE64)) {
|
||||
unsigned char *msg;
|
||||
size_t msglen;
|
||||
const char *serverdata = (const char *)Curl_bufref_ptr(out);
|
||||
const char *serverdata = Curl_bufref_ptr(out);
|
||||
|
||||
if(!*serverdata || *serverdata == '=')
|
||||
Curl_bufref_set(out, NULL, 0, NULL);
|
||||
@ -263,7 +263,7 @@ static CURLcode build_message(struct SASL *sasl, struct bufref *msg)
|
||||
char *base64;
|
||||
size_t base64len;
|
||||
|
||||
result = curlx_base64_encode(Curl_bufref_ptr(msg),
|
||||
result = curlx_base64_encode(Curl_bufref_uptr(msg),
|
||||
Curl_bufref_len(msg), &base64, &base64len);
|
||||
if(!result)
|
||||
Curl_bufref_set(msg, base64, base64len, curl_free);
|
||||
|
||||
@ -201,7 +201,7 @@ CURLcode Curl_output_ntlm(struct Curl_easy *data, bool proxy)
|
||||
hostname, ntlm, &ntlmmsg);
|
||||
if(!result) {
|
||||
DEBUGASSERT(Curl_bufref_len(&ntlmmsg) != 0);
|
||||
result = curlx_base64_encode(Curl_bufref_ptr(&ntlmmsg),
|
||||
result = curlx_base64_encode(Curl_bufref_uptr(&ntlmmsg),
|
||||
Curl_bufref_len(&ntlmmsg), &base64, &len);
|
||||
if(!result) {
|
||||
curlx_free(*allocuserpwd);
|
||||
@ -219,7 +219,7 @@ CURLcode Curl_output_ntlm(struct Curl_easy *data, bool proxy)
|
||||
result = Curl_auth_create_ntlm_type3_message(data, userp, passwdp,
|
||||
ntlm, &ntlmmsg);
|
||||
if(!result && Curl_bufref_len(&ntlmmsg)) {
|
||||
result = curlx_base64_encode(Curl_bufref_ptr(&ntlmmsg),
|
||||
result = curlx_base64_encode(Curl_bufref_uptr(&ntlmmsg),
|
||||
Curl_bufref_len(&ntlmmsg), &base64, &len);
|
||||
if(!result) {
|
||||
curlx_free(*allocuserpwd);
|
||||
|
||||
@ -636,7 +636,7 @@ static CURLcode imap_perform_authenticate(struct Curl_easy *data,
|
||||
struct imap_conn *imapc =
|
||||
Curl_conn_meta_get(data->conn, CURL_META_IMAP_CONN);
|
||||
CURLcode result = CURLE_OK;
|
||||
const char *ir = (const char *)Curl_bufref_ptr(initresp);
|
||||
const char *ir = Curl_bufref_ptr(initresp);
|
||||
|
||||
if(!imapc)
|
||||
return CURLE_FAILED_INIT;
|
||||
@ -668,8 +668,7 @@ static CURLcode imap_continue_authenticate(struct Curl_easy *data,
|
||||
(void)mech;
|
||||
if(!imapc)
|
||||
return CURLE_FAILED_INIT;
|
||||
return Curl_pp_sendf(data, &imapc->pp,
|
||||
"%s", (const char *)Curl_bufref_ptr(resp));
|
||||
return Curl_pp_sendf(data, &imapc->pp, "%s", Curl_bufref_ptr(resp));
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
|
||||
@ -623,7 +623,7 @@ static CURLcode pop3_perform_auth(struct Curl_easy *data,
|
||||
struct pop3_conn *pop3c =
|
||||
Curl_conn_meta_get(data->conn, CURL_META_POP3_CONN);
|
||||
CURLcode result = CURLE_OK;
|
||||
const char *ir = (const char *)Curl_bufref_ptr(initresp);
|
||||
const char *ir = Curl_bufref_ptr(initresp);
|
||||
|
||||
if(!pop3c)
|
||||
return CURLE_FAILED_INIT;
|
||||
@ -657,8 +657,7 @@ static CURLcode pop3_continue_auth(struct Curl_easy *data,
|
||||
if(!pop3c)
|
||||
return CURLE_FAILED_INIT;
|
||||
|
||||
return Curl_pp_sendf(data, &pop3c->pp,
|
||||
"%s", (const char *) Curl_bufref_ptr(resp));
|
||||
return Curl_pp_sendf(data, &pop3c->pp, "%s", Curl_bufref_ptr(resp));
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
|
||||
@ -506,7 +506,7 @@ static CURLcode smtp_perform_auth(struct Curl_easy *data,
|
||||
CURLcode result = CURLE_OK;
|
||||
struct smtp_conn *smtpc =
|
||||
Curl_conn_meta_get(data->conn, CURL_META_SMTP_CONN);
|
||||
const char *ir = (const char *)Curl_bufref_ptr(initresp);
|
||||
const char *ir = Curl_bufref_ptr(initresp);
|
||||
|
||||
if(!smtpc)
|
||||
return CURLE_FAILED_INIT;
|
||||
@ -539,8 +539,7 @@ static CURLcode smtp_continue_auth(struct Curl_easy *data,
|
||||
(void)mech;
|
||||
if(!smtpc)
|
||||
return CURLE_FAILED_INIT;
|
||||
return Curl_pp_sendf(data, &smtpc->pp,
|
||||
"%s", (const char *)Curl_bufref_ptr(resp));
|
||||
return Curl_pp_sendf(data, &smtpc->pp, "%s", Curl_bufref_ptr(resp));
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
|
||||
@ -69,7 +69,7 @@ CURLcode Curl_auth_create_cram_md5_message(const struct bufref *chlg,
|
||||
|
||||
/* Update the digest with the given challenge */
|
||||
if(Curl_bufref_len(chlg))
|
||||
Curl_HMAC_update(ctxt, Curl_bufref_ptr(chlg),
|
||||
Curl_HMAC_update(ctxt, Curl_bufref_uptr(chlg),
|
||||
curlx_uztoui(Curl_bufref_len(chlg)));
|
||||
|
||||
/* Finalise the digest */
|
||||
|
||||
@ -271,7 +271,7 @@ static CURLcode auth_decode_digest_md5_message(const struct bufref *chlgref,
|
||||
char *alg, size_t alen,
|
||||
char *qop, size_t qlen)
|
||||
{
|
||||
const char *chlg = (const char *)Curl_bufref_ptr(chlgref);
|
||||
const char *chlg = Curl_bufref_ptr(chlgref);
|
||||
|
||||
/* Ensure we have a valid challenge message */
|
||||
if(!Curl_bufref_len(chlgref))
|
||||
|
||||
@ -98,8 +98,7 @@ CURLcode Curl_auth_gsasl_token(struct Curl_easy *data,
|
||||
char *response;
|
||||
size_t outlen;
|
||||
|
||||
res = gsasl_step(gsasl->client,
|
||||
(const char *)Curl_bufref_ptr(chlg), Curl_bufref_len(chlg),
|
||||
res = gsasl_step(gsasl->client, Curl_bufref_ptr(chlg), Curl_bufref_len(chlg),
|
||||
&response, &outlen);
|
||||
if(res != GSASL_OK && res != GSASL_NEEDS_MORE) {
|
||||
failf(data, "GSASL step: %s", gsasl_strerror(res));
|
||||
|
||||
@ -255,7 +255,7 @@ static CURLcode ntlm_decode_type2_target(struct Curl_easy *data,
|
||||
{
|
||||
unsigned short target_info_len = 0;
|
||||
unsigned int target_info_offset = 0;
|
||||
const unsigned char *type2 = Curl_bufref_ptr(type2ref);
|
||||
const unsigned char *type2 = Curl_bufref_uptr(type2ref);
|
||||
size_t type2len = Curl_bufref_len(type2ref);
|
||||
|
||||
#ifdef CURL_DISABLE_VERBOSE_STRINGS
|
||||
@ -355,7 +355,7 @@ CURLcode Curl_auth_decode_ntlm_type2_message(struct Curl_easy *data,
|
||||
*/
|
||||
|
||||
CURLcode result = CURLE_OK;
|
||||
const unsigned char *type2 = Curl_bufref_ptr(type2ref);
|
||||
const unsigned char *type2 = Curl_bufref_uptr(type2ref);
|
||||
size_t type2len = Curl_bufref_len(type2ref);
|
||||
|
||||
#ifdef CURL_DISABLE_VERBOSE_STRINGS
|
||||
|
||||
@ -209,7 +209,7 @@ CURLcode Curl_auth_decode_ntlm_type2_message(struct Curl_easy *data,
|
||||
}
|
||||
|
||||
/* Store the challenge for later use */
|
||||
ntlm->input_token = Curl_memdup0((const char *)Curl_bufref_ptr(type2),
|
||||
ntlm->input_token = Curl_memdup0(Curl_bufref_ptr(type2),
|
||||
Curl_bufref_len(type2));
|
||||
if(!ntlm->input_token)
|
||||
return CURLE_OUT_OF_MEMORY;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user