pier 00/11/30 09:34:16 Modified: connectors/webapplib wa_callback.c wa_provider_info.c wa_provider_warp.c wa_provider_warp.h Log: Get rid of Solaris' strlcpy() function (not portable). Revision Changes Path 1.2 +3 -3 jakarta-tomcat-4.0/connectors/webapplib/wa_callback.c Index: wa_callback.c =================================================================== RCS file: /home/cvs/jakarta-tomcat-4.0/connectors/webapplib/wa_callback.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- wa_callback.c 2000/11/27 12:48:09 1.1 +++ wa_callback.c 2000/11/30 17:34:15 1.2 @@ -55,7 +55,7 @@ * * * ========================================================================= */ -// CVS $Id: wa_callback.c,v 1.1 2000/11/27 12:48:09 pier Exp $ +// CVS $Id: wa_callback.c,v 1.2 2000/11/30 17:34:15 pier Exp $ // Author: Pier Fumagalli <mailto:[EMAIL PROTECTED]> #include <wa.h> @@ -101,13 +101,13 @@ va_list ap; char buf[1024]; int ret; - + va_start(ap,fmt); ret=vsnprintf(buf,1024,fmt,ap); va_end(ap); if (ret<0) return(-1); - + return(wa_callback_write(c,r,buf,ret)); } 1.6 +16 -7 jakarta-tomcat-4.0/connectors/webapplib/wa_provider_info.c Index: wa_provider_info.c =================================================================== RCS file: /home/cvs/jakarta-tomcat-4.0/connectors/webapplib/wa_provider_info.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- wa_provider_info.c 2000/11/30 16:20:54 1.5 +++ wa_provider_info.c 2000/11/30 17:34:15 1.6 @@ -55,7 +55,7 @@ * * * ========================================================================= */ -// CVS $Id: wa_provider_info.c,v 1.5 2000/11/30 16:20:54 pier Exp $ +// CVS $Id: wa_provider_info.c,v 1.6 2000/11/30 17:34:15 pier Exp $ // Author: Pier Fumagalli <mailto:[EMAIL PROTECTED]> #include <wa.h> @@ -81,13 +81,22 @@ * @param conn The connection for wich a description must be produced. * @param buf The buffer where the description must be stored. * @param len The buffer length. - * @return The number of bytes written to the buffer. + * @return The number of bytes written to the buffer (terminator included). */ static int wa_info_conninfo(wa_connection *conn, char *buf, int len) { + int x=0; + char *msg="Null connection specified\0"; + if ((buf==NULL)||(len==0)) return(0); + if(conn!=NULL) msg=(char *)conn->conf; - if(conn==NULL) return(strlcpy(buf,"Null connection specified",len)); - return(strlcpy(buf,conn->conf,len)); + // Copy the message string in the buffer and return + for (x=0; x<len; x++) { + buf[x]=msg[x]; + if (msg[x]=='\0') return(x+1); + } + buf[x-1]='\0'; + return(x); } /** @@ -96,7 +105,7 @@ * @param appl The application for wich a description must be produced. * @param buf The buffer where the description must be stored. * @param len The buffer length. - * @return The number of bytes written to the buffer. + * @return The number of bytes written to the buffer (terminator included). */ static int wa_info_applinfo(wa_application *conn, char *buf, int len) { return(0); @@ -139,7 +148,7 @@ wa_callback_printf(cb,req," <title>mod_webapp: status</title>\n"); wa_callback_printf(cb,req," </head>\n"); wa_callback_printf(cb,req," <body>\n"); - + // Dump configured connections while (conn!=NULL) { char desc[1024]; @@ -210,7 +219,7 @@ wa_callback_printf(cb,req," </code>\n"); wa_callback_printf(cb,req," </dd>\n"); wa_callback_printf(cb,req," </dl>\n"); - + // Finish the page wa_callback_printf(cb,req," </body>\n"); wa_callback_printf(cb,req,"<html>\n"); 1.2 +53 -29 jakarta-tomcat-4.0/connectors/webapplib/wa_provider_warp.c Index: wa_provider_warp.c =================================================================== RCS file: /home/cvs/jakarta-tomcat-4.0/connectors/webapplib/wa_provider_warp.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- wa_provider_warp.c 2000/11/30 16:20:54 1.1 +++ wa_provider_warp.c 2000/11/30 17:34:15 1.2 @@ -55,7 +55,7 @@ * * * ========================================================================= */ -// CVS $Id: wa_provider_warp.c,v 1.1 2000/11/30 16:20:54 pier Exp $ +// CVS $Id: wa_provider_warp.c,v 1.2 2000/11/30 17:34:15 pier Exp $ // Author: Pier Fumagalli <mailto:[EMAIL PROTECTED]> #include <wa.h> @@ -194,7 +194,7 @@ if (!wa_warp_send_short(c,p->typ)) return(FALSE); // Send the packet length if (!wa_warp_send_short(c,p->len)) return(FALSE); - + // Check if we need to send the payload if (p->len<=0) return(TRUE); if (p->buf==NULL) return(FALSE); @@ -212,7 +212,7 @@ if (c->sock<0) return(-1); if ((k=recv(c->sock,buf,2,0))!=2) return(-1); - + k=((((buf[0]<<8)&0x0ff00)|(buf[1]&0x0ff))&0x0ffff); return(k); } @@ -225,7 +225,7 @@ int rid=-1; int typ=-1; int siz=-1; - + // Get the packet RID if ((rid=wa_warp_recv_short(c))<0) return(NULL); // Fix this for multithreaded environments (demultiplexing of packets) @@ -282,7 +282,7 @@ conf->sock=SOCKET_NOT_CONNECTED; return(FALSE); } - + // Whohoo! return(TRUE); } @@ -315,7 +315,7 @@ conf->sock=SOCKET_NOT_CONNECTED; return(TRUE); -} +} /** * Configure a connection with the parameter from the web server configuration @@ -369,25 +369,37 @@ * @param conn The connection for wich a description must be produced. * @param buf The buffer where the description must be stored. * @param len The buffer length. - * @return The number of bytes written to the buffer. + * @return The number of bytes written to the buffer (terminator included). */ static int wa_warp_conninfo(wa_connection *conn, char *buf, int len) { wa_warp_conn_config *conf; char temp[1024]; + char *msg=NULL; + int x=0; if ((buf==NULL)||(len==0)) return(0); // Check sanity - if(conn==NULL) return(strlcpy(buf,"Null connection specified",len)); - if(conn->conf==NULL) return(strlcpy(buf,"Invalid configuration",len)); - conf=(wa_warp_conn_config *)conn->conf; + if(conn==NULL) msg="Null connection specified\0"; + else if(conn->conf==NULL) msg="Invalid configuration\0"; + else { + conf=(wa_warp_conn_config *)conn->conf; + + // Prepare and return description + sprintf(temp,"Host: %s (%d.%d.%d.%d) Port: %d",conf->name, + (int)((conf->addr>>0)&0x0ff), (int)((conf->addr>>8)&0x0ff), + (int)((conf->addr>>16)&0x0ff), (int)((conf->addr>>24)&0x0ff), + conf->port); + msg=temp; + } - // Prepare and return description - sprintf(temp,"Host: %s (%d.%d.%d.%d) Port: %d",conf->name, - (int)((conf->addr>>0)&0x0ff), (int)((conf->addr>>8)&0x0ff), - (int)((conf->addr>>16)&0x0ff), (int)((conf->addr>>24)&0x0ff), - conf->port); - return(strlcpy(buf,temp,len)); + // Copy the message string in the buffer and return + for (x=0; x<len; x++) { + buf[x]=msg[x]; + if (msg[x]=='\0') return(x+1); + } + buf[x-1]='\0'; + return(x); } /** @@ -396,22 +408,34 @@ * @param appl The application for wich a description must be produced. * @param buf The buffer where the description must be stored. * @param len The buffer length. - * @return The number of bytes written to the buffer. + * @return The number of bytes written to the buffer (terminator included). */ static int wa_warp_applinfo(wa_application *conn, char *buf, int len) { wa_warp_appl_config *conf; char temp[1024]; + char *msg=NULL; + int x=0; if ((buf==NULL)||(len==0)) return(0); // Check sanity - if(conn==NULL) return(strlcpy(buf,"Null connection specified",len)); - if(conn->conf==NULL) return(strlcpy(buf,"Invalid configuration",len)); - conf=(wa_warp_appl_config *)conn->conf; - - // Prepare and return description - sprintf(temp,"Host ID: %d Application ID: %d",conf->host,conf->appl); - return(strlcpy(buf,temp,len)); + if(conn==NULL) msg="Null connection specified\0"; + else if(conn->conf==NULL) msg="Invalid configuration\0"; + else { + conf=(wa_warp_appl_config *)conn->conf; + + // Prepare and return description + sprintf(temp,"Host ID: %d Application ID: %d",conf->host,conf->appl); + msg=temp; + } + + // Copy the message string in the buffer and return + for (x=0; x<len; x++) { + buf[x]=msg[x]; + if (msg[x]=='\0') return(x+1); + } + buf[x-1]='\0'; + return(x); } /** @@ -432,7 +456,7 @@ // Try to open a connection with the server if (!wa_warp_connect(conf)) return; - + // Configure our list of hosts while(host!=NULL) { wa_application *appl=host->apps; @@ -450,7 +474,7 @@ return; } wa_warp_packet_reset(p); - + // Retrieve the packet for the host ID in=wa_warp_recv(conf,RID_CONNECTION); if (in==NULL) { @@ -515,7 +539,7 @@ // Check the next configured host. host=host->next; } - + // All done (free packet) wa_warp_packet_free(p); } @@ -541,9 +565,9 @@ * @param req The request data. * @param cb The web-server callback information. */ -void wa_warp_handle(wa_request *req, wa_callbacks *cb) { +void wa_warp_handle(wa_request *req, wa_callbacks *cb) { wa_warp_conn_config *conf=NULL; - + conf=(wa_warp_conn_config *)req->appl->conn->conf; if (conf->sock<0) { wa_callback_setstatus(cb,req,500); 1.2 +6 -6 jakarta-tomcat-4.0/connectors/webapplib/wa_provider_warp.h Index: wa_provider_warp.h =================================================================== RCS file: /home/cvs/jakarta-tomcat-4.0/connectors/webapplib/wa_provider_warp.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- wa_provider_warp.h 2000/11/30 16:20:55 1.1 +++ wa_provider_warp.h 2000/11/30 17:34:15 1.2 @@ -55,7 +55,7 @@ * * * ========================================================================= */ -// CVS $Id: wa_provider_warp.h,v 1.1 2000/11/30 16:20:55 pier Exp $ +// CVS $Id: wa_provider_warp.h,v 1.2 2000/11/30 17:34:15 pier Exp $ // Author: Pier Fumagalli <mailto:[EMAIL PROTECTED]> /* The warp packet structure */ @@ -88,8 +88,8 @@ #define RID_CONNECTION 0x00000 #define RID_DISCONNECT 0x0ffff #define TYP_HOST 0x00000 -#define TYP_HOST_ID 0x00001 -#define TYP_APPLICATION 0x00002 -#define TYP_APPLICATION_ID 0x00003 -#define TYP_REQUEST 0x00004 -#define TYP_REQUEST_ID 0x00005 +#define TYP_HOST_ID 0x00001 +#define TYP_APPLICATION 0x00002 +#define TYP_APPLICATION_ID 0x00003 +#define TYP_REQUEST 0x00004 +#define TYP_REQUEST_ID 0x00005