< prev index next >

src/java.base/share/native/libjli/parse_manifest.c

Print this page


   1 /*
   2  * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 #include <sys/types.h>
  27 #include <sys/stat.h>
  28 #include <fcntl.h>
  29 #include <stdio.h>
  30 #include <stdlib.h>
  31 #include <string.h>

  32 #include "jli_util.h"
  33 
  34 #include <zlib.h>
  35 #include "manifest_info.h"
  36 
  37 static char     *manifest;
  38 
  39 static const char       *manifest_name = "META-INF/MANIFEST.MF";
  40 
  41 /*
  42  * Inflate the manifest file (or any file for that matter).
  43  *
  44  *   fd:        File descriptor of the jar file.
  45  *   entry:     Contains the information necessary to perform the inflation
  46  *              (the compressed and uncompressed sizes and the offset in
  47  *              the file where the compressed data is located).
  48  *   size_out:  Returns the size of the inflated file.
  49  *
  50  * Upon success, it returns a pointer to a NUL-terminated malloc'd buffer
  51  * containing the inflated manifest file.  When the caller is done with it,


 659 /*
 660  * Specialized "free" function.
 661  */
 662 void
 663 JLI_FreeManifest()
 664 {
 665     if (manifest)
 666         free(manifest);
 667 }
 668 
 669 /*
 670  * Iterate over the manifest of the specified jar file and invoke the provided
 671  * closure function for each attribute encountered.
 672  *
 673  * Error returns are as follows:
 674  *    0 Success
 675  *   -1 Unable to open jarfile
 676  *   -2 Error accessing the manifest from within the jarfile (most likely
 677  *      this means a manifest is not present, or it isn't a valid zip/jar file).
 678  */
 679 int
 680 JLI_ManifestIterate(const char *jarfile, attribute_closure ac, void *user_data)
 681 {
 682     int     fd;
 683     zentry  entry;
 684     char    *mp;        /* manifest pointer */
 685     char    *lp;        /* pointer into manifest, updated during iteration */
 686     char    *name;
 687     char    *value;
 688     int     rc;
 689 
 690     if ((fd = open(jarfile, O_RDONLY
 691 #ifdef O_LARGEFILE
 692         | O_LARGEFILE /* large file mode */
 693 #endif
 694 #ifdef O_BINARY
 695         | O_BINARY /* use binary mode on windows */
 696 #endif
 697         )) == -1) {
 698         return (-1);
 699     }
   1 /*
   2  * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 #include <sys/types.h>
  27 #include <sys/stat.h>
  28 #include <fcntl.h>
  29 #include <stdio.h>
  30 #include <stdlib.h>
  31 #include <string.h>
  32 #include "jni.h"
  33 #include "jli_util.h"
  34 
  35 #include <zlib.h>
  36 #include "manifest_info.h"
  37 
  38 static char     *manifest;
  39 
  40 static const char       *manifest_name = "META-INF/MANIFEST.MF";
  41 
  42 /*
  43  * Inflate the manifest file (or any file for that matter).
  44  *
  45  *   fd:        File descriptor of the jar file.
  46  *   entry:     Contains the information necessary to perform the inflation
  47  *              (the compressed and uncompressed sizes and the offset in
  48  *              the file where the compressed data is located).
  49  *   size_out:  Returns the size of the inflated file.
  50  *
  51  * Upon success, it returns a pointer to a NUL-terminated malloc'd buffer
  52  * containing the inflated manifest file.  When the caller is done with it,


 660 /*
 661  * Specialized "free" function.
 662  */
 663 void
 664 JLI_FreeManifest()
 665 {
 666     if (manifest)
 667         free(manifest);
 668 }
 669 
 670 /*
 671  * Iterate over the manifest of the specified jar file and invoke the provided
 672  * closure function for each attribute encountered.
 673  *
 674  * Error returns are as follows:
 675  *    0 Success
 676  *   -1 Unable to open jarfile
 677  *   -2 Error accessing the manifest from within the jarfile (most likely
 678  *      this means a manifest is not present, or it isn't a valid zip/jar file).
 679  */
 680 JNIEXPORT int JNICALL
 681 JLI_ManifestIterate(const char *jarfile, attribute_closure ac, void *user_data)
 682 {
 683     int     fd;
 684     zentry  entry;
 685     char    *mp;        /* manifest pointer */
 686     char    *lp;        /* pointer into manifest, updated during iteration */
 687     char    *name;
 688     char    *value;
 689     int     rc;
 690 
 691     if ((fd = open(jarfile, O_RDONLY
 692 #ifdef O_LARGEFILE
 693         | O_LARGEFILE /* large file mode */
 694 #endif
 695 #ifdef O_BINARY
 696         | O_BINARY /* use binary mode on windows */
 697 #endif
 698         )) == -1) {
 699         return (-1);
 700     }
< prev index next >