Cryptography Reference
In-Depth Information
char *login_sep, *colon_sep, *trailer_sep;
// Technically, the user should start the proxy spec with
// “http://”. But, be forgiving if he didn't.
if ( !strncmp( “http://”, proxy_spec, 7 ) )
{
proxy_spec += 7;
}
In Listing 1-11, check to see if an authentication string has been supplied. If the @
symbol appears in the proxy_spec , it must be preceded by a “username:password”
pair. If it is, parse those out; if it isn't, there's no error because the username and
password are not strictly required.
Listing 1-11: “http.c” parse_proxy_param (continued)
login_sep = strchr( proxy_spec, '@' );
if ( login_sep )
{
colon_sep = strchr( proxy_spec, ':' );
if ( !colon_sep || ( colon_sep > login_sep ) )
{
// Error - if username supplied, password must be supplied.
fprintf( stderr, “Expected password in '%s'\n”, proxy_spec );
return 0;
}
*colon_sep = '\0';
*proxy_user = proxy_spec;
*login_sep = '\0';
*proxy_password = colon_sep + 1;
proxy_spec = login_sep + 1;
}
Notice that, if a username and password are supplied, you modify the proxy_
spec parameter to point to the character after the @ . This way, proxy_spec now
points to the proxy host whether an authentication string was supplied or not.
Listing 1-12 shows the rest of the proxy parameter parsing — the user can
supply a port number if the proxy is listening on a non-standard port.
Listing 1-12: “http.c” parse_proxy_param (continued)
// If the user added a “/” on the end (as they sometimes do),
// just ignore it.
trailer_sep = strchr( proxy_spec, '/' );
if ( trailer_sep )
{
*trailer_sep = '\0';
}
colon_sep = strchr( proxy_spec, ':' );
if ( colon_sep )
(Continued)
Search WWH ::




Custom Search