mturk       2004/07/28 23:52:33

  Modified:    ajp/ajplib/test httpd_wrap.h httpd_wrap.c
  Log:
  Added ap_wrap_make_request. This creates an request simulating
  client web browser
  
  Revision  Changes    Path
  1.6       +27 -0     jakarta-tomcat-connectors/ajp/ajplib/test/httpd_wrap.h
  
  Index: httpd_wrap.h
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/ajp/ajplib/test/httpd_wrap.h,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- httpd_wrap.h      28 Jul 2004 16:09:04 -0000      1.5
  +++ httpd_wrap.h      29 Jul 2004 06:52:32 -0000      1.6
  @@ -240,6 +240,16 @@
   #define AP_METHOD_BIT ((apr_int64_t)1)
   /** @} */
   
  +/** default HTTP Server protocol */
  +#define AP_SERVER_PROTOCOL "HTTP/1.1"
  +/** Internal representation for a HTTP protocol number, e.g., HTTP/1.1 */
  +
  +#define HTTP_VERSION(major,minor) (1000*(major)+(minor))
  +/** Major part of HTTP protocol */
  +#define HTTP_VERSION_MAJOR(number) ((number)/1000)
  +/** Minor part of HTTP protocol */
  +#define HTTP_VERSION_MINOR(number) ((number)%1000)
  +
   
   /* fake structure declarations */
   typedef struct process_rec  process_rec;
  @@ -626,6 +636,23 @@
    * create the main process_rec. 
    */
   AP_DECLARE(process_rec *) ap_wrap_create_process(int argc, const char * const 
*argv);
  +
  +/**
  + * Fill the request_rec with data. 
  + * @param r      The current request
  + * @param url    The full url http://[username:[EMAIL PROTECTED]:port]/uri
  + * @param method Method "GET", "POST", etc...
  + * @param content_type The post data content type
  + * @param content_encoding The post data transfer encoding
  + * @param content_length The post data content length
  + * @param content The post content data.
  + * @return APR_SUCCESS or error
  + */
  +AP_DECLARE(apr_status_t) ap_wrap_make_request(request_rec *r, const char *url,
  +                                              const char *method,
  +                                              const char *content_type,
  +                                              const char *content_encoding,
  +                                              apr_size_t content_length, char 
*content);
   
   #ifdef __cplusplus
   }
  
  
  
  1.8       +242 -0    jakarta-tomcat-connectors/ajp/ajplib/test/httpd_wrap.c
  
  Index: httpd_wrap.c
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/ajp/ajplib/test/httpd_wrap.c,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- httpd_wrap.c      28 Jul 2004 16:09:04 -0000      1.7
  +++ httpd_wrap.c      29 Jul 2004 06:52:32 -0000      1.8
  @@ -317,3 +317,245 @@
       /* default */
       return r->server->server_hostname;
   } 
  +
  +#define UNKNOWN_METHOD (-1)
  +
  +static int lookup_builtin_method(const char *method, apr_size_t len)
  +{
  +    /* Note: the following code was generated by the "shilka" tool from
  +       the "cocom" parsing/compilation toolkit. It is an optimized lookup
  +       based on analysis of the input keywords. Postprocessing was done
  +       on the shilka output, but the basic structure and analysis is
  +       from there. Should new HTTP methods be added, then manual insertion
  +       into this code is fine, or simply re-running the shilka tool on
  +       the appropriate input. */
  +
  +    /* Note: it is also quite reasonable to just use our method_registry,
  +       but I'm assuming (probably incorrectly) we want more speed here
  +       (based on the optimizations the previous code was doing). */
  +
  +    switch (len)
  +    {
  +    case 3:
  +        switch (method[0])
  +        {
  +        case 'P':
  +            return (method[1] == 'U'
  +                    && method[2] == 'T'
  +                    ? M_PUT : UNKNOWN_METHOD);
  +        case 'G':
  +            return (method[1] == 'E'
  +                    && method[2] == 'T'
  +                    ? M_GET : UNKNOWN_METHOD);
  +        default:
  +            return UNKNOWN_METHOD;
  +        }
  +
  +    case 4:
  +        switch (method[0])
  +        {
  +        case 'H':
  +            return (method[1] == 'E'
  +                    && method[2] == 'A'
  +                    && method[3] == 'D'
  +                    ? M_GET : UNKNOWN_METHOD);
  +        case 'P':
  +            return (method[1] == 'O'
  +                    && method[2] == 'S'
  +                    && method[3] == 'T'
  +                    ? M_POST : UNKNOWN_METHOD);
  +        case 'M':
  +            return (method[1] == 'O'
  +                    && method[2] == 'V'
  +                    && method[3] == 'E'
  +                    ? M_MOVE : UNKNOWN_METHOD);
  +        case 'L':
  +            return (method[1] == 'O'
  +                    && method[2] == 'C'
  +                    && method[3] == 'K'
  +                    ? M_LOCK : UNKNOWN_METHOD);
  +        case 'C':
  +            return (method[1] == 'O'
  +                    && method[2] == 'P'
  +                    && method[3] == 'Y'
  +                    ? M_COPY : UNKNOWN_METHOD);
  +        default:
  +            return UNKNOWN_METHOD;
  +        }
  +
  +    case 5:
  +        switch (method[2])
  +        {
  +        case 'T':
  +            return (memcmp(method, "PATCH", 5) == 0
  +                    ? M_PATCH : UNKNOWN_METHOD);
  +        case 'R':
  +            return (memcmp(method, "MERGE", 5) == 0
  +                    ? M_MERGE : UNKNOWN_METHOD);
  +        case 'C':
  +            return (memcmp(method, "MKCOL", 5) == 0
  +                    ? M_MKCOL : UNKNOWN_METHOD);
  +        case 'B':
  +            return (memcmp(method, "LABEL", 5) == 0
  +                    ? M_LABEL : UNKNOWN_METHOD);
  +        case 'A':
  +            return (memcmp(method, "TRACE", 5) == 0
  +                    ? M_TRACE : UNKNOWN_METHOD);
  +        default:
  +            return UNKNOWN_METHOD;
  +        }
  +
  +    case 6:
  +        switch (method[0])
  +        {
  +        case 'U':
  +            switch (method[5])
  +            {
  +            case 'K':
  +                return (memcmp(method, "UNLOCK", 6) == 0
  +                        ? M_UNLOCK : UNKNOWN_METHOD);
  +            case 'E':
  +                return (memcmp(method, "UPDATE", 6) == 0
  +                        ? M_UPDATE : UNKNOWN_METHOD);
  +            default:
  +                return UNKNOWN_METHOD;
  +            }
  +        case 'R':
  +            return (memcmp(method, "REPORT", 6) == 0
  +                    ? M_REPORT : UNKNOWN_METHOD);
  +        case 'D':
  +            return (memcmp(method, "DELETE", 6) == 0
  +                    ? M_DELETE : UNKNOWN_METHOD);
  +        default:
  +            return UNKNOWN_METHOD;
  +        }
  +
  +    case 7:
  +        switch (method[1])
  +        {
  +        case 'P':
  +            return (memcmp(method, "OPTIONS", 7) == 0
  +                    ? M_OPTIONS : UNKNOWN_METHOD);
  +        case 'O':
  +            return (memcmp(method, "CONNECT", 7) == 0
  +                    ? M_CONNECT : UNKNOWN_METHOD);
  +        case 'H':
  +            return (memcmp(method, "CHECKIN", 7) == 0
  +                    ? M_CHECKIN : UNKNOWN_METHOD);
  +        default:
  +            return UNKNOWN_METHOD;
  +        }
  +
  +    case 8:
  +        switch (method[0])
  +        {
  +        case 'P':
  +            return (memcmp(method, "PROPFIND", 8) == 0
  +                    ? M_PROPFIND : UNKNOWN_METHOD);
  +        case 'C':
  +            return (memcmp(method, "CHECKOUT", 8) == 0
  +                    ? M_CHECKOUT : UNKNOWN_METHOD);
  +        default:
  +            return UNKNOWN_METHOD;
  +        }
  +
  +    case 9:
  +        return (memcmp(method, "PROPPATCH", 9) == 0
  +                ? M_PROPPATCH : UNKNOWN_METHOD);
  +
  +    case 10:
  +        switch (method[0])
  +        {
  +        case 'U':
  +            return (memcmp(method, "UNCHECKOUT", 10) == 0
  +                    ? M_UNCHECKOUT : UNKNOWN_METHOD);
  +        case 'M':
  +            return (memcmp(method, "MKACTIVITY", 10) == 0
  +                    ? M_MKACTIVITY : UNKNOWN_METHOD);
  +        default:
  +            return UNKNOWN_METHOD;
  +        }
  +
  +    case 11:
  +        return (memcmp(method, "MKWORKSPACE", 11) == 0
  +                ? M_MKWORKSPACE : UNKNOWN_METHOD);
  +
  +    case 15:
  +        return (memcmp(method, "VERSION-CONTROL", 15) == 0
  +                ? M_VERSION_CONTROL : UNKNOWN_METHOD);
  +
  +    case 16:
  +        return (memcmp(method, "BASELINE-CONTROL", 16) == 0
  +                ? M_BASELINE_CONTROL : UNKNOWN_METHOD);
  +
  +    default:
  +        return UNKNOWN_METHOD;
  +    }
  +
  +    /* NOTREACHED */
  +}
  +
  +AP_DECLARE(apr_status_t) ap_wrap_make_request(request_rec *r, const char *url,
  +                                              const char *method,
  +                                              const char *content_type,
  +                                              const char *content_encoding,
  +                                              apr_size_t content_length, char 
*content)
  +{
  +    apr_status_t rc;
  +
  +    if (!url) {
  +        ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "Missing url");
  +        return APR_EINVAL;
  +    }
  +    if (!method)
  +        method = "GET";
  +    if ((r->method_number == lookup_builtin_method(method, strlen(method))) ==
  +                                UNKNOWN_METHOD) {
  +        ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "Unknown HTTP metdod %s",
  +                      method);
  +        return APR_EINVAL;
  +    }
  +    r->method = method;
  +    r->protocol = AP_SERVER_PROTOCOL;
  +    r->proto_num = HTTP_VERSION(1, 1);
  +
  +    if ((rc = apr_uri_parse(r->pool, url, &r->parsed_uri)) != APR_SUCCESS) {
  +        ap_log_rerror(APLOG_MARK, APLOG_ERR, rc, r, "error parsing uri");
  +        return APR_EINVAL;
  +    }
  +    r->user = r->parsed_uri.user;
  +    r->content_type = content_type;
  +    r->content_encoding = content_encoding;
  +    r->uri = r->parsed_uri.path;
  +    if (r->parsed_uri.query)
  +        r->unparsed_uri = apr_pstrcat(r->pool, r->parsed_uri.path, "?",
  +                                      r->parsed_uri.query, NULL);
  +    else
  +        r->unparsed_uri = r->uri;
  +    if (!r->parsed_uri.port)
  +        r->parsed_uri.port = r->server->port;
  +    
  +    if (r->parsed_uri.hostname) {
  +        if (r->parsed_uri.port)
  +        apr_table_addn(r->headers_in, "Host",
  +            apr_psprintf(r->pool, "%s:%d", r->parsed_uri.hostname, 
r->parsed_uri.port));
  +        else
  +            apr_table_addn(r->headers_in, "Host", r->parsed_uri.hostname);
  +    }
  +    if (r->content_type)
  +        apr_table_addn(r->headers_in, "Content-Type", r->content_type);
  +    if (r->content_encoding)
  +        apr_table_addn(r->headers_in, "Transfer-Encoding", r->content_encoding);
  +    if (content_length)
  +        apr_table_addn(r->headers_in, "Content-Length", apr_itoa(r->pool,
  +                                                       (int)content_length));
  +    apr_table_addn(r->headers_in, "Accept", "*/*");
  +    apr_table_addn(r->headers_in, "Pragma", "no-cache");
  +    apr_table_addn(r->headers_in, "User-Agent", "httpd-wrap/1.0");
  +    apr_table_addn(r->headers_in, "Accept-Charset", "iso-8859-2");
  +    apr_table_addn(r->headers_in, "Accept-Language", "hr");
  +
  +    /* TODO: create bucket brigade for post data */
  +
  +    return APR_SUCCESS;
  +}
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to