pier        01/07/19 16:53:41

  Modified:    webapp/lib pr_warp.c
  Log:
  Readded request handling.
  
  Revision  Changes    Path
  1.10      +182 -4    jakarta-tomcat-connectors/webapp/lib/pr_warp.c
  
  Index: pr_warp.c
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/webapp/lib/pr_warp.c,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- pr_warp.c 2001/07/18 19:19:26     1.9
  +++ pr_warp.c 2001/07/19 23:53:41     1.10
  @@ -54,7 +54,7 @@
    *                                                                           *
    * ========================================================================= */
   
  -/* @version $Id: pr_warp.c,v 1.9 2001/07/18 19:19:26 pier Exp $ */
  +/* @version $Id: pr_warp.c,v 1.10 2001/07/19 23:53:41 pier Exp $ */
   #include "pr_warp.h"
   
   /* Initialize this provider. */
  @@ -73,8 +73,11 @@
           wa_debug(WA_MARK,"Opening connection \"%s\"",curr->name);
           if (n_connect(curr)==wa_true) {
               wa_debug(WA_MARK,"Connection \"%s\" opened",curr->name);
  -            if (n_configure(curr)==wa_true)
  +            if (c_configure(curr)==wa_true) {
                   wa_debug(WA_MARK,"Connection \"%s\" configured",curr->name);
  +            } else {
  +                wa_log(WA_MARK,"Cannot configure connection \"%s\"",curr->name);
  +            }
           } else wa_log(WA_MARK,"Cannot open connection \"%s\"",curr->name);
           elem=elem->next;
       }
  @@ -185,9 +188,184 @@
       return(apr_psprintf(pool,"Application ID: %d",(int)(appl->conf)));
   }
   
  +/* Transmit headers */
  +static int headers(void *d, const char *n, const char *v) {
  +    warp_header *data=(warp_header *)d;
  +    wa_connection *conn=data->conn;
  +    warp_config *conf=(warp_config *)conn->conf;
  +    warp_packet *pack=data->pack;
  +
  +    pack->type=TYPE_REQ_HEADER;
  +    p_write_string(pack,(char *)n);
  +    p_write_string(pack,(char *)v);
  +    if (n_send(conf->sock,pack)!=wa_true) {
  +        data->fail=wa_true;
  +        return(FALSE);
  +    }
  +    wa_debug(WA_MARK,"Req. header %s: %s",n,v);
  +    return(TRUE);
  +}
  +
   /* Handle a connection from the web server. */
  -static int warp_handle(wa_request *r, wa_application *a) {
  -    return(wa_rerror(WA_MARK,r,500,"Not yet implemented"));
  +static int warp_handle(wa_request *r, wa_application *appl) {
  +    warp_header *h=(warp_header *)apr_palloc(r->pool,sizeof(warp_header));
  +    wa_connection *conn=appl->conn;
  +    warp_config *conf=(warp_config *)conn->conf;
  +    warp_packet *pack=p_create(r->pool);
  +    int status=0;
  +
  +    // Check packet
  +    if (pack==NULL)
  +        return(wa_rerror(WA_MARK,r,500,"Cannot create WARP packet"));
  +
  +    // Check application
  +    if (((int)(appl->conf))==-1)
  +        return(wa_rerror(WA_MARK,r,404,"Application not deployed"));
  +
  +    // Attempt to reconnect if disconnected
  +    if (conf->sock==NULL) {
  +        if (n_connect(conn)==wa_true) {
  +            wa_debug(WA_MARK,"Connection \"%s\" opened",conn->name);
  +            if (c_configure(conn)==wa_true) {
  +                wa_debug(WA_MARK,"Connection \"%s\" configured",conn->name);
  +            } else {
  +                wa_log(WA_MARK,"Cannot configure connection %s",conn->name);
  +                return(wa_rerror(WA_MARK,r,500,
  +                                 "Cannot configure connection \"%s\"",
  +                                 conn->name));
  +            }
  +        } else {
  +            wa_log(WA_MARK,"Cannot open connection %s",conn->name);
  +            return(wa_rerror(WA_MARK,r,500,"Cannot open connection %s",
  +                             conn->name));
  +        }
  +    }
  +
  +    // Let's do it
  +    pack->type=TYPE_REQ_INIT;
  +    p_write_int(pack,(int)(appl->conf));
  +    p_write_string(pack,r->meth);
  +    p_write_string(pack,r->ruri);
  +    p_write_string(pack,r->args);
  +    p_write_string(pack,r->prot);
  +    if (n_send(conf->sock,pack)!=wa_true) {
  +        n_disconnect(conn);
  +        return(wa_rerror(WA_MARK,r,500,"Communitcation interrupted"));
  +    } else {
  +        wa_debug(WA_MARK,"Req. %s %s %s",r->meth,r->ruri,r->prot);
  +    }
  +    
  +    p_reset(pack);
  +    pack->type=TYPE_REQ_CONTENT;
  +    p_write_string(pack,r->ctyp);
  +    p_write_int(pack,r->clen);
  +    if (n_send(conf->sock,pack)!=wa_true) {
  +        n_disconnect(conn);
  +        return(wa_rerror(WA_MARK,r,500,"Communitcation interrupted"));
  +    } else {
  +        wa_debug(WA_MARK,"Req. content typ=%s len=%d",r->ctyp,r->clen);
  +    }
  +
  +    if (r->schm!=NULL) {
  +        p_reset(pack);
  +        pack->type=TYPE_REQ_SCHEME;
  +        p_write_string(pack,r->schm);
  +        if (n_send(conf->sock,pack)!=wa_true) {
  +            n_disconnect(conn);
  +            return(wa_rerror(WA_MARK,r,500,"Communitcation interrupted"));
  +        } else {
  +            wa_debug(WA_MARK,"Req. scheme %s",r->schm);
  +        }
  +    }
  +
  +    if ((r->user!=NULL)||(r->auth!=NULL)) {
  +        p_reset(pack);
  +        pack->type=TYPE_REQ_AUTH;
  +        if (r->user==NULL) r->user="\0";
  +        if (r->auth==NULL) r->auth="\0";
  +        p_write_string(pack,r->user); 
  +        p_write_string(pack,r->auth); 
  +        if (n_send(conf->sock,pack)!=wa_true) {
  +            n_disconnect(conn);
  +            return(wa_rerror(WA_MARK,r,500,"Communitcation interrupted"));
  +        } else {
  +            wa_debug(WA_MARK,"Req. user %s auth %s",r->user,r->auth);
  +        }
  +    }
  +
  +    /* The request headers */
  +    h->conn=conn;
  +    h->pack=pack;
  +    h->fail=wa_false;
  +    apr_table_do(headers,h,r->hdrs,NULL);
  +    if (h->fail==wa_true) {
  +        n_disconnect(conn);
  +        return(wa_rerror(WA_MARK,r,500,"Communitcation interrupted"));
  +    }
  +
  +    p_reset(pack);
  +    pack->type=TYPE_REQ_PROCEED;
  +    if (n_send(conf->sock,pack)!=wa_true) {
  +        n_disconnect(conn);
  +        return(wa_rerror(WA_MARK,r,500,"Communitcation interrupted"));
  +    }
  +
  +    
  +    while (1) {
  +        if (n_recv(conf->sock,pack)!=wa_true) {
  +            n_disconnect(conn);
  +            return(wa_rerror(WA_MARK,r,500,"Communitcation interrupted"));
  +        }
  +        switch (pack->type) {
  +            case TYPE_RES_STATUS: {
  +                char *prot=NULL;
  +                char *mesg=NULL;
  +                p_read_string(pack,&prot);
  +                p_read_ushort(pack,&status);
  +                p_read_string(pack,&mesg);
  +                wa_debug(WA_MARK,"=== %s %d %s",prot,status,mesg);
  +                wa_rsetstatus(r,status);
  +                break;
  +            }
  +            case TYPE_RES_HEADER: {
  +                char *name=NULL;
  +                char *valu=NULL;
  +                p_read_string(pack,&name);
  +                p_read_string(pack,&valu);
  +                if (strcasecmp("content-type",name)==0)
  +                    wa_rsetctype(r,valu);
  +                else wa_rsetheader(r,name,valu);
  +                wa_debug(WA_MARK,"=== %s: %s",name,valu);
  +                break;
  +            }
  +            case TYPE_RES_COMMIT: {
  +                wa_rcommit(r);
  +                wa_debug(WA_MARK,"=== ");
  +                break;
  +            }
  +            case TYPE_RES_BODY: {
  +                wa_rwrite(r,pack->buff,pack->size);
  +                wa_rflush(r);
  +                pack->buff[pack->size]='\0';
  +                wa_debug(WA_MARK,"=== %s",pack->buff);
  +                break;
  +            }
  +            case TYPE_RES_DONE: {
  +                wa_debug(WA_MARK,"=== DONE ===");
  +                return(status);
  +                break;
  +            }
  +            case TYPE_ERROR: {
  +                char *mesg=NULL;
  +                p_read_string(pack,&mesg);
  +                return(wa_rerror(WA_MARK,r,500,"%s",mesg));
  +            }
  +            default: {
  +                n_disconnect(conn);
  +                return(wa_rerror(WA_MARK,r,500,"Invalid packet %d",pack->type));
  +            }
  +        }           
  +    }
   }
   
   /* The list of all configured connections */
  
  
  

Reply via email to