You are viewing a plain text version of this content. The canonical link for it is here.
Posted to test-cvs@httpd.apache.org by ja...@apache.org on 2002/09/06 12:16:10 UTC

cvs commit: httpd-test/flood config.h.in flood_round_robin.c

jacekp      2002/09/06 03:16:09

  Modified:    flood    config.h.in flood_round_robin.c
  Log:
  Added basic auth. Following URL:
  <url user="foo" password="bar">http://localhost/auth</url>
  ...causes appropriate Authorization header to be sent.
  
  You have to know when you need auth enabled. Auth challenge (401 header)
  is treated (along with all 4xx type responses) as error.
  
  Revision  Changes    Path
  1.24      +2 -0      httpd-test/flood/config.h.in
  
  Index: config.h.in
  ===================================================================
  RCS file: /home/cvs/httpd-test/flood/config.h.in,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- config.h.in	23 Jul 2002 18:44:07 -0000	1.23
  +++ config.h.in	6 Sep 2002 10:16:09 -0000	1.24
  @@ -28,6 +28,8 @@
   #define XML_URLLIST_PREDELAYPRECISION "predelayprecision"
   #define XML_URLLIST_POSTDELAY "postdelay"
   #define XML_URLLIST_POSTDELAYPRECISION "postdelayprecision"
  +#define XML_URLLIST_USER "user"
  +#define XML_URLLIST_PASSWORD "password"
   #define XML_URLLIST_NAME "name"
   #define XML_PROFILE "profile"
   #define XML_PROFILE_COUNT "count"
  
  
  
  1.29      +36 -0     httpd-test/flood/flood_round_robin.c
  
  Index: flood_round_robin.c
  ===================================================================
  RCS file: /home/cvs/httpd-test/flood/flood_round_robin.c,v
  retrieving revision 1.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- flood_round_robin.c	6 Sep 2002 09:42:56 -0000	1.28
  +++ flood_round_robin.c	6 Sep 2002 10:16:09 -0000	1.29
  @@ -60,6 +60,7 @@
   #include <apr_uri.h>
   #include <apr_lib.h>
   #include <apr_hash.h>
  +#include <apr_base64.h>
   
   #if APR_HAVE_STRINGS_H
   #include <strings.h>    /* strncasecmp */
  @@ -115,6 +116,8 @@
       char *responsetemplate;
       char *responsename;
       int responselen;
  +    char *user;
  +    char *password;
   } url_t;
   
   typedef struct cookie_t {
  @@ -244,7 +247,9 @@
   apr_status_t round_robin_create_req(profile_t *profile, request_t *r)
   {
       round_robin_profile_t *p;
  +    int crdlen;
       char *cookies;
  +    char *enc_credtls, *credtls, *authz_hdr = NULL;
       cookie_t *cook;
      
       p = (round_robin_profile_t*)profile; 
  @@ -271,6 +276,19 @@
       else
           cookies = "";
   
  +    if (p->url[p->current_url].user) {
  +        if (!p->url[p->current_url].password) {
  +            apr_file_printf(local_stderr, "missing password for user '%s'\n", p->url[p->current_url].user);
  +            return APR_EGENERAL;
  +	} else {
  +	    credtls = apr_pstrcat(r->pool, p->url[p->current_url].user, ":", p->url[p->current_url].password, NULL);
  +	    crdlen = strlen(credtls);
  +	    enc_credtls = (char *) apr_palloc(r->pool, apr_base64_encode_len(crdlen) + 1);
  +	    apr_base64_encode(enc_credtls, credtls, crdlen);
  +	    authz_hdr = apr_pstrcat(r->pool, "Authorization: Basic ", enc_credtls, CRLF, NULL);
  +	}
  +    }
  +
       switch (r->method)
       {
       case GET:
  @@ -279,12 +297,14 @@
                                  "User-Agent: Flood/" FLOOD_VERSION CRLF
                                  "Connection: %s" CRLF
                                  "Host: %s" CRLF 
  +                               "%s"
                                  "%s" CRLF,
                                  r->parsed_uri->path, 
                                  r->parsed_uri->query ? "?" : "",
                                  r->parsed_uri->query ? r->parsed_uri->query : "",
                                  r->keepalive ? "Keep-Alive" : "Close",
                                  r->parsed_uri->hostinfo,
  +                               authz_hdr ? authz_hdr : "",
                                  cookies);
           r->rbuftype = POOL;
           r->rbufsize = strlen(r->rbuf);
  @@ -295,12 +315,14 @@
                                  "User-Agent: Flood/" FLOOD_VERSION CRLF
                                  "Connection: %s" CRLF
                                  "Host: %s" CRLF 
  +                               "%s"
                                  "%s" CRLF,
                                  r->parsed_uri->path, 
                                  r->parsed_uri->query ? "?" : "",
                                  r->parsed_uri->query ? r->parsed_uri->query : "",
                                  r->keepalive ? "Keep-Alive" : "Close",
                                  r->parsed_uri->hostinfo,
  +                               authz_hdr ? authz_hdr : "",
                                  cookies);
           r->rbuftype = POOL;
           r->rbufsize = strlen(r->rbuf);
  @@ -315,6 +337,7 @@
                                      "Host: %s" CRLF
                                      "Content-Length: %d" CRLF 
                                      "Content-type: application/x-www-form-urlencoded" CRLF
  +                                   "%s"
                                      "%s" CRLF
                                      "%s",
                                      r->parsed_uri->path, 
  @@ -323,6 +346,7 @@
                                      r->keepalive ? "Keep-Alive" : "Close",
                                      r->parsed_uri->hostinfo,
                                      r->payloadsize,
  +                                   authz_hdr ? authz_hdr : "",
                                      cookies,
                                      (char*)r->payload);
           } else { /* There is no payload, but it's still a POST */
  @@ -332,12 +356,14 @@
                                      "Connection: %s" CRLF
                                      "Host: %s" CRLF
   
  +                                   "%s"
                                      "%s" CRLF "",
                                      r->parsed_uri->path, 
                                      r->parsed_uri->query ? "?" : "",
                                      r->parsed_uri->query ? r->parsed_uri->query : "",
                                      r->keepalive ? "Keep-Alive" : "Close",
                                      r->parsed_uri->hostinfo,
  +                                   authz_hdr ? authz_hdr : "",
                                      cookies);
           }
           r->rbuftype = POOL;
  @@ -468,6 +494,16 @@
                                    FLOOD_STRLEN_MAX) == 0) {
                   url->responsename = (char*)attr->value;
                   url->responselen = strlen((char*)attr->value);
  +            }
  +            else if (strncasecmp(attr->name, 
  +                                 XML_URLLIST_USER,
  +                                 FLOOD_STRLEN_MAX) == 0) {
  +                url->user = (char*)attr->value;
  +            }
  +            else if (strncasecmp(attr->name, 
  +                                 XML_URLLIST_PASSWORD,
  +                                 FLOOD_STRLEN_MAX) == 0) {
  +                url->password = (char*)attr->value;
               }
               attr = attr->next;
           }
  
  
  

