New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
http: refactor http auth into static functions #12272
Conversation
e726a5a
to
fdbf3d5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Needs a rebase
- Seems to have broken test 1204
authinfo->data->state.authproblem = TRUE; | ||
} | ||
} | ||
return true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use TRUE
and FALSE
(uppercase).
if(handle_spnego(&authinfo)) {} | ||
else if(handle_ntlm(&authinfo)) {} | ||
else if(handle_digest(&authinfo)) {} | ||
else if(handle_basic(&authinfo)) {} | ||
else if(handle_bearer(&authinfo)) {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if(handle_spnego(&authinfo)) {} | |
else if(handle_ntlm(&authinfo)) {} | |
else if(handle_digest(&authinfo)) {} | |
else if(handle_basic(&authinfo)) {} | |
else if(handle_bearer(&authinfo)) {} | |
if(handle_spnego(&authinfo) || | |
handle_ntlm(&authinfo) || | |
handle_digest(&authinfo) || | |
handle_basic(&authinfo) || | |
handle_bearer(&authinfo)) | |
{} |
Saves having to use {}
so many times.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in that case, even the if
is not needed:
handle_spnego(&authinfo) ||
handle_ntlm(&authinfo) ||
handle_digest(&authinfo) ||
handle_basic(&authinfo) ||
handle_bearer(&authinfo);
@bagder Generally speaking would you support factoring out all the authentication specific code into its own interface? For start, I'm thinking of a simple interface like this: (pseudocode) struct authimpl {
const char *name;
bool (*handle)(struct authdata *);
};
// ...
static bool handle_auth_basic(struct authdata *) {
// ...
}
static struct authimpl authimpls[] {
{ "Basic", 5, handle_auth_basic },
{ "Bearer", 5, handle_auth_bearer },
// ...
}
// ...
struct authdata ad = { ... };
for(int i = 0; i < LENGTH(authimpls); i++) {
if (checkauth(authimpls[i].name, auth)) {
authimpls[i].handle(&ad);
break;
}
} In the second iteration I'd like to move the auth methods to their own files and let them build conditionally. This would reduce |
fdbf3d5
to
0965914
Compare
free(authinfo->data->req.newurl); | ||
authinfo->data->req.newurl = strdup(authinfo->data->state.url); | ||
if(!authinfo->data->req.newurl) | ||
return CURLE_OUT_OF_MEMORY; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This returns an error code, not a boolean! You probably need to propagate the error code.
I would. I think that could clean things up nicely! |
Stalled |
Based on #12262 I factored the auth functions out into its own functions. While doing that I noticed that the auth code could be turned into a abstract interface with multiple implementors. Are you peps interested in this?
The changes I currently did are purely cosmetic (given, that the compiler is smart enough to do proper inlining/dead code elimination), but if I'm implementing an abstract interface, this would introduce an indirection between the http code and the http-auth code.
This PR is opened as a draft for now to discuss if my approach makes sense.