You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by pi...@apache.org on 2006/05/15 05:07:57 UTC

svn commit: r406509 - in /webservices/axis2/trunk/c/modules/util: Makefile.am dir_handler.c

Author: pini
Date: Sun May 14 20:07:56 2006
New Revision: 406509

URL: http://svn.apache.org/viewcvs?rev=406509&view=rev
Log:
Implementing archive based deployment model

Modified:
    webservices/axis2/trunk/c/modules/util/Makefile.am
    webservices/axis2/trunk/c/modules/util/dir_handler.c

Modified: webservices/axis2/trunk/c/modules/util/Makefile.am
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/c/modules/util/Makefile.am?rev=406509&r1=406508&r2=406509&view=diff
==============================================================================
--- webservices/axis2/trunk/c/modules/util/Makefile.am (original)
+++ webservices/axis2/trunk/c/modules/util/Makefile.am Sun May 14 20:07:56 2006
@@ -1,6 +1,9 @@
 TESTS =
+SUBDIRS=minizip
 lib_LTLIBRARIES = libaxis2_util.la
 
+libaxis2_util_la_LIBADD = minizip/libaxis2_minizip.la 
+
 libaxis2_util_la_SOURCES = hash.c \
                         allocator.c \
                         env.c \
@@ -26,7 +29,8 @@
 						param_container.c \
 						dll_desc.c\
 						url.c\
-                        stack.c
+                        stack.c 
+
 
 INCLUDES = -I$(top_builddir)/include \
             -I$(top_builddir)/modules/util \

Modified: webservices/axis2/trunk/c/modules/util/dir_handler.c
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/c/modules/util/dir_handler.c?rev=406509&r1=406508&r2=406509&view=diff
==============================================================================
--- webservices/axis2/trunk/c/modules/util/dir_handler.c (original)
+++ webservices/axis2/trunk/c/modules/util/dir_handler.c Sun May 14 20:07:56 2006
@@ -22,10 +22,22 @@
 #include <axis2_file.h>
 #include <platforms/axis2_platform_auto_sense.h>
 #include <axis2_string.h>
+#include <zlib.h>
+#include <fcntl.h>
+#include "minizip/unzip.h"
+
+#define CASESENSITIVITY (0)
+#define WRITEBUFFERSIZE (8192)
+#define MAXFILENAME (256)
+
+#ifndef S_ISDIR
+#   define S_ISDIR(m) ((m & S_IFMT) == S_IFDIR)
+#endif
 
 extern int AXIS2_ALPHASORT();
 
 int dir_select(struct dirent *entry);
+int aar_select();
 
 /**
  * List the dll files in the given service or module folder path
@@ -190,17 +202,17 @@
     struct stat *buf = NULL;
     int count = 1;
     int i = 0;
-    struct dirent **files = NULL;
+	struct dirent **files = NULL;
+	char cwd[500];
+	
 /**FIXME:
  * This magic number 500 was selected as a temperary solution. It has to be
  * replaced with dinamic memory allocation. This will be done once the use of
  * errno after getwcd() on Windows is figured out.
  */
-    char cwd[500];
 
 	/*int dir_select();*/
     axis2_status_t status = AXIS2_FAILURE;
-    
     AXIS2_ENV_CHECK(env, NULL);
 	/*if ((handle = opendir(pathname)) != NULL && (handle->finished == 1))
 	{
@@ -210,8 +222,10 @@
     file_list = axis2_array_list_create(env, 0);
 	if (!getcwd(cwd, 500)) exit(1);
 	chdir(pathname);
+    aar_select();
 	count = AXIS2_SCANDIR(pathname, &files, dir_select, AXIS2_ALPHASORT);
 	chdir(cwd);
+
 	/* If no files found, make a non-selectable menu item */
 	if (count <= 0)
 	{		 
@@ -379,11 +393,13 @@
 	if (-1 ==  stat (entry->d_name, &stat_p))
 		return (AXIS2_FALSE);
 
+	axis2_char_t *rindex(const axis2_char_t *s, int c);
+
 	if ((entry->d_name[0] == '.') || (!S_ISDIR(stat_p.st_mode)))
     {
 		return (AXIS2_FALSE);
-    }
- 
+	}
+
 	/* Check for filename extensions */
 	/*ptr = AXIS2_RINDEX(entry->d_name, '.');
 	if (ptr != NULL)
@@ -392,3 +408,309 @@
     }*/
 	return AXIS2_TRUE;
 }