Re: cvs commit: httpd-test/flood config.h.in flood_round_robin.c

Posted by Jacek Prucia <ja...@7bulls.com>.
On Fri, 6 Sep 2002 09:43:39 -0700
Justin Erenkrantz <je...@apache.org> wrote:

[...]
> One nitpick is that lines shouldn't be over 80 characters.  So, the
[...]
> We also don't use tabs.  Please remove them in favor of spaces.
> 
> You might want to take a quick glance at:
> 
> http://httpd.apache.org/dev/styleguide.html

Yeah. I did read style guide, but it's pretty hard to switch. I've got
used to a bit different style. Sorry for the style mess. I've already
fixed all my previous commits. Please watch my work for a few weeks
until I'll be '100% style guide' compilatnt :)

regards,
-- 
Jacek Prucia
7bulls.com S.A.
http://www.7bulls.com/


Re: cvs commit: httpd-test/flood config.h.in flood_round_robin.c

Posted by Justin Erenkrantz <je...@apache.org>.
On Fri, Sep 06, 2002 at 10:16:10AM -0000, jacekp@apache.org wrote:
>   @@ -244,7 +247,9 @@
>    apr_status_t round_robin_create_req(profile_t *profile, request_t *r)
>    {
>        round_robin_profile_t *p;
>   +    int crdlen;
>        char *cookies;
>   +    char *enc_credtls, *credtls, *authz_hdr = NULL;
>        cookie_t *cook;
>       
>        p = (round_robin_profile_t*)profile; 
>   @@ -271,6 +276,19 @@
>        else
>            cookies = "";
>    
>   +    if (p->url[p->current_url].user) {
>   +        if (!p->url[p->current_url].password) {
>   +            apr_file_printf(local_stderr, "missing password for user '%s'\n", p->url[p->current_url].user);
>   +            return APR_EGENERAL;
>   +	} else {

One nitpick is that lines shouldn't be over 80 characters.  So, the
apr_file_printf should be:
            apr_file_printf(local_stderr,
                            "missing password for user '%s'\n",
                            p->url[p->current_url].user);

We also don't use tabs.  Please remove them in favor of spaces.

You might want to take a quick glance at:

http://httpd.apache.org/dev/styleguide.html

>   +	    credtls = apr_pstrcat(r->pool, p->url[p->current_url].user, ":", p->url[p->current_url].password, NULL);
>   +	    crdlen = strlen(credtls);
>   +	    enc_credtls = (char *) apr_palloc(r->pool, apr_base64_encode_len(crdlen) + 1);
>   +	    apr_base64_encode(enc_credtls, credtls, crdlen);
>   +	    authz_hdr = apr_pstrcat(r->pool, "Authorization: Basic ", enc_credtls, CRLF, NULL);
>   +	}
>   +    }
>   +

Since crdlen isn't used outside of this else block, it seems that its
declaration should be inside the else block rather than at the
beginning of the function.  And, I'd guess it should be called
credlen - no need to mince one letter. 

Looks good though except for these minor nitpicks.  =)  -- justin