pier        01/07/18 12:08:35

  Modified:    webapp/lib .cvsignore Makefile.in pr_warp.c
  Added:       webapp/lib pr_warp.h pr_warp_config.c pr_warp_network.c
                        pr_warp_packet.c
  Log:
  Splitting WARP provider into several separate files to enhance maintainability
  
  Revision  Changes    Path
  1.5       +6 -0      jakarta-tomcat-connectors/webapp/lib/.cvsignore
  
  Index: .cvsignore
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/webapp/lib/.cvsignore,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- .cvsignore        2001/07/13 02:33:27     1.4
  +++ .cvsignore        2001/07/18 19:08:35     1.5
  @@ -7,6 +7,12 @@
   pr_info.o
   pr_warp.lo
   pr_warp.o
  +pr_warp_config.lo
  +pr_warp_config.o
  +pr_warp_network.lo
  +pr_warp_network.o
  +pr_warp_packet.lo
  +pr_warp_packet.o
   wa_config.lo
   wa_config.o
   wa_main.lo
  
  
  
  1.12      +6 -2      jakarta-tomcat-connectors/webapp/lib/Makefile.in
  
  Index: Makefile.in
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/webapp/lib/Makefile.in,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- Makefile.in       2001/07/13 02:08:42     1.11
  +++ Makefile.in       2001/07/18 19:08:35     1.12
  @@ -56,12 +56,16 @@
   # ========================================================================= #
   
   # @author  Pier Fumagalli <mailto:[EMAIL PROTECTED]>
  -# @version $Id: Makefile.in,v 1.11 2001/07/13 02:08:42 pier Exp $
  +# @version $Id: Makefile.in,v 1.12 2001/07/18 19:08:35 pier Exp $
   
   include @SRCDIR@/Makedefs
   
   OBJS = wa_main.lo wa_config.lo wa_request.lo
  -PROVS = pr_info.lo pr_warp.lo
  +PROVS = pr_info.lo \
  +     pr_warp.lo \
  +     pr_warp_packet.lo \
  +     pr_warp_network.lo \
  +     pr_warp_config.lo
   
   LIB = libwebapp.la
   
  
  
  
  1.7       +2 -348    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.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- pr_warp.c 2001/07/15 08:39:58     1.6
  +++ pr_warp.c 2001/07/18 19:08:35     1.7
  @@ -54,359 +54,13 @@
    *                                                                           *
    * ========================================================================= */
   
  -/* @version $Id: pr_warp.c,v 1.6 2001/07/15 08:39:58 pier Exp $ */
  -#include <wa.h>
  +/* @version $Id: pr_warp.c,v 1.7 2001/07/18 19:08:35 pier Exp $ */
  +#include "pr_warp.h"
   
  -/* ************************************************************************* */
  -/* STRUCTURES AND FUNCTIONS DECLARATION                                      */
  -/* ************************************************************************* */
  -
  -/* The WARP connection configuration structure */
  -typedef struct warp_config {
  -    apr_sockaddr_t *addr;
  -    apr_socket_t *sock;
  -    int serv;
  -} warp_config;
  -
  -/* The WARP packet structure */
  -typedef struct warp_packet {
  -    apr_pool_t *pool;
  -    int type;
  -    int size;
  -    int curr;
  -    char buff[65536];
  -} warp_packet;
  -
  -/* WARP definitions */
  -#define VERS_MAJOR 0
  -#define VERS_MINOR 9
  -
  -#define TYPE_INVALID -1
  -#define TYPE_ERROR   0x00
  -#define TYPE_FATAL   0xff
  -
  -#define TYPE_CONF_WELCOME 0x01
  -#define TYPE_CONF_DEPLOY  0x02
  -#define TYPE_CONF_APPLIC  0x03
  -#define TYPE_CONF_DONE    0x04
  -
  -
   /* The list of all configured connections */
   static wa_chain *warp_connections=NULL;
   /* The list of all deployed connections */
   static wa_chain *warp_applications=NULL;
  -/* This provider */
  -wa_provider wa_provider_warp;
  -
  -/* ************************************************************************* */
  -/* PACKET FUNCTIONS                                                          */
  -/* ************************************************************************* */
  -static void p_reset(warp_packet *pack) {
  -    pack->type=TYPE_INVALID;
  -    pack->type=TYPE_INVALID;
  -    pack->size=0;
  -    pack->curr=0;
  -    pack->buff[0]='\0';
  -}
  -
  -static warp_packet *p_create(apr_pool_t *pool) {
  -    warp_packet *pack=NULL;
  -
  -    if (pool==NULL) return(NULL);
  -    pack=(warp_packet *)apr_palloc(pool,sizeof(warp_packet));
  -    pack->pool=pool;
  -    p_reset(pack);
  -    return(pack);
  -}
  -
  -static wa_boolean p_read_ushort(warp_packet *pack, int *x) {
  -    int k=0;
  -
  -    if ((pack->curr+2)>=pack->size) return(wa_false);
  -    k=(pack->buff[pack->curr++]&0x0ff)<<8;
  -    k=k|(pack->buff[pack->curr++]&0x0ff);
  -    *x=k;
  -    return(wa_true);
  -}
  -
  -static wa_boolean p_read_int(warp_packet *pack, int *x) {
  -    int k=0;
  -
  -    if ((pack->curr+2)>=pack->size) return(wa_false);
  -    k=(pack->buff[pack->curr++]&0x0ff)<<24;
  -    k=k|((pack->buff[pack->curr++]&0x0ff)<<16);
  -    k=k|((pack->buff[pack->curr++]&0x0ff)<<8);
  -    k=k|(pack->buff[pack->curr++]&0x0ff);
  -    *x=k;
  -    return(wa_true);
  -}
  -
  -static wa_boolean p_read_string(warp_packet *pack, char **x) {
  -    int len=0;
  -
  -    if (p_read_ushort(pack,&len)==wa_false) {
  -        *x=NULL;
  -        return(wa_false);
  -    }
  -    if ((pack->curr+len)>=pack->size) {
  -        *x=NULL;
  -        return(wa_false);
  -    }
  -
  -    *x=(char *)apr_palloc(pack->pool,(len+1)*sizeof(char));
  -    if (*x==NULL) return(wa_false);
  -
  -    apr_cpystrn(*x,&pack->buff[pack->curr],len);
  -    pack->curr+=len;
  -    return(wa_true);
  -}
  -
  -static wa_boolean p_write_ushort(warp_packet *pack, int x) {
  -    if (pack->size>65533) return(wa_false);
  -    pack->buff[pack->size++]=(x>>8)&0x0ff;
  -    pack->buff[pack->size++]=x&0x0ff;
  -    return(wa_true);
  -}
  -
  -static wa_boolean p_write_int(warp_packet *pack, int x) {
  -    if (pack->size>65531) return(wa_false);
  -    pack->buff[pack->size++]=(x>>24)&0x0ff;
  -    pack->buff[pack->size++]=(x>>16)&0x0ff;
  -    pack->buff[pack->size++]=(x>>8)&0x0ff;
  -    pack->buff[pack->size++]=x&0x0ff;
  -    return(wa_true);
  -}
  -
  -static wa_boolean p_write_string(warp_packet *pack, char *x) {
  -    int len=0;
  -    char *k=NULL;
  -    int q=0;
  -
  -    if (x==NULL) return(p_write_ushort(pack,0));
  -    for (k=x; k[0]!='\0'; k++);
  -    len=k-x;
  -    if (p_write_ushort(pack,len)==wa_false) {
  -        pack->size-=2;
  -        return(wa_false);
  -    }
  -    if ((pack->size+len)>65535) {
  -        pack->size-=2;
  -        return(wa_false);
  -    }
  -    for (q=0;q<len;q++) pack->buff[pack->size++]=x[q];
  -    return(wa_true);
  -}
  -
  -/* ************************************************************************* */
  -/* NETWORK FUNCTIONS                                                         */
  -/* ************************************************************************* */
  -
  -static wa_boolean n_recv(apr_socket_t *sock, warp_packet *pack) {
  -    apr_size_t len=0;
  -    char hdr[3];
  -    int ptr=0;
  -
  -    if (sock==NULL) return(wa_false);
  -    if (pack==NULL) return(wa_false);
  -
  -    p_reset(pack);
  -    len=3;
  -    while(1) {
  -        if (apr_recv(sock,&hdr[ptr],&len)!=APR_SUCCESS) return(wa_false);
  -        ptr+=len;
  -        len=3-ptr;
  -        if (len==0) break;
  -    }
  -    pack->type=((int)hdr[0])&0x0ff;
  -    pack->size=(hdr[1]&0x0ff)<<8;
  -    pack->size=pack->size|(hdr[2]&0x0ff);
  -
  -    len=pack->size;
  -    ptr=0;
  -    while(1) {
  -        if (apr_recv(sock,&pack->buff[ptr],&len)!=APR_SUCCESS)
  -            return(wa_false);
  -        ptr+=len;
  -        len=pack->size-ptr;
  -        if (len==0) break;
  -    }
  -
  -    wa_debug(WA_MARK,"WARP <<< TYP=%d LEN=%d",pack->type,pack->size);
  -
  -    return(wa_true);
  -}
  -
  -static wa_boolean n_send(apr_socket_t *sock, warp_packet *pack) {
  -    apr_size_t len=0;
  -    char hdr[3];
  -    int ptr=0;
  -
  -    if (sock==NULL) return(wa_false);
  -    if (pack==NULL) return(wa_false);
  -
  -    hdr[0]=(char)(pack->type&0x0ff);
  -    hdr[1]=(char)((pack->size>>8)&0x0ff);
  -    hdr[2]=(char)(pack->size&0x0ff);
  -
  -    len=3;
  -    while(1) {
  -        if (apr_send(sock,&hdr[ptr],&len)!=APR_SUCCESS) return(wa_false);
  -        ptr+=len;
  -        len=3-ptr;
  -        if (len==0) break;
  -    }
  -
  -    len=pack->size;
  -    ptr=0;
  -    while(1) {
  -        if (apr_send(sock,&pack->buff[ptr],&len)!=APR_SUCCESS)
  -            return(wa_false);
  -        ptr+=len;
  -        len=pack->size-ptr;
  -        if (len==0) break;
  -    }
  -
  -    wa_debug(WA_MARK,"WARP >>> TYP=%d LEN=%d",pack->type,pack->size);
  -
  -    p_reset(pack);
  -    return(wa_true);
  -}
  -
  -/* Attempt to connect to the remote endpoint of the WARP connection (if not
  -   done already). */
  -static wa_boolean n_connect(wa_connection *conn) {
  -    warp_config *conf=(warp_config *)conn->conf;
  -    apr_status_t ret=APR_SUCCESS;
  -
  -    /* Create the APR socket if that has not been yet created */
  -    if (conf->sock!=NULL) {
  -        wa_debug(WA_MARK,"Connection \"%s\" already opened",conn->conf);
  -        return(wa_true);
  -    }
  -
  -    ret=apr_socket_create(&conf->sock,AF_INET,SOCK_STREAM,wa_pool);
  -    if (ret!=APR_SUCCESS) {
  -        conf->sock=NULL;
  -        wa_log(WA_MARK,"Cannot create socket for conn. \"%s\"",conn->name);
  -        return(wa_false);
  -    }
  -
  -    /* Attempt to connect to the remote endpoint */
  -    ret=apr_connect(conf->sock, conf->addr);
  -    if (ret!=APR_SUCCESS) {
  -        apr_shutdown(conf->sock,APR_SHUTDOWN_READWRITE);
  -        conf->sock=NULL;
  -        wa_log(WA_MARK,"Connection \"%s\" cannot connect",conn->name);
  -        return(wa_false);
  -    }
  -
  -    return(wa_true);
  -}
  -
  -/* Attempt to disconnect a connection if connected. */
  -static void n_disconnect(wa_connection *conn) {
  -    warp_config *conf=(warp_config *)conn->conf;
  -    apr_status_t ret=APR_SUCCESS;
  -
  -    wa_debug(WA_MARK,"Disconnecting \"%s\"",conn->name);
  -
  -    /* Create the APR socket if that has not been yet created */
  -    if (conf->sock==NULL) return;
  -
  -    /* Shutdown and close the socket (ignoring errors) */
  -    ret=apr_shutdown(conf->sock,APR_SHUTDOWN_READWRITE);
  -    if (ret!=APR_SUCCESS)
  -        wa_log(WA_MARK,"Cannot shutdown \"%s\"",conn->name);
  -    ret=apr_socket_close(conf->sock);
  -    if (ret!=APR_SUCCESS)
  -        wa_log(WA_MARK,"Cannot close \"%s\"",conn->name);
  -
  -    /* Reset the state */
  -    conf->sock=NULL;
  -}
  -
  -static wa_boolean n_check(wa_connection *conn, warp_packet *pack) {
  -    warp_config *conf=(warp_config *)conn->conf;
  -    int maj=-1;
  -    int min=-1;
  -    int sid=-1;
  -
  -    if (n_recv(conf->sock,pack)!=wa_true) {
  -        wa_log(WA_MARK,"Cannot receive handshake WARP packet");
  -        return(wa_false);
  -    }
  -
  -    if (pack->type!=TYPE_CONF_WELCOME) {
  -        wa_log(WA_MARK,"Invalid WARP packet %d (WELCOME)",pack->type);
  -        return(wa_false);
  -    }
  -        
  -    if (p_read_ushort(pack,&maj)!=wa_true) {
  -        wa_log(WA_MARK,"Cannot read major version");
  -        return(wa_false);
  -    }
  -
  -    if (p_read_ushort(pack,&min)!=wa_true) {
  -        wa_log(WA_MARK,"Cannot read minor version");
  -        return(wa_false);
  -    }
  -
  -    if ((maj!=VERS_MAJOR)||(min!=VERS_MINOR)) {
  -        wa_log(WA_MARK,"Invalid WARP protocol version %d.%d",maj,min);
  -        return(wa_false);
  -    }
  -
  -    if (p_read_int(pack,&sid)!=wa_true) {
  -        wa_log(WA_MARK,"Cannot read server id");
  -        return(wa_false);
  -    }
  -
  -    conf->serv=sid;
  -    wa_debug(WA_MARK,"Connection \"%s\" checked WARP/%d.%d (SERVER ID=%d)",
  -        conn->name,maj,min,conf->serv);
  -    return(wa_true);
  -}
  -
  -static wa_boolean n_configure(wa_connection *conn) {
  -    warp_config *conf=(warp_config *)conn->conf;
  -    wa_chain *elem=warp_applications;
  -    apr_pool_t *pool=NULL;
  -    wa_boolean ret=wa_false;
  -    warp_packet *pack=NULL;
  -
  -    if (apr_pool_create(&pool,wa_pool)!=APR_SUCCESS) {
  -        wa_log(WA_MARK,"Cannot create WARP temporary configuration pool");
  -        n_disconnect(conn);
  -        return(wa_false);
  -    }
  -
  -    if ((pack=p_create(wa_pool))==NULL) {
  -        wa_log(WA_MARK,"Cannot create WARP configuration packet");
  -        apr_pool_destroy(pool);
  -        return(wa_false);
  -    }
  -
  -    if ((ret=n_check(conn,pack))==wa_false) n_disconnect(conn);
  -
  -    while (elem!=NULL) {
  -        wa_application *appl=(wa_application *)elem->curr;
  -        wa_debug(WA_MARK,"Deploying \"%s\" via \"%s\" in \"http://%s:%d%s\"";,
  -                appl->name,conn->name,appl->host->name,appl->host->port,
  -                appl->rpth);
  -        p_reset(pack);
  -        pack->type=TYPE_CONF_DEPLOY;
  -        p_write_string(pack,appl->name);
  -        p_write_string(pack,appl->host->name);
  -        p_write_ushort(pack,appl->host->port);
  -        p_write_string(pack,appl->rpth);
  -        n_send(conf->sock,pack);
  -
  -        elem=elem->next;
  -    }
  -
  -    apr_pool_destroy(pool);
  -    return(ret);
  -}
   
   /* ************************************************************************* */
   /* WEBAPP LIBRARY PROVIDER FUNCTIONS                                         */
  
  
  
  1.1                  jakarta-tomcat-connectors/webapp/lib/pr_warp.h
  
  Index: pr_warp.h
  ===================================================================
  /* ========================================================================= *
   *                                                                           *
   *                 The Apache Software License,  Version 1.1                 *
   *                                                                           *
   *          Copyright (c) 1999-2001 The Apache Software Foundation.          *
   *                           All rights reserved.                            *
   *                                                                           *
   * ========================================================================= *
   *                                                                           *
   * Redistribution and use in source and binary forms,  with or without modi- *
   * fication, are permitted provided that the following conditions are met:   *
   *                                                                           *
   * 1. Redistributions of source code  must retain the above copyright notice *
   *    notice, this list of conditions and the following disclaimer.          *
   *                                                                           *
   * 2. Redistributions  in binary  form  must  reproduce the  above copyright *
   *    notice,  this list of conditions  and the following  disclaimer in the *
   *    documentation and/or other materials provided with the distribution.   *
   *                                                                           *
   * 3. The end-user documentation  included with the redistribution,  if any, *
   *    must include the following acknowlegement:                             *
   *                                                                           *
   *       "This product includes  software developed  by the Apache  Software *
   *        Foundation <http://www.apache.org/>."                              *
   *                                                                           *
   *    Alternately, this acknowlegement may appear in the software itself, if *
   *    and wherever such third-party acknowlegements normally appear.         *
   *                                                                           *
   * 4. The names  "The  Jakarta  Project",  "WebApp",  and  "Apache  Software *
   *    Foundation"  must not be used  to endorse or promote  products derived *
   *    from this  software without  prior  written  permission.  For  written *
   *    permission, please contact <[EMAIL PROTECTED]>.                        *
   *                                                                           *
   * 5. Products derived from this software may not be called "Apache" nor may *
   *    "Apache" appear in their names without prior written permission of the *
   *    Apache Software Foundation.                                            *
   *                                                                           *
   * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES *
   * INCLUDING, BUT NOT LIMITED TO,  THE IMPLIED WARRANTIES OF MERCHANTABILITY *
  2 * THE APACHE  SOFTWARE  FOUNDATION OR  ITS CONTRIBUTORS  BE LIABLE  FOR ANY *
   * DIRECT,  INDIRECT,   INCIDENTAL,  SPECIAL,  EXEMPLARY,  OR  CONSEQUENTIAL *
   * DAMAGES (INCLUDING,  BUT NOT LIMITED TO,  PROCUREMENT OF SUBSTITUTE GOODS *
   * OR SERVICES;  LOSS OF USE,  DATA,  OR PROFITS;  OR BUSINESS INTERRUPTION) *
   * HOWEVER CAUSED AND  ON ANY  THEORY  OF  LIABILITY,  WHETHER IN  CONTRACT, *
   * STRICT LIABILITY, OR TORT  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN *
   * ANY  WAY  OUT OF  THE  USE OF  THIS  SOFTWARE,  EVEN  IF  ADVISED  OF THE *
   * POSSIBILITY OF SUCH DAMAGE.                                               *
   *                                                                           *
   * ========================================================================= *
   *                                                                           *
   * This software  consists of voluntary  contributions made  by many indivi- *
   * duals on behalf of the  Apache Software Foundation.  For more information *
   * on the Apache Software Foundation, please see <http://www.apache.org/>.   *
   *                                                                           *
   * ========================================================================= */
  
  /* @version $Id: pr_warp.h,v 1.1 2001/07/18 19:08:35 pier Exp $ */
  #ifndef _PR_WARP_H_
  #define _PR_WARP_H_
  
  #include <wa.h>
  
  /* ************************************************************************* */
  /* INSTANCE VARIABLES                                                        */
  /* ************************************************************************* */
  /* The list of all configured connections */
  extern wa_chain *warp_connections;
  /* The list of all deployed connections */
  extern wa_chain *warp_applications;
  /* The warp provider structure */
  extern wa_provider wa_provider_warp;
  
  /* ************************************************************************* */
  /* STRUCTURES                                                                */
  /* ************************************************************************* */
  
  /* The WARP connection configuration structure */
  typedef struct warp_config {
      apr_sockaddr_t *addr;
      apr_socket_t *sock;
      int serv;
  } warp_config;
  
  /* The WARP packet structure */
  typedef struct warp_packet {
      apr_pool_t *pool;
      int type;
      int size;
      int curr;
      char buff[65536];
  } warp_packet;
  
  /* ************************************************************************* */
  /* DEFINITIONS                                                               */
  /* ************************************************************************* */
  
  /* WARP definitions */
  #define VERS_MAJOR 0
  #define VERS_MINOR 9
  
  #define TYPE_INVALID -1
  #define TYPE_ERROR   0x00
  #define TYPE_FATAL   0xff
  
  #define TYPE_CONF_WELCOME 0x01
  #define TYPE_CONF_DEPLOY  0x02
  #define TYPE_CONF_APPLIC  0x03
  #define TYPE_CONF_DONE    0x04
  
  /* ************************************************************************* */
  /* PACKET FUNCTIONS FROM PR_WARP_PACKET.C                                    */
  /* ************************************************************************* */
  void p_reset(warp_packet *pack);
  warp_packet *p_create(apr_pool_t *pool);
  wa_boolean p_read_ushort(warp_packet *pack, int *x);
  wa_boolean p_read_int(warp_packet *pack, int *x);
  wa_boolean p_read_string(warp_packet *pack, char **x);
  wa_boolean p_write_ushort(warp_packet *pack, int x);
  wa_boolean p_write_int(warp_packet *pack, int x);
  wa_boolean p_write_string(warp_packet *pack, char *x);
  
  /* ************************************************************************* */
  /* NETWORK FUNCTIONS FROM PR_WARP_NETWORK.C                                  */
  /* ************************************************************************* */
  wa_boolean n_recv(apr_socket_t *sock, warp_packet *pack);
  wa_boolean n_send(apr_socket_t *sock, warp_packet *pack);
  wa_boolean n_connect(wa_connection *conn);
  void n_disconnect(wa_connection *conn);
  
  /* ************************************************************************* */
  /* CONFIGURATION FUNCTIONS FROM PR_WARP_CONFIG.C                             */
  /* ************************************************************************* */
  wa_boolean n_check(wa_connection *conn, warp_packet *pack);
  wa_boolean n_configure(wa_connection *conn);
  
  #endif /* ifndef _PR_WARP_H_ */
  
  
  
  1.1                  jakarta-tomcat-connectors/webapp/lib/pr_warp_config.c
  
  Index: pr_warp_config.c
  ===================================================================
  /* ========================================================================= *
   *                                                                           *
   *                 The Apache Software License,  Version 1.1                 *
   *                                                                           *
   *          Copyright (c) 1999-2001 The Apache Software Foundation.          *
   *                           All rights reserved.                            *
   *                                                                           *
   * ========================================================================= *
   *                                                                           *
   * Redistribution and use in source and binary forms,  with or without modi- *
   * fication, are permitted provided that the following conditions are met:   *
   *                                                                           *
   * 1. Redistributions of source code  must retain the above copyright notice *
   *    notice, this list of conditions and the following disclaimer.          *
   *                                                                           *
   * 2. Redistributions  in binary  form  must  reproduce the  above copyright *
   *    notice,  this list of conditions  and the following  disclaimer in the *
   *    documentation and/or other materials provided with the distribution.   *
   *                                                                           *
   * 3. The end-user documentation  included with the redistribution,  if any, *
   *    must include the following acknowlegement:                             *
   *                                                                           *
   *       "This product includes  software developed  by the Apache  Software *
   *        Foundation <http://www.apache.org/>."                              *
   *                                                                           *
   *    Alternately, this acknowlegement may appear in the software itself, if *
   *    and wherever such third-party acknowlegements normally appear.         *
   *                                                                           *
   * 4. The names  "The  Jakarta  Project",  "WebApp",  and  "Apache  Software *
   *    Foundation"  must not be used  to endorse or promote  products derived *
   *    from this  software without  prior  written  permission.  For  written *
   *    permission, please contact <[EMAIL PROTECTED]>.                        *
   *                                                                           *
   * 5. Products derived from this software may not be called "Apache" nor may *
   *    "Apache" appear in their names without prior written permission of the *
   *    Apache Software Foundation.                                            *
   *                                                                           *
   * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES *
   * INCLUDING, BUT NOT LIMITED TO,  THE IMPLIED WARRANTIES OF MERCHANTABILITY *
  2 * THE APACHE  SOFTWARE  FOUNDATION OR  ITS CONTRIBUTORS  BE LIABLE  FOR ANY *
   * DIRECT,  INDIRECT,   INCIDENTAL,  SPECIAL,  EXEMPLARY,  OR  CONSEQUENTIAL *
   * DAMAGES (INCLUDING,  BUT NOT LIMITED TO,  PROCUREMENT OF SUBSTITUTE GOODS *
   * OR SERVICES;  LOSS OF USE,  DATA,  OR PROFITS;  OR BUSINESS INTERRUPTION) *
   * HOWEVER CAUSED AND  ON ANY  THEORY  OF  LIABILITY,  WHETHER IN  CONTRACT, *
   * STRICT LIABILITY, OR TORT  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN *
   * ANY  WAY  OUT OF  THE  USE OF  THIS  SOFTWARE,  EVEN  IF  ADVISED  OF THE *
   * POSSIBILITY OF SUCH DAMAGE.                                               *
   *                                                                           *
   * ========================================================================= *
   *                                                                           *
   * This software  consists of voluntary  contributions made  by many indivi- *
   * duals on behalf of the  Apache Software Foundation.  For more information *
   * on the Apache Software Foundation, please see <http://www.apache.org/>.   *
   *                                                                           *
   * ========================================================================= */
  
  /* @version $Id: pr_warp_config.c,v 1.1 2001/07/18 19:08:35 pier Exp $ */
  #include "pr_warp.h"
  
  wa_boolean n_check(wa_connection *conn, warp_packet *pack) {
      warp_config *conf=(warp_config *)conn->conf;
      int maj=-1;
      int min=-1;
      int sid=-1;
  
      if (n_recv(conf->sock,pack)!=wa_true) {
          wa_log(WA_MARK,"Cannot receive handshake WARP packet");
          return(wa_false);
      }
  
      if (pack->type!=TYPE_CONF_WELCOME) {
          wa_log(WA_MARK,"Invalid WARP packet %d (WELCOME)",pack->type);
          return(wa_false);
      }
          
      if (p_read_ushort(pack,&maj)!=wa_true) {
          wa_log(WA_MARK,"Cannot read major version");
          return(wa_false);
      }
  
      if (p_read_ushort(pack,&min)!=wa_true) {
          wa_log(WA_MARK,"Cannot read minor version");
          return(wa_false);
      }
  
      if ((maj!=VERS_MAJOR)||(min!=VERS_MINOR)) {
          wa_log(WA_MARK,"Invalid WARP protocol version %d.%d",maj,min);
          return(wa_false);
      }
  
      if (p_read_int(pack,&sid)!=wa_true) {
          wa_log(WA_MARK,"Cannot read server id");
          return(wa_false);
      }
  
      conf->serv=sid;
      wa_debug(WA_MARK,"Connection \"%s\" checked WARP/%d.%d (SERVER ID=%d)",
          conn->name,maj,min,conf->serv);
      return(wa_true);
  }
  
  wa_boolean n_configure(wa_connection *conn) {
      warp_config *conf=(warp_config *)conn->conf;
      wa_chain *elem=warp_applications;
      apr_pool_t *pool=NULL;
      wa_boolean ret=wa_false;
      warp_packet *pack=NULL;
  
      if (apr_pool_create(&pool,wa_pool)!=APR_SUCCESS) {
          wa_log(WA_MARK,"Cannot create WARP temporary configuration pool");
          n_disconnect(conn);
          return(wa_false);
      }
  
      if ((pack=p_create(wa_pool))==NULL) {
          wa_log(WA_MARK,"Cannot create WARP configuration packet");
          apr_pool_destroy(pool);
          return(wa_false);
      }
  
      if ((ret=n_check(conn,pack))==wa_false) n_disconnect(conn);
  
      while (elem!=NULL) {
          wa_application *appl=(wa_application *)elem->curr;
          wa_debug(WA_MARK,"Deploying \"%s\" via \"%s\" in \"http://%s:%d%s\"";,
                  appl->name,conn->name,appl->host->name,appl->host->port,
                  appl->rpth);
          p_reset(pack);
          pack->type=TYPE_CONF_DEPLOY;
          p_write_string(pack,appl->name);
          p_write_string(pack,appl->host->name);
          p_write_ushort(pack,appl->host->port);
          p_write_string(pack,appl->rpth);
          n_send(conf->sock,pack);
  
          elem=elem->next;
      }
  
      apr_pool_destroy(pool);
      return(ret);
  }
  
  
  
  1.1                  jakarta-tomcat-connectors/webapp/lib/pr_warp_network.c
  
  Index: pr_warp_network.c
  ===================================================================
  /* ========================================================================= *
   *                                                                           *
   *                 The Apache Software License,  Version 1.1                 *
   *                                                                           *
   *          Copyright (c) 1999-2001 The Apache Software Foundation.          *
   *                           All rights reserved.                            *
   *                                                                           *
   * ========================================================================= *
   *                                                                           *
   * Redistribution and use in source and binary forms,  with or without modi- *
   * fication, are permitted provided that the following conditions are met:   *
   *                                                                           *
   * 1. Redistributions of source code  must retain the above copyright notice *
   *    notice, this list of conditions and the following disclaimer.          *
   *                                                                           *
   * 2. Redistributions  in binary  form  must  reproduce the  above copyright *
   *    notice,  this list of conditions  and the following  disclaimer in the *
   *    documentation and/or other materials provided with the distribution.   *
   *                                                                           *
   * 3. The end-user documentation  included with the redistribution,  if any, *
   *    must include the following acknowlegement:                             *
   *                                                                           *
   *       "This product includes  software developed  by the Apache  Software *
   *        Foundation <http://www.apache.org/>."                              *
   *                                                                           *
   *    Alternately, this acknowlegement may appear in the software itself, if *
   *    and wherever such third-party acknowlegements normally appear.         *
   *                                                                           *
   * 4. The names  "The  Jakarta  Project",  "WebApp",  and  "Apache  Software *
   *    Foundation"  must not be used  to endorse or promote  products derived *
   *    from this  software without  prior  written  permission.  For  written *
   *    permission, please contact <[EMAIL PROTECTED]>.                        *
   *                                                                           *
   * 5. Products derived from this software may not be called "Apache" nor may *
   *    "Apache" appear in their names without prior written permission of the *
   *    Apache Software Foundation.                                            *
   *                                                                           *
   * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES *
   * INCLUDING, BUT NOT LIMITED TO,  THE IMPLIED WARRANTIES OF MERCHANTABILITY *
  2 * THE APACHE  SOFTWARE  FOUNDATION OR  ITS CONTRIBUTORS  BE LIABLE  FOR ANY *
   * DIRECT,  INDIRECT,   INCIDENTAL,  SPECIAL,  EXEMPLARY,  OR  CONSEQUENTIAL *
   * DAMAGES (INCLUDING,  BUT NOT LIMITED TO,  PROCUREMENT OF SUBSTITUTE GOODS *
   * OR SERVICES;  LOSS OF USE,  DATA,  OR PROFITS;  OR BUSINESS INTERRUPTION) *
   * HOWEVER CAUSED AND  ON ANY  THEORY  OF  LIABILITY,  WHETHER IN  CONTRACT, *
   * STRICT LIABILITY, OR TORT  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN *
   * ANY  WAY  OUT OF  THE  USE OF  THIS  SOFTWARE,  EVEN  IF  ADVISED  OF THE *
   * POSSIBILITY OF SUCH DAMAGE.                                               *
   *                                                                           *
   * ========================================================================= *
   *                                                                           *
   * This software  consists of voluntary  contributions made  by many indivi- *
   * duals on behalf of the  Apache Software Foundation.  For more information *
   * on the Apache Software Foundation, please see <http://www.apache.org/>.   *
   *                                                                           *
   * ========================================================================= */
  
  /* @version $Id: pr_warp_network.c,v 1.1 2001/07/18 19:08:35 pier Exp $ */
  #include "pr_warp.h"
  
  wa_boolean n_recv(apr_socket_t *sock, warp_packet *pack) {
      apr_size_t len=0;
      char hdr[3];
      int ptr=0;
  
      if (sock==NULL) return(wa_false);
      if (pack==NULL) return(wa_false);
  
      p_reset(pack);
      len=3;
      while(1) {
          if (apr_recv(sock,&hdr[ptr],&len)!=APR_SUCCESS) return(wa_false);
          ptr+=len;
          len=3-ptr;
          if (len==0) break;
      }
      pack->type=((int)hdr[0])&0x0ff;
      pack->size=(hdr[1]&0x0ff)<<8;
      pack->size=pack->size|(hdr[2]&0x0ff);
  
      len=pack->size;
      ptr=0;
      while(1) {
          if (apr_recv(sock,&pack->buff[ptr],&len)!=APR_SUCCESS)
              return(wa_false);
          ptr+=len;
          len=pack->size-ptr;
          if (len==0) break;
      }
  
      wa_debug(WA_MARK,"WARP <<< TYP=%d LEN=%d",pack->type,pack->size);
  
      return(wa_true);
  }
  
  wa_boolean n_send(apr_socket_t *sock, warp_packet *pack) {
      apr_size_t len=0;
      char hdr[3];
      int ptr=0;
  
      if (sock==NULL) return(wa_false);
      if (pack==NULL) return(wa_false);
  
      hdr[0]=(char)(pack->type&0x0ff);
      hdr[1]=(char)((pack->size>>8)&0x0ff);
      hdr[2]=(char)(pack->size&0x0ff);
  
      len=3;
      while(1) {
          if (apr_send(sock,&hdr[ptr],&len)!=APR_SUCCESS) return(wa_false);
          ptr+=len;
          len=3-ptr;
          if (len==0) break;
      }
  
      len=pack->size;
      ptr=0;
      while(1) {
          if (apr_send(sock,&pack->buff[ptr],&len)!=APR_SUCCESS)
              return(wa_false);
          ptr+=len;
          len=pack->size-ptr;
          if (len==0) break;
      }
  
      wa_debug(WA_MARK,"WARP >>> TYP=%d LEN=%d",pack->type,pack->size);
  
      p_reset(pack);
      return(wa_true);
  }
  
  /* Attempt to connect to the remote endpoint of the WARP connection (if not
     done already). */
  wa_boolean n_connect(wa_connection *conn) {
      warp_config *conf=(warp_config *)conn->conf;
      apr_status_t ret=APR_SUCCESS;
  
      /* Create the APR socket if that has not been yet created */
      if (conf->sock!=NULL) {
          wa_debug(WA_MARK,"Connection \"%s\" already opened",conn->conf);
          return(wa_true);
      }
  
      ret=apr_socket_create(&conf->sock,AF_INET,SOCK_STREAM,wa_pool);
      if (ret!=APR_SUCCESS) {
          conf->sock=NULL;
          wa_log(WA_MARK,"Cannot create socket for conn. \"%s\"",conn->name);
          return(wa_false);
      }
  
      /* Attempt to connect to the remote endpoint */
      ret=apr_connect(conf->sock, conf->addr);
      if (ret!=APR_SUCCESS) {
          apr_shutdown(conf->sock,APR_SHUTDOWN_READWRITE);
          conf->sock=NULL;
          wa_log(WA_MARK,"Connection \"%s\" cannot connect",conn->name);
          return(wa_false);
      }
  
      return(wa_true);
  }
  
  /* Attempt to disconnect a connection if connected. */
  void n_disconnect(wa_connection *conn) {
      warp_config *conf=(warp_config *)conn->conf;
      apr_status_t ret=APR_SUCCESS;
  
      wa_debug(WA_MARK,"Disconnecting \"%s\"",conn->name);
  
      /* Create the APR socket if that has not been yet created */
      if (conf->sock==NULL) return;
  
      /* Shutdown and close the socket (ignoring errors) */
      ret=apr_shutdown(conf->sock,APR_SHUTDOWN_READWRITE);
      if (ret!=APR_SUCCESS)
          wa_log(WA_MARK,"Cannot shutdown \"%s\"",conn->name);
      ret=apr_socket_close(conf->sock);
      if (ret!=APR_SUCCESS)
          wa_log(WA_MARK,"Cannot close \"%s\"",conn->name);
  
      /* Reset the state */
      conf->sock=NULL;
  }
  
  
  
  
  1.1                  jakarta-tomcat-connectors/webapp/lib/pr_warp_packet.c
  
  Index: pr_warp_packet.c
  ===================================================================
  /* ========================================================================= *
   *                                                                           *
   *                 The Apache Software License,  Version 1.1                 *
   *                                                                           *
   *          Copyright (c) 1999-2001 The Apache Software Foundation.          *
   *                           All rights reserved.                            *
   *                                                                           *
   * ========================================================================= *
   *                                                                           *
   * Redistribution and use in source and binary forms,  with or without modi- *
   * fication, are permitted provided that the following conditions are met:   *
   *                                                                           *
   * 1. Redistributions of source code  must retain the above copyright notice *
   *    notice, this list of conditions and the following disclaimer.          *
   *                                                                           *
   * 2. Redistributions  in binary  form  must  reproduce the  above copyright *
   *    notice,  this list of conditions  and the following  disclaimer in the *
   *    documentation and/or other materials provided with the distribution.   *
   *                                                                           *
   * 3. The end-user documentation  included with the redistribution,  if any, *
   *    must include the following acknowlegement:                             *
   *                                                                           *
   *       "This product includes  software developed  by the Apache  Software *
   *        Foundation <http://www.apache.org/>."                              *
   *                                                                           *
   *    Alternately, this acknowlegement may appear in the software itself, if *
   *    and wherever such third-party acknowlegements normally appear.         *
   *                                                                           *
   * 4. The names  "The  Jakarta  Project",  "WebApp",  and  "Apache  Software *
   *    Foundation"  must not be used  to endorse or promote  products derived *
   *    from this  software without  prior  written  permission.  For  written *
   *    permission, please contact <[EMAIL PROTECTED]>.                        *
   *                                                                           *
   * 5. Products derived from this software may not be called "Apache" nor may *
   *    "Apache" appear in their names without prior written permission of the *
   *    Apache Software Foundation.                                            *
   *                                                                           *
   * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES *
   * INCLUDING, BUT NOT LIMITED TO,  THE IMPLIED WARRANTIES OF MERCHANTABILITY *
  2 * THE APACHE  SOFTWARE  FOUNDATION OR  ITS CONTRIBUTORS  BE LIABLE  FOR ANY *
   * DIRECT,  INDIRECT,   INCIDENTAL,  SPECIAL,  EXEMPLARY,  OR  CONSEQUENTIAL *
   * DAMAGES (INCLUDING,  BUT NOT LIMITED TO,  PROCUREMENT OF SUBSTITUTE GOODS *
   * OR SERVICES;  LOSS OF USE,  DATA,  OR PROFITS;  OR BUSINESS INTERRUPTION) *
   * HOWEVER CAUSED AND  ON ANY  THEORY  OF  LIABILITY,  WHETHER IN  CONTRACT, *
   * STRICT LIABILITY, OR TORT  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN *
   * ANY  WAY  OUT OF  THE  USE OF  THIS  SOFTWARE,  EVEN  IF  ADVISED  OF THE *
   * POSSIBILITY OF SUCH DAMAGE.                                               *
   *                                                                           *
   * ========================================================================= *
   *                                                                           *
   * This software  consists of voluntary  contributions made  by many indivi- *
   * duals on behalf of the  Apache Software Foundation.  For more information *
   * on the Apache Software Foundation, please see <http://www.apache.org/>.   *
   *                                                                           *
   * ========================================================================= */
  
  /* @version $Id: pr_warp_packet.c,v 1.1 2001/07/18 19:08:35 pier Exp $ */
  #include "pr_warp.h"
  
  void p_reset(warp_packet *pack) {
      pack->type=TYPE_INVALID;
      pack->type=TYPE_INVALID;
      pack->size=0;
      pack->curr=0;
      pack->buff[0]='\0';
  }
  
  warp_packet *p_create(apr_pool_t *pool) {
      warp_packet *pack=NULL;
  
      if (pool==NULL) return(NULL);
      pack=(warp_packet *)apr_palloc(pool,sizeof(warp_packet));
      pack->pool=pool;
      p_reset(pack);
      return(pack);
  }
  
  wa_boolean p_read_ushort(warp_packet *pack, int *x) {
      int k=0;
  
      if ((pack->curr+2)>=pack->size) return(wa_false);
      k=(pack->buff[pack->curr++]&0x0ff)<<8;
      k=k|(pack->buff[pack->curr++]&0x0ff);
      *x=k;
      return(wa_true);
  }
  
  wa_boolean p_read_int(warp_packet *pack, int *x) {
      int k=0;
  
      if ((pack->curr+2)>=pack->size) return(wa_false);
      k=(pack->buff[pack->curr++]&0x0ff)<<24;
      k=k|((pack->buff[pack->curr++]&0x0ff)<<16);
      k=k|((pack->buff[pack->curr++]&0x0ff)<<8);
      k=k|(pack->buff[pack->curr++]&0x0ff);
      *x=k;
      return(wa_true);
  }
  
  wa_boolean p_read_string(warp_packet *pack, char **x) {
      int len=0;
  
      if (p_read_ushort(pack,&len)==wa_false) {
          *x=NULL;
          return(wa_false);
      }
      if ((pack->curr+len)>=pack->size) {
          *x=NULL;
          return(wa_false);
      }
  
      *x=(char *)apr_palloc(pack->pool,(len+1)*sizeof(char));
      if (*x==NULL) return(wa_false);
  
      apr_cpystrn(*x,&pack->buff[pack->curr],len);
      pack->curr+=len;
      return(wa_true);
  }
  
  wa_boolean p_write_ushort(warp_packet *pack, int x) {
      if (pack->size>65533) return(wa_false);
      pack->buff[pack->size++]=(x>>8)&0x0ff;
      pack->buff[pack->size++]=x&0x0ff;
      return(wa_true);
  }
  
  wa_boolean p_write_int(warp_packet *pack, int x) {
      if (pack->size>65531) return(wa_false);
      pack->buff[pack->size++]=(x>>24)&0x0ff;
      pack->buff[pack->size++]=(x>>16)&0x0ff;
      pack->buff[pack->size++]=(x>>8)&0x0ff;
      pack->buff[pack->size++]=x&0x0ff;
      return(wa_true);
  }
  
  wa_boolean p_write_string(warp_packet *pack, char *x) {
      int len=0;
      char *k=NULL;
      int q=0;
  
      if (x==NULL) return(p_write_ushort(pack,0));
      for (k=x; k[0]!='\0'; k++);
      len=k-x;
      if (p_write_ushort(pack,len)==wa_false) {
          pack->size-=2;
          return(wa_false);
      }
      if ((pack->size+len)>65535) {
          pack->size-=2;
          return(wa_false);
      }
      for (q=0;q<len;q++) pack->buff[pack->size++]=x[q];
      return(wa_true);
  }
  
  
  

Reply via email to