+
+int aar_select()
+{
+	struct dirent **namelist;
+	int n;
+	axis2_char_t *ptr;
+
+	n = scandir(".", &namelist, 0, alphasort);
+	if (n < 0)
+		perror("scandir");
+	else 
+	{
+		while(n--) 
+		{
+			if ((strcmp(namelist[n]->d_name, ".")== 0) ||
+			(strcmp(namelist[n]->d_name, "..") == 0))
+				return (AXIS2_FALSE);
+
+			ptr = AXIS2_RINDEX(namelist[n]->d_name, '.');
+
+			if ((ptr != NULL) &&
+			((strcmp(ptr, AXIS2_AAR_SUFFIX) == 0) ))
+			{
+				aar_extract(namelist[n]->d_name);
+			}
+			free(namelist[n]);
+		}
+	free(namelist);
+	}
+}
+
+int aar_extract(axis2_char_t *d_name)
+{
+	const axis2_char_t *zipfilename=NULL;
+	const axis2_char_t *filename_to_extract=NULL;
+	const axis2_char_t *password=NULL;
+	axis2_char_t filename_try[MAXFILENAME+16] = "";
+	int opt_do_extract_withoutpath=0;
+	int opt_overwrite=0;
+	int opt_extractdir=0;
+	const axis2_char_t *dir_name=NULL;
+	unzFile uf=NULL;
+
+	if (zipfilename == NULL)
+
+	zipfilename = d_name;
+	filename_to_extract = d_name;
+	if (zipfilename!=NULL)
+	{
+		#if defined( WIN32 )
+			zlib_filefunc_def ffunc;
+		#endif
+
+		strncpy(filename_try, zipfilename,MAXFILENAME-1);
+		filename_try[ MAXFILENAME ] = '\0';
+		
+		#if defined( WIN32 )
+			fill_win32_filefunc(&ffunc);
+			uf = unzOpen2(zipfilename,&ffunc);
+		#else
+			uf = unzOpen(zipfilename);
+		#endif
+		if (uf==NULL)
+		{
+			strcat(filename_try,".zip");
+
+			#if defined( WIN32 )
+				uf = unzOpen2(filename_try,&ffunc);
+			#else
+				uf = unzOpen(filename_try);
+			#endif
+		}
+	}
+
+	if (uf==NULL)
+		return -1;
+
+	if (opt_extractdir && chdir(dir_name))
+		exit(-1);
+
+	return axis2_extract(uf,opt_do_extract_withoutpath,opt_overwrite,password);
+	unzCloseCurrentFile(uf);
+	return 0;
+}
+
+int axis2_extract_onefile(uf,filename,opt_extract_without_path,opt_overwrite,password)
+	    unzFile uf;
+		const axis2_char_t* filename;
+		int opt_extract_without_path;
+		int opt_overwrite;
+		const axis2_char_t* password;
+{
+	int err = UNZ_OK;
+	if (unzLocateFile(uf,filename,CASESENSITIVITY)!=UNZ_OK)
+		return -1;
+
+	if (axis2_extract_currentfile(uf,&opt_extract_without_path,
+		&opt_overwrite,
+		password) == UNZ_OK)
+		return 0;
+	else
+		return -1;
+}
+
+
+
+int axis2_extract(uf,opt_extract_without_path,opt_overwrite,password)
+	    unzFile uf;
+		int opt_extract_without_path;
+		int opt_overwrite;
+		const axis2_char_t* password;
+{
+	uLong i;
+	unz_global_info gi;
+	int err;
+	FILE* fout=NULL;
+
+	err = unzGetGlobalInfo (uf,&gi);
+	if (err!=UNZ_OK)
+		return -1;
+
+	for (i=0;i<gi.number_entry;i++)
+	{
+		if (axis2_extract_currentfile(uf,&opt_extract_without_path,
+		&opt_overwrite,
+		password) != UNZ_OK)
+		break;
+
+		if ((i+1)<gi.number_entry)
+		{
+			err = unzGoToNextFile(uf);
+			if (err!=UNZ_OK)
+			{
+				return -1;
+				break;
+			}
+		}
+	}
+
+	return 0;
+}
+
+int axis2_extract_currentfile(uf,popt_extract_without_path,popt_overwrite,password)
+	unzFile uf;
+	const int* popt_extract_without_path;
+	int* popt_overwrite;
+	const axis2_char_t* password;
+{
+	axis2_char_t filename_inzip[256];
+	axis2_char_t* filename_withoutpath;
+	axis2_char_t* p;
+	int err=UNZ_OK;
+	FILE *fout=NULL;
+	void* buf;
+	uInt size_buf;
+
+	unz_file_info file_info;
+	err = unzGetCurrentFileInfo(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0);
+
+	if (err!=UNZ_OK)
+	{
+		return err;
+	}
+
+	size_buf = WRITEBUFFERSIZE;
+	buf = (void*)malloc(size_buf);
+	if (buf==NULL)
+		return UNZ_INTERNALERROR;
+
+    p = filename_withoutpath = filename_inzip;
+	while ((*p) != '\0')
+	{
+		if (((*p)=='/') || ((*p)=='\\'))
+		filename_withoutpath = p+1;
+		p++;
+	}
+
+	if ((*filename_withoutpath)=='\0')
+	{
+		if ((*popt_extract_without_path)==0)
+		{
+			axis2_mkdir(filename_inzip);
+		}
+	}
+	else
+	{
+		const axis2_char_t* write_filename;
+		int skip=0;
+
+		if ((*popt_extract_without_path)==0)
+		write_filename = filename_inzip;
+		else
+		write_filename = filename_withoutpath;
+
+		err = unzOpenCurrentFilePassword(uf,password);
+
+		if ((skip==0) && (err==UNZ_OK))
+		{
+			fout=fopen(write_filename,"wb");
+
+		if ((fout==NULL) && ((*popt_extract_without_path)==0) &&
+		(filename_withoutpath!=(axis2_char_t*)filename_inzip))
+		{
+			axis2_char_t c=*(filename_withoutpath-1);
+			*(filename_withoutpath-1)='\0';
+			axis2_create_dir(write_filename);
+			*(filename_withoutpath-1)=c;
+			fout=fopen(write_filename,"wb");
+		}
+
+	}
+
+	if (fout!=NULL)
+	{
+		do
+		{
+			err = unzReadCurrentFile(uf,buf,size_buf);
+			if (err<0)
+			{
+				break;
+			}
+			if (err>0)
+			if (fwrite(buf,err,1,fout)!=1)
+			{
+				err=UNZ_ERRNO;
+				break;
+			}
+		}
+		while (err>0);
+		if (fout)
+		fclose(fout);
+
+	}
+
+	if (err==UNZ_OK)
+	{
+		err = unzCloseCurrentFile (uf);
+	}
+	else
+		unzCloseCurrentFile(uf);
+	}
+
+	free(buf);
+	return err;
+}
+
+
+int axis2_create_dir (new_dir)
+	axis2_char_t *new_dir;
+{
+	axis2_char_t *buffer ;
+	axis2_char_t *p;
+	int  len = (int)strlen(new_dir);
+
+	if (len <= 0)
+	return 0;
+
+	buffer = (axis2_char_t*)malloc(len+1);
+	strcpy(buffer,new_dir);
+
+	if (buffer[len-1] == '/') 
+	{
+		buffer[len-1] = '\0';
+	}
+
+	if (axis2_mkdir(buffer) == 0)
+	{
+		free(buffer);
+		return 1;
+	}
+
+	p = buffer+1;
+	while (1)
+	{
+		axis2_char_t hold;
+
+		while(*p && *p != '\\' && *p != '/')
+		p++;
+		hold = *p;
+		*p = 0;
+		if ((axis2_mkdir(buffer) == -1))
+		{
+			free(buffer);
+			return 0;
+		}
+		if (hold == 0)
+		break;
+		*p++ = hold;
+	}
+	free(buffer);
+	return 1;
+}
+
+int axis2_mkdir(dir_name)
+	const axis2_char_t* dir_name;
+{
+
+    int value=0;
+	#ifdef WIN32
+	    value = mkdir(dir_name);
+	#else
+		    value = mkdir (dir_name,0775);
+	#endif
+	return value;
+}
+