author | rwestberg |
Fri, 01 Jun 2018 10:15:48 +0200 | |
changeset 50336 | 1b6ea6bcd21a |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
5506 | 2 |
* Copyright (c) 2004, 2008, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 24 |
*/ |
25 |
||
26 |
#include <string.h> |
|
27 |
#include <stdlib.h> |
|
28 |
||
29 |
#include "jni.h" |
|
30 |
#include "manifest_info.h" |
|
31 |
#include "JarFacade.h" |
|
32 |
||
33 |
typedef struct { |
|
34 |
jarAttribute* head; |
|
35 |
jarAttribute* tail; |
|
36 |
} iterationContext; |
|
37 |
||
38 |
static void |
|
39 |
doAttribute(const char* name, const char* value, void* user_data) { |
|
40 |
iterationContext* context = (iterationContext*) user_data; |
|
41 |
||
42 |
jarAttribute* attribute = (jarAttribute*)malloc(sizeof(jarAttribute)); |
|
43 |
if (attribute != NULL) { |
|
44 |
attribute->name = strdup(name); |
|
45 |
if (attribute->name == NULL) { |
|
46 |
free(attribute); |
|
47 |
} else { |
|
285
1db7e0f6f7b0
6679866: 3/2 portability issues with JLI-batch-200803 on Win*
dcubed
parents:
273
diff
changeset
|
48 |
char *begin = (char *)value; |
273
3d51c181a2e5
6274276: 3/2 java.lang.instrument JAR manifest processing does not remove spaces from class names
dcubed
parents:
2
diff
changeset
|
49 |
char *end; |
285
1db7e0f6f7b0
6679866: 3/2 portability issues with JLI-batch-200803 on Win*
dcubed
parents:
273
diff
changeset
|
50 |
size_t value_len; |
273
3d51c181a2e5
6274276: 3/2 java.lang.instrument JAR manifest processing does not remove spaces from class names
dcubed
parents:
2
diff
changeset
|
51 |
|
3d51c181a2e5
6274276: 3/2 java.lang.instrument JAR manifest processing does not remove spaces from class names
dcubed
parents:
2
diff
changeset
|
52 |
/* skip any leading white space */ |
23014 | 53 |
while (*begin == ' ') { |
273
3d51c181a2e5
6274276: 3/2 java.lang.instrument JAR manifest processing does not remove spaces from class names
dcubed
parents:
2
diff
changeset
|
54 |
begin++; |
3d51c181a2e5
6274276: 3/2 java.lang.instrument JAR manifest processing does not remove spaces from class names
dcubed
parents:
2
diff
changeset
|
55 |
} |
3d51c181a2e5
6274276: 3/2 java.lang.instrument JAR manifest processing does not remove spaces from class names
dcubed
parents:
2
diff
changeset
|
56 |
|
3d51c181a2e5
6274276: 3/2 java.lang.instrument JAR manifest processing does not remove spaces from class names
dcubed
parents:
2
diff
changeset
|
57 |
/* skip any trailing white space */ |
3d51c181a2e5
6274276: 3/2 java.lang.instrument JAR manifest processing does not remove spaces from class names
dcubed
parents:
2
diff
changeset
|
58 |
end = &begin[strlen(begin)]; |
23014 | 59 |
while (end > begin && end[-1] == ' ') { |
273
3d51c181a2e5
6274276: 3/2 java.lang.instrument JAR manifest processing does not remove spaces from class names
dcubed
parents:
2
diff
changeset
|
60 |
end--; |
3d51c181a2e5
6274276: 3/2 java.lang.instrument JAR manifest processing does not remove spaces from class names
dcubed
parents:
2
diff
changeset
|
61 |
} |
3d51c181a2e5
6274276: 3/2 java.lang.instrument JAR manifest processing does not remove spaces from class names
dcubed
parents:
2
diff
changeset
|
62 |
|
3d51c181a2e5
6274276: 3/2 java.lang.instrument JAR manifest processing does not remove spaces from class names
dcubed
parents:
2
diff
changeset
|
63 |
if (begin == end) { |
3d51c181a2e5
6274276: 3/2 java.lang.instrument JAR manifest processing does not remove spaces from class names
dcubed
parents:
2
diff
changeset
|
64 |
/* no value so skip this attribute */ |
3d51c181a2e5
6274276: 3/2 java.lang.instrument JAR manifest processing does not remove spaces from class names
dcubed
parents:
2
diff
changeset
|
65 |
free(attribute->name); |
3d51c181a2e5
6274276: 3/2 java.lang.instrument JAR manifest processing does not remove spaces from class names
dcubed
parents:
2
diff
changeset
|
66 |
free(attribute); |
3d51c181a2e5
6274276: 3/2 java.lang.instrument JAR manifest processing does not remove spaces from class names
dcubed
parents:
2
diff
changeset
|
67 |
return; |
3d51c181a2e5
6274276: 3/2 java.lang.instrument JAR manifest processing does not remove spaces from class names
dcubed
parents:
2
diff
changeset
|
68 |
} |
3d51c181a2e5
6274276: 3/2 java.lang.instrument JAR manifest processing does not remove spaces from class names
dcubed
parents:
2
diff
changeset
|
69 |
|
285
1db7e0f6f7b0
6679866: 3/2 portability issues with JLI-batch-200803 on Win*
dcubed
parents:
273
diff
changeset
|
70 |
value_len = (size_t)(end - begin); |
273
3d51c181a2e5
6274276: 3/2 java.lang.instrument JAR manifest processing does not remove spaces from class names
dcubed
parents:
2
diff
changeset
|
71 |
attribute->value = malloc(value_len + 1); |
2 | 72 |
if (attribute->value == NULL) { |
73 |
free(attribute->name); |
|
74 |
free(attribute); |
|
75 |
} else { |
|
273
3d51c181a2e5
6274276: 3/2 java.lang.instrument JAR manifest processing does not remove spaces from class names
dcubed
parents:
2
diff
changeset
|
76 |
/* save the value without leading or trailing whitespace */ |
3d51c181a2e5
6274276: 3/2 java.lang.instrument JAR manifest processing does not remove spaces from class names
dcubed
parents:
2
diff
changeset
|
77 |
strncpy(attribute->value, begin, value_len); |
285
1db7e0f6f7b0
6679866: 3/2 portability issues with JLI-batch-200803 on Win*
dcubed
parents:
273
diff
changeset
|
78 |
attribute->value[value_len] = '\0'; |
2 | 79 |
attribute->next = NULL; |
80 |
if (context->head == NULL) { |
|
81 |
context->head = attribute; |
|
82 |
} else { |
|
83 |
context->tail->next = attribute; |
|
84 |
} |
|
85 |
context->tail = attribute; |
|
86 |
} |
|
87 |
} |
|
88 |
||
89 |
} |
|
90 |
} |
|
91 |
||
92 |
/* |
|
93 |
* Return a list of attributes from the main section of the given JAR |
|
94 |
* file. Returns NULL if there is an error or there aren't any attributes. |
|
95 |
*/ |
|
96 |
jarAttribute* |
|
97 |
readAttributes(const char* jarfile) |
|
98 |
{ |
|
99 |
int rc; |
|
100 |
iterationContext context = { NULL, NULL }; |
|
101 |
||
102 |
rc = JLI_ManifestIterate(jarfile, doAttribute, (void*)&context); |
|
103 |
||
104 |
if (rc == 0) { |
|
105 |
return context.head; |
|
106 |
} else { |
|
107 |
freeAttributes(context.head); |
|
108 |
return NULL; |
|
109 |
} |
|
110 |
} |
|
111 |
||
112 |
||
113 |
/* |
|
114 |
* Free a list of attributes |
|
115 |
*/ |
|
116 |
void |
|
117 |
freeAttributes(jarAttribute* head) { |
|
118 |
while (head != NULL) { |
|
119 |
jarAttribute* next = (jarAttribute*)head->next; |
|
120 |
free(head->name); |
|
121 |
free(head->value); |
|
122 |
free(head); |
|
123 |
head = next; |
|
124 |
} |
|
125 |
} |
|
126 |
||
127 |
/* |
|
128 |
* Get the value of an attribute in an attribute list. Returns NULL |
|
129 |
* if attribute not found. |
|
130 |
*/ |
|
131 |
char* |
|
132 |
getAttribute(const jarAttribute* attributes, const char* name) { |
|
133 |
while (attributes != NULL) { |
|
134 |
if (strcasecmp(attributes->name, name) == 0) { |
|
135 |
return attributes->value; |
|
136 |
} |
|
137 |
attributes = (jarAttribute*)attributes->next; |
|
138 |
} |
|
139 |
return NULL; |
|
140 |
} |