Пример #1
0
JNIEXPORT void JNICALL
Java_java_util_zip_ZipFile_closeZipImpl (JNIEnv * env, jobject recv)
{
  PORT_ACCESS_FROM_ENV (env);

  I_32 retval = 0;
  JCLZipFile *jclZipFile;
  jfieldID descriptorFID =
    JCL_CACHE_GET (env, FID_java_util_zip_ZipFile_descriptor);

  jclZipFile = (JCLZipFile *) (IDATA) (*env)->GetLongField (env, recv, descriptorFID);
  if (jclZipFile != (void *) -1)
    {
      retval =
        zip_closeZipFile (privatePortLibrary, &(jclZipFile->hyZipFile));
      (*env)->SetLongField (env, recv, descriptorFID, -1);

      /* Free the zip struct */
      if (jclZipFile->last != NULL)
        jclZipFile->last->next = jclZipFile->next;
      if (jclZipFile->next != NULL)
        jclZipFile->next->last = jclZipFile->last;

      jclmem_free_memory (env, jclZipFile);
      if (retval)
        {
          throwJavaZIOException (env, "");
          return;
        }
    }
}
Пример #2
0
/**
 * This DLL is being unloaded, do any clean up required.
 * This may be called more than once!!
 */
JNIEXPORT void JNICALL
JNI_OnUnload (JavaVM * vm, void *reserved)
{
  JNIEnv *env;
  void *keyInitCountPtr = GLOBAL_DATA (keyInitCount);
  void **jclIdCache = GLOBAL_DATA (JCL_ID_CACHE);

  if ((*vm)->GetEnv (vm, (void **) &env, JNI_VERSION_1_2) == JNI_OK)
    {
      JniIDCache *idCache = (JniIDCache *) HY_VMLS_GET (env, *jclIdCache);

      if (idCache)
        {
          JCLZipFileLink *zipfileHandles;
          JCLZipFile *jclZipFile;

          PORT_ACCESS_FROM_ENV (env);
#ifdef HY_ZIP_API
          VMI_ACCESS_FROM_ENV(env);
          VMIZipFunctionTable *zipFuncs = (*VMI)->GetZipFunctions(VMI);
#endif /* HY_ZIP_API */

          /* Detach from the common library */
          ClearLibDetach (env);

          /* Close and free the HyZipFile handles */
          zipfileHandles = JCL_CACHE_GET (env, zipfile_handles);
          if (zipfileHandles != NULL)
            {
              jclZipFile = zipfileHandles->next;
              while (jclZipFile != NULL)
                {
                  JCLZipFile *next = jclZipFile->next;
#ifndef HY_ZIP_API
                  zip_closeZipFile (PORTLIB, &jclZipFile->hyZipFile);
#else /* HY_ZIP_API */
                  zipFuncs->zip_closeZipFile (VMI, &jclZipFile->hyZipFile);
#endif /* HY_ZIP_API */
                  jclmem_free_memory (env, jclZipFile);
                  jclZipFile = next;
                }
              MUTEX_DESTROY (zipfileHandles->mutex);
              jclmem_free_memory (env, zipfileHandles);
            }

          /* Free any global references */
          freeReferences (env);

          /* Free VMLS keys */
          idCache = (JniIDCache *) HY_VMLS_GET (env, *jclIdCache);
          HY_VMLS_FNTBL (env)->HYVMLSFreeKeys (env, keyInitCountPtr,
                                              jclIdCache, NULL);
          hymem_free_memory (idCache);
        }
    }
}
Пример #3
0
char* Read_Manifest(JavaVM *vm, JNIEnv *env,const char *jar_name){
    I_32 retval;
#ifndef HY_ZIP_API
    HyZipFile zipFile;
    HyZipEntry zipEntry;
#else
    VMIZipFile zipFile;
    VMIZipEntry zipEntry;
#endif
    char *result;
    int size = 0;
    char errorMessage[1024];

    /* Reach for the VM interface */
    VMI_ACCESS_FROM_JAVAVM(vm);
    PORT_ACCESS_FROM_JAVAVM(vm);

#ifdef HY_ZIP_API
    VMIZipFunctionTable *zipFuncs = (*VMI)->GetZipFunctions(VMI);

#endif /* HY_ZIP_API */
    /* open zip file */
#ifndef HY_ZIP_API
    retval = zip_openZipFile(privatePortLibrary, (char *)jar_name, &zipFile, NULL);
#else /* HY_ZIP_API */
    retval = zipFuncs->zip_openZipFile(VMI, (char *)jar_name, &zipFile, 0);
#endif /* HY_ZIP_API */
    if(retval){
        sprintf(errorMessage,"failed to open file:%s, %d\n", jar_name, retval);
        (*env)->FatalError(env, errorMessage);
        return NULL;
    }

    /* get manifest entry */
#ifndef HY_ZIP_API
    zip_initZipEntry(privatePortLibrary, &zipEntry);
    retval = zip_getZipEntry(privatePortLibrary, &zipFile, &zipEntry, "META-INF/MANIFEST.MF", TRUE);
#else /* HY_ZIP_API */
    zipFuncs->zip_initZipEntry(VMI, &zipEntry);
    retval = zipFuncs->zip_getZipEntry(VMI, &zipFile, &zipEntry, "META-INF/MANIFEST.MF", ZIP_FLAG_READ_DATA_POINTER);
#endif /* HY_ZIP_API */
    if (retval) {
#ifndef HY_ZIP_API
        zip_freeZipEntry(PORTLIB, &zipEntry);
#else /* HY_ZIP_API */
        zipFuncs->zip_freeZipEntry(VMI, &zipEntry);
#endif /* HY_ZIP_API */
        sprintf(errorMessage,"failed to get entry: %d\n", retval);
        (*env)->FatalError(env, errorMessage);
        return NULL;
    }

    /* read bytes */
    size = zipEntry.uncompressedSize;
    result = (char *)hymem_allocate_memory(size*sizeof(char) + 1);
#ifndef HY_ZIP_API
    retval = zip_getZipEntryData(privatePortLibrary, &zipFile, &zipEntry, (unsigned char*)result, size);
#else /* HY_ZIP_API */
    retval = zipFuncs->zip_getZipEntryData(VMI, &zipFile, &zipEntry, (unsigned char*)result, size);
#endif /* HY_ZIP_API */
    if(retval){
#ifndef HY_ZIP_API
        zip_freeZipEntry(PORTLIB, &zipEntry);
#else /* HY_ZIP_API */
        zipFuncs->zip_freeZipEntry(VMI, &zipEntry);
#endif /* HY_ZIP_API */
        sprintf(errorMessage,"failed to get bytes from zip entry, %d\n", zipEntry.extraFieldLength);
        (*env)->FatalError(env, errorMessage);
        return NULL;
    }

    result[size] = '\0';
    /* free resource */
#ifndef HY_ZIP_API
    zip_freeZipEntry(privatePortLibrary, &zipEntry);
    retval = zip_closeZipFile(privatePortLibrary, &zipFile);
#else /* HY_ZIP_API */
    zipFuncs->zip_freeZipEntry(VMI, &zipEntry);
    retval = zipFuncs->zip_closeZipFile(VMI, &zipFile);
#endif /* HY_ZIP_API */
    if (retval) {
        sprintf(errorMessage,"failed to close zip file: %s, %d\n", jar_name, retval);
        (*env)->FatalError(env, errorMessage);
        return NULL;
    }
    return result;
}