author | alanb |
Thu, 13 Feb 2014 14:08:12 +0000 | |
changeset 22964 | 59c522d83ed9 |
parent 5506 | 202f599c92aa |
child 23014 | af8145529dd4 |
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 |
||
285
1db7e0f6f7b0
6679866: 3/2 portability issues with JLI-batch-200803 on Win*
dcubed
parents:
273
diff
changeset
|
26 |
#ifdef _WIN32 |
1db7e0f6f7b0
6679866: 3/2 portability issues with JLI-batch-200803 on Win*
dcubed
parents:
273
diff
changeset
|
27 |
/* |
1db7e0f6f7b0
6679866: 3/2 portability issues with JLI-batch-200803 on Win*
dcubed
parents:
273
diff
changeset
|
28 |
* Win* needs this include. However, Linux and Solaris do not. |
1db7e0f6f7b0
6679866: 3/2 portability issues with JLI-batch-200803 on Win*
dcubed
parents:
273
diff
changeset
|
29 |
* Having this include on Solaris SPARC breaks having non US-ASCII |
1db7e0f6f7b0
6679866: 3/2 portability issues with JLI-batch-200803 on Win*
dcubed
parents:
273
diff
changeset
|
30 |
* characters in the value of the Premain-Class attribute. |
1db7e0f6f7b0
6679866: 3/2 portability issues with JLI-batch-200803 on Win*
dcubed
parents:
273
diff
changeset
|
31 |
*/ |
1db7e0f6f7b0
6679866: 3/2 portability issues with JLI-batch-200803 on Win*
dcubed
parents:
273
diff
changeset
|
32 |
#include <ctype.h> |
1db7e0f6f7b0
6679866: 3/2 portability issues with JLI-batch-200803 on Win*
dcubed
parents:
273
diff
changeset
|
33 |
#endif /* _WIN32 */ |
2 | 34 |
#include <string.h> |
35 |
#include <stdlib.h> |
|
22964
59c522d83ed9
8034856: gcc warnings compiling src/solaris/native/sun/security/pkcs11
alanb
parents:
5506
diff
changeset
|
36 |
#include <ctype.h> |
2 | 37 |
|
38 |
#include "jni.h" |
|
39 |
#include "manifest_info.h" |
|
40 |
#include "JarFacade.h" |
|
41 |
||
42 |
typedef struct { |
|
43 |
jarAttribute* head; |
|
44 |
jarAttribute* tail; |
|
45 |
} iterationContext; |
|
46 |
||
47 |
static void |
|
48 |
doAttribute(const char* name, const char* value, void* user_data) { |
|
49 |
iterationContext* context = (iterationContext*) user_data; |
|
50 |
||
51 |
jarAttribute* attribute = (jarAttribute*)malloc(sizeof(jarAttribute)); |
|
52 |
if (attribute != NULL) { |
|
53 |
attribute->name = strdup(name); |
|
54 |
if (attribute->name == NULL) { |
|
55 |
free(attribute); |
|
56 |
} else { |
|
285
1db7e0f6f7b0
6679866: 3/2 portability issues with JLI-batch-200803 on Win*
dcubed
parents:
273
diff
changeset
|
57 |
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
|
58 |
char *end; |
285
1db7e0f6f7b0
6679866: 3/2 portability issues with JLI-batch-200803 on Win*
dcubed
parents:
273
diff
changeset
|
59 |
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
|
60 |
|
3d51c181a2e5
6274276: 3/2 java.lang.instrument JAR manifest processing does not remove spaces from class names
dcubed
parents:
2
diff
changeset
|
61 |
/* skip any leading white space */ |
3d51c181a2e5
6274276: 3/2 java.lang.instrument JAR manifest processing does not remove spaces from class names
dcubed
parents:
2
diff
changeset
|
62 |
while (isspace(*begin)) { |
3d51c181a2e5
6274276: 3/2 java.lang.instrument JAR manifest processing does not remove spaces from class names
dcubed
parents:
2
diff
changeset
|
63 |
begin++; |
3d51c181a2e5
6274276: 3/2 java.lang.instrument JAR manifest processing does not remove spaces from class names
dcubed
parents:
2
diff
changeset
|
64 |
} |
3d51c181a2e5
6274276: 3/2 java.lang.instrument JAR manifest processing does not remove spaces from class names
dcubed
parents:
2
diff
changeset
|
65 |
|
3d51c181a2e5
6274276: 3/2 java.lang.instrument JAR manifest processing does not remove spaces from class names
dcubed
parents:
2
diff
changeset
|
66 |
/* 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
|
67 |
end = &begin[strlen(begin)]; |
3d51c181a2e5
6274276: 3/2 java.lang.instrument JAR manifest processing does not remove spaces from class names
dcubed
parents:
2
diff
changeset
|
68 |
while (end > begin && isspace(end[-1])) { |
3d51c181a2e5
6274276: 3/2 java.lang.instrument JAR manifest processing does not remove spaces from class names
dcubed
parents:
2
diff
changeset
|
69 |
end--; |
3d51c181a2e5
6274276: 3/2 java.lang.instrument JAR manifest processing does not remove spaces from class names
dcubed
parents:
2
diff
changeset
|
70 |
} |
3d51c181a2e5
6274276: 3/2 java.lang.instrument JAR manifest processing does not remove spaces from class names
dcubed
parents:
2
diff
changeset
|
71 |
|
3d51c181a2e5
6274276: 3/2 java.lang.instrument JAR manifest processing does not remove spaces from class names
dcubed
parents:
2
diff
changeset
|
72 |
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
|
73 |
/* 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
|
74 |
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
|
75 |
free(attribute); |
3d51c181a2e5
6274276: 3/2 java.lang.instrument JAR manifest processing does not remove spaces from class names
dcubed
parents:
2
diff
changeset
|
76 |
return; |
3d51c181a2e5
6274276: 3/2 java.lang.instrument JAR manifest processing does not remove spaces from class names
dcubed
parents:
2
diff
changeset
|
77 |
} |
3d51c181a2e5
6274276: 3/2 java.lang.instrument JAR manifest processing does not remove spaces from class names
dcubed
parents:
2
diff
changeset
|
78 |
|
285
1db7e0f6f7b0
6679866: 3/2 portability issues with JLI-batch-200803 on Win*
dcubed
parents:
273
diff
changeset
|
79 |
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
|
80 |
attribute->value = malloc(value_len + 1); |
2 | 81 |
if (attribute->value == NULL) { |
82 |
free(attribute->name); |
|
83 |
free(attribute); |
|
84 |
} else { |
|
273
3d51c181a2e5
6274276: 3/2 java.lang.instrument JAR manifest processing does not remove spaces from class names
dcubed
parents:
2
diff
changeset
|
85 |
/* 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
|
86 |
strncpy(attribute->value, begin, value_len); |
285
1db7e0f6f7b0
6679866: 3/2 portability issues with JLI-batch-200803 on Win*
dcubed
parents:
273
diff
changeset
|
87 |
attribute->value[value_len] = '\0'; |
2 | 88 |
attribute->next = NULL; |
89 |
if (context->head == NULL) { |
|
90 |
context->head = attribute; |
|
91 |
} else { |
|
92 |
context->tail->next = attribute; |
|
93 |
} |
|
94 |
context->tail = attribute; |
|
95 |
} |
|
96 |
} |
|
97 |
||
98 |
} |
|
99 |
} |
|
100 |
||
101 |
/* |
|
102 |
* Return a list of attributes from the main section of the given JAR |
|
103 |
* file. Returns NULL if there is an error or there aren't any attributes. |
|
104 |
*/ |
|
105 |
jarAttribute* |
|
106 |
readAttributes(const char* jarfile) |
|
107 |
{ |
|
108 |
int rc; |
|
109 |
iterationContext context = { NULL, NULL }; |
|
110 |
||
111 |
rc = JLI_ManifestIterate(jarfile, doAttribute, (void*)&context); |
|
112 |
||
113 |
if (rc == 0) { |
|
114 |
return context.head; |
|
115 |
} else { |
|
116 |
freeAttributes(context.head); |
|
117 |
return NULL; |
|
118 |
} |
|
119 |
} |
|
120 |
||
121 |
||
122 |
/* |
|
123 |
* Free a list of attributes |
|
124 |
*/ |
|
125 |
void |
|
126 |
freeAttributes(jarAttribute* head) { |
|
127 |
while (head != NULL) { |
|
128 |
jarAttribute* next = (jarAttribute*)head->next; |
|
129 |
free(head->name); |
|
130 |
free(head->value); |
|
131 |
free(head); |
|
132 |
head = next; |
|
133 |
} |
|
134 |
} |
|
135 |
||
136 |
/* |
|
137 |
* Get the value of an attribute in an attribute list. Returns NULL |
|
138 |
* if attribute not found. |
|
139 |
*/ |
|
140 |
char* |
|
141 |
getAttribute(const jarAttribute* attributes, const char* name) { |
|
142 |
while (attributes != NULL) { |
|
143 |
if (strcasecmp(attributes->name, name) == 0) { |
|
144 |
return attributes->value; |
|
145 |
} |
|
146 |
attributes = (jarAttribute*)attributes->next; |
|
147 |
} |
|
148 |
return NULL; |
|
149 |
} |