54 } |
54 } |
55 |
55 |
56 return result; |
56 return result; |
57 } |
57 } |
58 |
58 |
59 LinuxPlatform::LinuxPlatform(void) : Platform(), GenericPlatform(), PosixPlatform() { |
59 LinuxPlatform::LinuxPlatform(void) : Platform(), |
|
60 GenericPlatform(), PosixPlatform() { |
60 FMainThread = pthread_self(); |
61 FMainThread = pthread_self(); |
61 } |
62 } |
62 |
63 |
63 LinuxPlatform::~LinuxPlatform(void) { |
64 LinuxPlatform::~LinuxPlatform(void) { |
64 } |
65 } |
65 |
66 |
66 void LinuxPlatform::ShowMessage(TString title, TString description) { |
67 void LinuxPlatform::ShowMessage(TString title, TString description) { |
67 printf("%s %s\n", PlatformString(title).toPlatformString(), PlatformString(description).toPlatformString()); |
68 printf("%s %s\n", PlatformString(title).toPlatformString(), |
|
69 PlatformString(description).toPlatformString()); |
68 fflush(stdout); |
70 fflush(stdout); |
69 } |
71 } |
70 |
72 |
71 void LinuxPlatform::ShowMessage(TString description) { |
73 void LinuxPlatform::ShowMessage(TString description) { |
72 TString appname = GetModuleFileName(); |
74 TString appname = GetModuleFileName(); |
73 appname = FilePath::ExtractFileName(appname); |
75 appname = FilePath::ExtractFileName(appname); |
74 ShowMessage(PlatformString(appname).toPlatformString(), PlatformString(description).toPlatformString()); |
76 ShowMessage(PlatformString(appname).toPlatformString(), |
75 } |
77 PlatformString(description).toPlatformString()); |
76 |
78 } |
77 TCHAR* LinuxPlatform::ConvertStringToFileSystemString(TCHAR* Source, bool &release) { |
79 |
|
80 TCHAR* LinuxPlatform::ConvertStringToFileSystemString(TCHAR* Source, |
|
81 bool &release) { |
78 // Not Implemented. |
82 // Not Implemented. |
79 return NULL; |
83 return NULL; |
80 } |
84 } |
81 |
85 |
82 TCHAR* LinuxPlatform::ConvertFileSystemStringToString(TCHAR* Source, bool &release) { |
86 TCHAR* LinuxPlatform::ConvertFileSystemStringToString(TCHAR* Source, |
|
87 bool &release) { |
83 // Not Implemented. |
88 // Not Implemented. |
84 return NULL; |
89 return NULL; |
85 } |
90 } |
86 |
91 |
87 TString LinuxPlatform::GetModuleFileName() { |
92 TString LinuxPlatform::GetModuleFileName() { |
88 ssize_t len = 0; |
93 ssize_t len = 0; |
89 TString result; |
94 TString result; |
90 DynamicBuffer<TCHAR> buffer(MAX_PATH); |
95 DynamicBuffer<TCHAR> buffer(MAX_PATH); |
91 |
96 |
92 if ((len = readlink("/proc/self/exe", buffer.GetData(), MAX_PATH - 1)) != -1) { |
97 if ((len = readlink("/proc/self/exe", buffer.GetData(), |
|
98 MAX_PATH - 1)) != -1) { |
93 buffer[len] = '\0'; |
99 buffer[len] = '\0'; |
94 result = buffer.GetData(); |
100 result = buffer.GetData(); |
95 } |
101 } |
96 |
102 |
97 return result; |
103 return result; |
109 TString LinuxPlatform::GetAppDataDirectory() { |
115 TString LinuxPlatform::GetAppDataDirectory() { |
110 TString result; |
116 TString result; |
111 TString home = GetEnv(_T("HOME")); |
117 TString home = GetEnv(_T("HOME")); |
112 |
118 |
113 if (home.empty() == false) { |
119 if (home.empty() == false) { |
114 result += FilePath::IncludeTrailingSeparater(home) + _T(".local"); |
120 result += FilePath::IncludeTrailingSeparator(home) + _T(".local"); |
115 } |
121 } |
116 |
122 |
117 return result; |
123 return result; |
118 } |
124 } |
119 |
125 |
120 ISectionalPropertyContainer* LinuxPlatform::GetConfigFile(TString FileName) { |
126 ISectionalPropertyContainer* LinuxPlatform::GetConfigFile(TString FileName) { |
121 IniFile *result = new IniFile(); |
127 IniFile *result = new IniFile(); |
122 |
128 |
123 if (result->LoadFromFile(FileName) == false) { |
129 if (result->LoadFromFile(FileName) == false) { |
124 // New property file format was not found, attempt to load old property file format. |
130 // New property file format was not found, |
|
131 // attempt to load old property file format. |
125 Helpers::LoadOldConfigFile(FileName, result); |
132 Helpers::LoadOldConfigFile(FileName, result); |
126 } |
133 } |
127 |
134 |
128 return result; |
135 return result; |
129 } |
136 } |
130 |
137 |
131 TString LinuxPlatform::GetBundledJVMLibraryFileName(TString RuntimePath) { |
138 TString LinuxPlatform::GetBundledJVMLibraryFileName(TString RuntimePath) { |
132 TString result = FilePath::IncludeTrailingSeparater(RuntimePath) + |
139 TString result = FilePath::IncludeTrailingSeparator(RuntimePath) + |
133 "lib/libjli.so"; |
140 "lib/libjli.so"; |
134 |
141 |
135 if (FilePath::FileExists(result) == false) { |
142 if (FilePath::FileExists(result) == false) { |
136 result = FilePath::IncludeTrailingSeparater(RuntimePath) + |
143 result = FilePath::IncludeTrailingSeparator(RuntimePath) + |
137 "lib/jli/libjli.so"; |
144 "lib/jli/libjli.so"; |
138 if (FilePath::FileExists(result) == false) { |
145 if (FilePath::FileExists(result) == false) { |
139 printf("Cannot find libjli.so!"); |
146 printf("Cannot find libjli.so!"); |
140 } |
147 } |
141 } |
148 } |
204 |
211 |
205 #define TCHAR char |
212 #define TCHAR char |
206 |
213 |
207 #define _T(x) x |
214 #define _T(x) x |
208 |
215 |
209 #define DEPLOY_MULTIBYTE_SNPRINTF snprintf |
216 #define PACKAGER_MULTIBYTE_SNPRINTF snprintf |
210 |
217 |
211 #define DEPLOY_SNPRINTF(buffer, sizeOfBuffer, count, format, ...) \ |
218 #define PACKAGER_SNPRINTF(buffer, sizeOfBuffer, count, format, ...) \ |
212 snprintf((buffer), (count), (format), __VA_ARGS__) |
219 snprintf((buffer), (count), (format), __VA_ARGS__) |
213 |
220 |
214 #define DEPLOY_PRINTF(format, ...) \ |
221 #define PACKAGER_PRINTF(format, ...) \ |
215 printf((format), ##__VA_ARGS__) |
222 printf((format), ##__VA_ARGS__) |
216 |
223 |
217 #define DEPLOY_FPRINTF(dest, format, ...) \ |
224 #define PACKAGER_FPRINTF(dest, format, ...) \ |
218 fprintf((dest), (format), __VA_ARGS__) |
225 fprintf((dest), (format), __VA_ARGS__) |
219 |
226 |
220 #define DEPLOY_SSCANF(buf, format, ...) \ |
227 #define PACKAGER_SSCANF(buf, format, ...) \ |
221 sscanf((buf), (format), __VA_ARGS__) |
228 sscanf((buf), (format), __VA_ARGS__) |
222 |
229 |
223 #define DEPLOY_STRDUP(strSource) \ |
230 #define PACKAGER_STRDUP(strSource) \ |
224 strdup((strSource)) |
231 strdup((strSource)) |
225 |
232 |
226 //return "error code" (like on Windows) |
233 //return "error code" (like on Windows) |
227 static int DEPLOY_STRNCPY(char *strDest, size_t numberOfElements, const char *strSource, size_t count) { |
234 static int PACKAGER_STRNCPY(char *strDest, size_t numberOfElements, |
|
235 const char *strSource, size_t count) { |
228 char *s = strncpy(strDest, strSource, count); |
236 char *s = strncpy(strDest, strSource, count); |
229 // Duplicate behavior of the Windows' _tcsncpy_s() by adding a NULL |
237 // Duplicate behavior of the Windows' _tcsncpy_s() by adding a NULL |
230 // terminator at the end of the string. |
238 // terminator at the end of the string. |
231 if (count < numberOfElements) { |
239 if (count < numberOfElements) { |
232 s[count] = '\0'; |
240 s[count] = '\0'; |
234 s[numberOfElements - 1] = '\0'; |
242 s[numberOfElements - 1] = '\0'; |
235 } |
243 } |
236 return (s == strDest) ? 0 : 1; |
244 return (s == strDest) ? 0 : 1; |
237 } |
245 } |
238 |
246 |
239 #define DEPLOY_STRICMP(x, y) \ |
247 #define PACKAGER_STRICMP(x, y) \ |
240 strcasecmp((x), (y)) |
248 strcasecmp((x), (y)) |
241 |
249 |
242 #define DEPLOY_STRNICMP(x, y, cnt) \ |
250 #define PACKAGER_STRNICMP(x, y, cnt) \ |
243 strncasecmp((x), (y), (cnt)) |
251 strncasecmp((x), (y), (cnt)) |
244 |
252 |
245 #define DEPLOY_STRNCMP(x, y, cnt) \ |
253 #define PACKAGER_STRNCMP(x, y, cnt) \ |
246 strncmp((x), (y), (cnt)) |
254 strncmp((x), (y), (cnt)) |
247 |
255 |
248 #define DEPLOY_STRLEN(x) \ |
256 #define PACKAGER_STRLEN(x) \ |
249 strlen((x)) |
257 strlen((x)) |
250 |
258 |
251 #define DEPLOY_STRSTR(x, y) \ |
259 #define PACKAGER_STRSTR(x, y) \ |
252 strstr((x), (y)) |
260 strstr((x), (y)) |
253 |
261 |
254 #define DEPLOY_STRCHR(x, y) \ |
262 #define PACKAGER_STRCHR(x, y) \ |
255 strchr((x), (y)) |
263 strchr((x), (y)) |
256 |
264 |
257 #define DEPLOY_STRRCHR(x, y) \ |
265 #define PACKAGER_STRRCHR(x, y) \ |
258 strrchr((x), (y)) |
266 strrchr((x), (y)) |
259 |
267 |
260 #define DEPLOY_STRPBRK(x, y) \ |
268 #define PACKAGER_STRPBRK(x, y) \ |
261 strpbrk((x), (y)) |
269 strpbrk((x), (y)) |
262 |
270 |
263 #define DEPLOY_GETENV(x) \ |
271 #define PACKAGER_GETENV(x) \ |
264 getenv((x)) |
272 getenv((x)) |
265 |
273 |
266 #define DEPLOY_PUTENV(x) \ |
274 #define PACKAGER_PUTENV(x) \ |
267 putenv((x)) |
275 putenv((x)) |
268 |
276 |
269 #define DEPLOY_STRCMP(x, y) \ |
277 #define PACKAGER_STRCMP(x, y) \ |
270 strcmp((x), (y)) |
278 strcmp((x), (y)) |
271 |
279 |
272 #define DEPLOY_STRCPY(x, y) \ |
280 #define PACKAGER_STRCPY(x, y) \ |
273 strcpy((x), (y)) |
281 strcpy((x), (y)) |
274 |
282 |
275 #define DEPLOY_STRCAT(x, y) \ |
283 #define PACKAGER_STRCAT(x, y) \ |
276 strcat((x), (y)) |
284 strcat((x), (y)) |
277 |
285 |
278 #define DEPLOY_ATOI(x) \ |
286 #define PACKAGER_ATOI(x) \ |
279 atoi((x)) |
287 atoi((x)) |
280 |
288 |
281 #define DEPLOY_FOPEN(x, y) \ |
289 #define PACKAGER_FOPEN(x, y) \ |
282 fopen((x), (y)) |
290 fopen((x), (y)) |
283 |
291 |
284 #define DEPLOY_FGETS(x, y, z) \ |
292 #define PACKAGER_FGETS(x, y, z) \ |
285 fgets((x), (y), (z)) |
293 fgets((x), (y), (z)) |
286 |
294 |
287 #define DEPLOY_REMOVE(x) \ |
295 #define PACKAGER_REMOVE(x) \ |
288 remove((x)) |
296 remove((x)) |
289 |
297 |
290 #define DEPLOY_SPAWNV(mode, cmd, args) \ |
298 #define PACKAGER_SPAWNV(mode, cmd, args) \ |
291 spawnv((mode), (cmd), (args)) |
299 spawnv((mode), (cmd), (args)) |
292 |
300 |
293 #define DEPLOY_ISDIGIT(ch) isdigit(ch) |
301 #define PACKAGER_ISDIGIT(ch) isdigit(ch) |
294 |
302 |
295 // for non-unicode, just return the input string for |
303 // for non-unicode, just return the input string for |
296 // the following 2 conversions |
304 // the following 2 conversions |
297 #define DEPLOY_NEW_MULTIBYTE(message) message |
305 #define PACKAGER_NEW_MULTIBYTE(message) message |
298 |
306 |
299 #define DEPLOY_NEW_FROM_MULTIBYTE(message) message |
307 #define PACKAGER_NEW_FROM_MULTIBYTE(message) message |
300 |
308 |
301 // for non-unicode, no-op for the relase operation |
309 // for non-unicode, no-op for the relase operation |
302 // since there is no memory allocated for the |
310 // since there is no memory allocated for the |
303 // string conversions |
311 // string conversions |
304 #define DEPLOY_RELEASE_MULTIBYTE(tmpMBCS) |
312 #define PACKAGER_RELEASE_MULTIBYTE(tmpMBCS) |
305 |
313 |
306 #define DEPLOY_RELEASE_FROM_MULTIBYTE(tmpMBCS) |
314 #define PACKAGER_RELEASE_FROM_MULTIBYTE(tmpMBCS) |
307 |
315 |
308 // The size will be used for converting from 1 byte to 1 byte encoding. |
316 // The size will be used for converting from 1 byte to 1 byte encoding. |
309 // Ensure have space for zero-terminator. |
317 // Ensure have space for zero-terminator. |
310 #define DEPLOY_GET_SIZE_FOR_ENCODING(message, theLength) (theLength + 1) |
318 #define PACKAGER_GET_SIZE_FOR_ENCODING(message, theLength) (theLength + 1) |
311 |
319 |
312 #endif |
320 #endif |
313 #define xmlTagType 0 |
321 #define xmlTagType 0 |
314 #define xmlPCDataType 1 |
322 #define xmlPCDataType 1 |
315 |
323 |
382 * that can be handled in ParseXMLDocument() |
390 * that can be handled in ParseXMLDocument() |
383 */ |
391 */ |
384 #define JMP_NO_ERROR 0 |
392 #define JMP_NO_ERROR 0 |
385 #define JMP_OUT_OF_RANGE 1 |
393 #define JMP_OUT_OF_RANGE 1 |
386 |
394 |
387 #define NEXT_CHAR(p) {if (*p != 0) { p++;} else {longjmp(jmpbuf, JMP_OUT_OF_RANGE);}} |
395 #define NEXT_CHAR(p) { \ |
388 #define NEXT_CHAR_OR_BREAK(p) {if (*p != 0) { p++;} else {break;}} |
396 if (*p != 0) { \ |
389 #define NEXT_CHAR_OR_RETURN(p) {if (*p != 0) { p++;} else {return;}} |
397 p++; \ |
390 #define SKIP_CHARS(p,n) {int i; for (i = 0; i < (n); i++) \ |
398 } else { \ |
391 {if (*p != 0) { p++;} else \ |
399 longjmp(jmpbuf, JMP_OUT_OF_RANGE); \ |
392 {longjmp(jmpbuf, JMP_OUT_OF_RANGE);}}} |
400 } \ |
393 #define SKIP_CHARS_OR_BREAK(p,n) {int i; for (i = 0; i < (n); i++) \ |
401 } |
394 {if (*p != 0) { p++;} else {break;}} \ |
402 #define NEXT_CHAR_OR_BREAK(p) { \ |
395 {if (i < (n)) {break;}}} |
403 if (*p != 0) { \ |
396 |
404 p++; \ |
397 /** Iterates through the null-terminated buffer (i.e., C string) and replaces all |
405 } else { \ |
398 * UTF-8 encoded character >255 with 255 |
406 break; \ |
|
407 } \ |
|
408 } |
|
409 #define NEXT_CHAR_OR_RETURN(p) { \ |
|
410 if (*p != 0) { \ |
|
411 p++; \ |
|
412 } else { \ |
|
413 return; \ |
|
414 } \ |
|
415 } |
|
416 #define SKIP_CHARS(p,n) { \ |
|
417 int i; \ |
|
418 for (i = 0; i < (n); i++) { \ |
|
419 if (*p != 0) { \ |
|
420 p++; \ |
|
421 } else { \ |
|
422 longjmp(jmpbuf, JMP_OUT_OF_RANGE); \ |
|
423 } \ |
|
424 } \ |
|
425 } |
|
426 #define SKIP_CHARS_OR_BREAK(p,n) { \ |
|
427 int i; \ |
|
428 for (i = 0; i < (n); i++) { \ |
|
429 if (*p != 0) { \ |
|
430 p++; \ |
|
431 } else { \ |
|
432 break; \ |
|
433 } \ |
|
434 } \ |
|
435 if (i < (n)) { \ |
|
436 break; \ |
|
437 } \ |
|
438 } |
|
439 |
|
440 /** Iterates through the null-terminated buffer (i.e., C string) and |
|
441 * replaces all UTF-8 encoded character >255 with 255 |
399 * |
442 * |
400 * UTF-8 encoding: |
443 * UTF-8 encoding: |
401 * |
444 * |
402 * Range A: 0x0000 - 0x007F |
445 * Range A: 0x0000 - 0x007F |
403 * 0 | bits 0 - 7 |
446 * 0 | bits 0 - 7 |
520 * and convert them to a real TCHARacter |
561 * and convert them to a real TCHARacter |
521 */ |
562 */ |
522 static void ConvertBuiltInEntities(TCHAR* p) { |
563 static void ConvertBuiltInEntities(TCHAR* p) { |
523 TCHAR* q; |
564 TCHAR* q; |
524 q = p; |
565 q = p; |
525 /* We are not using NEXT_CHAR() to check if *q is NULL, as q is output location |
566 // We are not using NEXT_CHAR() to check if *q is NULL, |
526 and offset for q is smaller than for p. */ |
567 // as q is output location and offset for q is smaller than for p. |
527 while(*p) { |
568 while(*p) { |
528 if (IsPCData(p)) { |
569 if (IsPCData(p)) { |
529 /* dont convert &xxx values within PData */ |
570 /* dont convert &xxx values within PData */ |
530 TCHAR *end; |
571 TCHAR *end; |
531 end = SkipPCData(p); |
572 end = SkipPCData(p); |
532 while(p < end) { |
573 while(p < end) { |
533 *q++ = *p; |
574 *q++ = *p; |
534 NEXT_CHAR(p); |
575 NEXT_CHAR(p); |
535 } |
576 } |
536 } else { |
|
537 if (DEPLOY_STRNCMP(p, _T("&"), 5) == 0) { |
|
538 *q++ = '&'; |
|
539 SKIP_CHARS(p, 5); |
|
540 } else if (DEPLOY_STRNCMP(p, _T("<"), 4) == 0) { |
|
541 *q = '<'; |
|
542 SKIP_CHARS(p, 4); |
|
543 } else if (DEPLOY_STRNCMP(p, _T(">"), 4) == 0) { |
|
544 *q = '>'; |
|
545 SKIP_CHARS(p, 4); |
|
546 } else if (DEPLOY_STRNCMP(p, _T("'"), 6) == 0) { |
|
547 *q = '\''; |
|
548 SKIP_CHARS(p, 6); |
|
549 } else if (DEPLOY_STRNCMP(p, _T(""e;"), 7) == 0) { |
|
550 *q = '\"'; |
|
551 SKIP_CHARS(p, 7); |
|
552 } else { |
577 } else { |
553 *q++ = *p; |
578 if (PACKAGER_STRNCMP(p, _T("&"), 5) == 0) { |
554 NEXT_CHAR(p); |
579 *q++ = '&'; |
555 } |
580 SKIP_CHARS(p, 5); |
556 } |
581 } else if (PACKAGER_STRNCMP(p, _T("<"), 4) == 0) { |
|
582 *q = '<'; |
|
583 SKIP_CHARS(p, 4); |
|
584 } else if (PACKAGER_STRNCMP(p, _T(">"), 4) == 0) { |
|
585 *q = '>'; |
|
586 SKIP_CHARS(p, 4); |
|
587 } else if (PACKAGER_STRNCMP(p, _T("'"), 6) == 0) { |
|
588 *q = '\''; |
|
589 SKIP_CHARS(p, 6); |
|
590 } else if (PACKAGER_STRNCMP(p, _T(""e;"), 7) == 0) { |
|
591 *q = '\"'; |
|
592 SKIP_CHARS(p, 7); |
|
593 } else { |
|
594 *q++ = *p; |
|
595 NEXT_CHAR(p); |
|
596 } |
|
597 } |
557 } |
598 } |
558 *q = '\0'; |
599 *q = '\0'; |
559 } |
600 } |
560 |
601 |
561 /* ------------------------------------------------------------- */ |
602 /* ------------------------------------------------------------- */ |
873 } |
915 } |
874 |
916 |
875 //Note: no need to free name and CurTokenName duplicate; they're assigned |
917 //Note: no need to free name and CurTokenName duplicate; they're assigned |
876 // to an XMLAttribute structure in CreateXMLAttribute |
918 // to an XMLAttribute structure in CreateXMLAttribute |
877 |
919 |
878 return CreateXMLAttribute(name, DEPLOY_STRDUP(CurTokenName)); |
920 return CreateXMLAttribute(name, PACKAGER_STRDUP(CurTokenName)); |
879 } |
921 } |
880 |
922 |
881 void FreeXMLDocument(XMLNode* root) { |
923 void FreeXMLDocument(XMLNode* root) { |
882 if (root == NULL) return; |
924 if (root == NULL) return; |
883 FreeXMLDocument(root->_sub); |
925 FreeXMLDocument(root->_sub); |
884 FreeXMLDocument(root->_next); |
926 FreeXMLDocument(root->_next); |
885 FreeXMLAttribute(root->_attributes); |
927 FreeXMLAttribute(root->_attributes); |
886 free(root->_name); |
928 free(root->_name); |
887 free(root); |
929 free(root); |
888 } |
930 } |
889 |
931 |
890 static void FreeXMLAttribute(XMLAttribute* attr) { |
932 static void FreeXMLAttribute(XMLAttribute* attr) { |
891 if (attr == NULL) return; |
933 if (attr == NULL) return; |
892 free(attr->_name); |
934 free(attr->_name); |
893 free(attr->_value); |
935 free(attr->_value); |
894 FreeXMLAttribute(attr->_next); |
936 FreeXMLAttribute(attr->_next); |
895 free(attr); |
937 free(attr); |
896 } |
938 } |
897 |
939 |
898 /* Find element at current level with a given name */ |
940 /* Find element at current level with a given name */ |
899 XMLNode* FindXMLChild(XMLNode* root, const TCHAR* name) { |
941 XMLNode* FindXMLChild(XMLNode* root, const TCHAR* name) { |
900 if (root == NULL) return NULL; |
942 if (root == NULL) return NULL; |
901 |
943 |
902 if (root->_type == xmlTagType && DEPLOY_STRCMP(root->_name, name) == 0) { |
944 if (root->_type == xmlTagType && PACKAGER_STRCMP(root->_name, name) == 0) { |
903 return root; |
945 return root; |
904 } |
946 } |
905 |
947 |
906 return FindXMLChild(root->_next, name); |
948 return FindXMLChild(root->_next, name); |
907 } |
949 } |
908 |
950 |
909 /* Search for an attribute with the given name and returns the contents. Returns NULL if |
951 /* Search for an attribute with the given name and returns the contents. Returns NULL if |
910 * attribute is not found |
952 * attribute is not found |
911 */ |
953 */ |
912 TCHAR* FindXMLAttribute(XMLAttribute* attr, const TCHAR* name) { |
954 TCHAR* FindXMLAttribute(XMLAttribute* attr, const TCHAR* name) { |
913 if (attr == NULL) return NULL; |
955 if (attr == NULL) return NULL; |
914 if (DEPLOY_STRCMP(attr->_name, name) == 0) return attr->_value; |
956 if (PACKAGER_STRCMP(attr->_name, name) == 0) return attr->_value; |
915 return FindXMLAttribute(attr->_next, name); |
957 return FindXMLAttribute(attr->_next, name); |
916 } |
958 } |
917 |
959 |
918 |
960 |
919 void PrintXMLDocument(XMLNode* node, int indt) { |
961 void PrintXMLDocument(XMLNode* node, int indt) { |
920 if (node == NULL) return; |
962 if (node == NULL) return; |
921 |
963 |
922 if (node->_type == xmlTagType) { |
964 if (node->_type == xmlTagType) { |
923 DEPLOY_PRINTF(_T("\n")); |
965 PACKAGER_PRINTF(_T("\n")); |
924 indent(indt); |
966 indent(indt); |
925 DEPLOY_PRINTF(_T("<%s"), node->_name); |
967 PACKAGER_PRINTF(_T("<%s"), node->_name); |
926 PrintXMLAttributes(node->_attributes); |
968 PrintXMLAttributes(node->_attributes); |
927 if (node->_sub == NULL) { |
969 if (node->_sub == NULL) { |
928 DEPLOY_PRINTF(_T("/>\n")); |
970 PACKAGER_PRINTF(_T("/>\n")); |
929 } else { |
971 } else { |
930 DEPLOY_PRINTF(_T(">")); |
972 PACKAGER_PRINTF(_T(">")); |
931 PrintXMLDocument(node->_sub, indt + 1); |
973 PrintXMLDocument(node->_sub, indt + 1); |
932 indent(indt); |
974 indent(indt); |
933 DEPLOY_PRINTF(_T("</%s>"), node->_name); |
975 PACKAGER_PRINTF(_T("</%s>"), node->_name); |
934 } |
976 } |
935 } else { |
977 } else { |
936 DEPLOY_PRINTF(_T("%s"), node->_name); |
978 PACKAGER_PRINTF(_T("%s"), node->_name); |
937 } |
979 } |
938 PrintXMLDocument(node->_next, indt); |
980 PrintXMLDocument(node->_next, indt); |
939 } |
981 } |
940 |
982 |
941 static void PrintXMLAttributes(XMLAttribute* attr) { |
983 static void PrintXMLAttributes(XMLAttribute* attr) { |
942 if (attr == NULL) return; |
984 if (attr == NULL) return; |
943 |
985 |
944 DEPLOY_PRINTF(_T(" %s=\"%s\""), attr->_name, attr->_value); |
986 PACKAGER_PRINTF(_T(" %s=\"%s\""), attr->_name, attr->_value); |
945 PrintXMLAttributes(attr->_next); |
987 PrintXMLAttributes(attr->_next); |
946 } |
988 } |
947 |
989 |
948 static void indent(int indt) { |
990 static void indent(int indt) { |
949 int i; |
991 int i; |
950 for(i = 0; i < indt; i++) { |
992 for(i = 0; i < indt; i++) { |
951 DEPLOY_PRINTF(_T(" ")); |
993 PACKAGER_PRINTF(_T(" ")); |
952 } |
994 } |
953 } |
995 } |
954 |
996 |
955 const TCHAR *CDStart = _T("<![CDATA["); |
997 const TCHAR *CDStart = _T("<![CDATA["); |
956 const TCHAR *CDEnd = _T("]]>"); |
998 const TCHAR *CDEnd = _T("]]>"); |
957 |
999 |
958 |
1000 |
959 static TCHAR* SkipPCData(TCHAR *p) { |
1001 static TCHAR* SkipPCData(TCHAR *p) { |
960 TCHAR *end = DEPLOY_STRSTR(p, CDEnd); |
1002 TCHAR *end = PACKAGER_STRSTR(p, CDEnd); |
961 if (end != NULL) { |
1003 if (end != NULL) { |
962 return end+sizeof(CDEnd); |
1004 return end+sizeof(CDEnd); |
963 } |
1005 } |
964 return (++p); |
1006 return (++p); |
965 } |
1007 } |
966 |
1008 |
967 static int IsPCData(TCHAR *p) { |
1009 static int IsPCData(TCHAR *p) { |
968 const int size = sizeof(CDStart); |
1010 const int size = sizeof(CDStart); |
969 return (DEPLOY_STRNCMP(CDStart, p, size) == 0); |
1011 return (PACKAGER_STRNCMP(CDStart, p, size) == 0); |
970 } |
1012 } |
971 |
1013 |
972 //-------------------------------------------------------------------------------------------------- |
1014 //---------------------------------------------------------------------------- |
973 |
1015 |
974 LinuxJavaUserPreferences::LinuxJavaUserPreferences(void) : JavaUserPreferences() { |
1016 LinuxJavaUserPreferences::LinuxJavaUserPreferences(void) : |
|
1017 JavaUserPreferences() { |
975 } |
1018 } |
976 |
1019 |
977 LinuxJavaUserPreferences::~LinuxJavaUserPreferences(void) { |
1020 LinuxJavaUserPreferences::~LinuxJavaUserPreferences(void) { |
978 } |
1021 } |
979 |
1022 |
980 TString LinuxJavaUserPreferences::GetUserPrefFileName(TString Appid) { |
1023 TString LinuxJavaUserPreferences::GetUserPrefFileName(TString Appid) { |
981 TString result; |
1024 TString result; |
982 struct passwd *pw = getpwuid(getuid()); |
1025 struct passwd *pw = getpwuid(getuid()); |
983 TString homedir = pw->pw_dir; |
1026 TString homedir = pw->pw_dir; |
984 TString userOverrideFileName = FilePath::IncludeTrailingSeparater(homedir) + |
1027 TString userOverrideFileName = FilePath::IncludeTrailingSeparator(homedir) |
985 FilePath::IncludeTrailingSeparater(_T(".java/.userPrefs")) + |
1028 + FilePath::IncludeTrailingSeparator(_T(".java/.userPrefs")) |
986 FilePath::IncludeTrailingSeparater(Appid) + |
1029 + FilePath::IncludeTrailingSeparator(Appid) |
987 _T("JVMUserOptions/prefs.xml"); |
1030 + _T("JVMUserOptions/prefs.xml"); |
988 |
1031 |
989 if (FilePath::FileExists(userOverrideFileName) == true) { |
1032 if (FilePath::FileExists(userOverrideFileName) == true) { |
990 result = userOverrideFileName; |
1033 result = userOverrideFileName; |
991 } |
1034 } |
992 |
1035 |
1053 |
1096 |
1054 return result; |
1097 return result; |
1055 } |
1098 } |
1056 |
1099 |
1057 namespace { |
1100 namespace { |
1058 template<class funcType> |
1101 template<class funcType> |
1059 class DllFunction { |
1102 class DllFunction { |
1060 const Library& lib; |
1103 const Library& lib; |
1061 funcType funcPtr; |
1104 funcType funcPtr; |
1062 std::string theName; |
1105 std::string theName; |
1063 |
1106 |
1064 public: |
1107 public: |
1065 DllFunction(const Library& library, const std::string &funcName): lib(library) { |
1108 DllFunction(const Library& library, |
1066 funcPtr = reinterpret_cast<funcType>(lib.GetProcAddress(funcName)); |
1109 const std::string &funcName): lib(library) { |
1067 if (!funcPtr) { |
1110 funcPtr = reinterpret_cast<funcType>(lib.GetProcAddress(funcName)); |
1068 throw std::runtime_error("Failed to load function \"" + funcName + "\" from \"" + library.GetName() + "\" library"); |
1111 if (!funcPtr) { |
1069 } |
1112 throw std::runtime_error("Failed to load function \"" |
1070 } |
1113 + funcName + "\" from \"" |
1071 |
1114 + library.GetName() + "\" library"); |
1072 operator funcType() const { |
1115 } |
1073 return funcPtr; |
1116 } |
1074 } |
1117 |
1075 }; |
1118 operator funcType() const { |
|
1119 return funcPtr; |
|
1120 } |
|
1121 }; |
1076 } // namespace |
1122 } // namespace |
1077 |
1123 |
1078 extern "C" { |
1124 extern "C" { |
1079 typedef Status (*XInitThreadsFuncPtr)(); |
1125 typedef Status (*XInitThreadsFuncPtr)(); |
1080 typedef Display* (*XOpenDisplayFuncPtr)(char *display_name); |
1126 typedef Display* (*XOpenDisplayFuncPtr)(char *display_name); |
1081 |
1127 |
1082 typedef Atom (*XInternAtomFuncPtr)(Display *display, char *atom_name, Bool only_if_exists); |
1128 typedef Atom (*XInternAtomFuncPtr)( |
|
1129 Display *display, char *atom_name, Bool only_if_exists); |
1083 |
1130 |
1084 typedef Window (*XDefaultRootWindowFuncPtr)(Display *display); |
1131 typedef Window (*XDefaultRootWindowFuncPtr)(Display *display); |
1085 |
1132 |
1086 typedef int (*XCloseDisplayFuncPtr)(Display *display); |
1133 typedef int (*XCloseDisplayFuncPtr)(Display *display); |
1087 } |
1134 } |
1106 |
1153 |
1107 if (_atomPid == None) { |
1154 if (_atomPid == None) { |
1108 return; |
1155 return; |
1109 } |
1156 } |
1110 |
1157 |
1111 DllFunction<XDefaultRootWindowFuncPtr> XDefaultRootWindowFunc(libX11, "XDefaultRootWindow"); |
1158 DllFunction<XDefaultRootWindowFuncPtr> XDefaultRootWindowFunc(libX11, |
|
1159 "XDefaultRootWindow"); |
1112 |
1160 |
1113 searchWindowHelper(XDefaultRootWindowFunc(_display)); |
1161 searchWindowHelper(XDefaultRootWindowFunc(_display)); |
1114 |
1162 |
1115 reactivateProcess(); |
1163 reactivateProcess(); |
1116 |
1164 |
1117 DllFunction<XCloseDisplayFuncPtr> XCloseDisplayFunc(libX11, "XCloseDisplay"); |
1165 DllFunction<XCloseDisplayFuncPtr> XCloseDisplayFunc(libX11, |
|
1166 "XCloseDisplay"); |
1118 |
1167 |
1119 XCloseDisplayFunc(_display); |
1168 XCloseDisplayFunc(_display); |
1120 } |
1169 } |
1121 |
1170 |
1122 extern "C" { |
1171 extern "C" { |
1123 typedef int (*XGetWindowPropertyFuncPtr)(Display *display, Window w, Atom property, |
1172 typedef int (*XGetWindowPropertyFuncPtr)( |
1124 long long_offset, long long_length, Bool d, Atom req_type, Atom *actual_type_return, |
1173 Display *display, Window w, Atom property, long long_offset, |
|
1174 long long_length, Bool d, Atom req_type, Atom *actual_type_return, |
1125 int *actual_format_return, unsigned long *nitems_return, |
1175 int *actual_format_return, unsigned long *nitems_return, |
1126 unsigned long *bytes_after_return, unsigned char **prop_return); |
1176 unsigned long *bytes_after_return, unsigned char **prop_return); |
1127 |
1177 |
1128 typedef Status (*XQueryTreeFuncPtr)(Display *display, Window w, Window *root_return, |
1178 typedef Status (*XQueryTreeFuncPtr)( |
1129 Window *parent_return, Window **children_return, unsigned int *nchildren_return); |
1179 Display *display, Window w, Window *root_return, Window *parent_return, |
|
1180 Window **children_return, unsigned int *nchildren_return); |
1130 |
1181 |
1131 typedef int (*XFreeFuncPtr)(void *data); |
1182 typedef int (*XFreeFuncPtr)(void *data); |
1132 } |
1183 } |
1133 |
1184 |
1134 void ProcessReactivator::searchWindowHelper(Window w) { |
1185 void ProcessReactivator::searchWindowHelper(Window w) { |
1135 |
1186 |
1136 DllFunction<XGetWindowPropertyFuncPtr> XGetWindowPropertyFunc(libX11, "XGetWindowProperty"); |
1187 DllFunction<XGetWindowPropertyFuncPtr> XGetWindowPropertyFunc(libX11, |
|
1188 "XGetWindowProperty"); |
1137 |
1189 |
1138 DllFunction<XFreeFuncPtr> XFreeFunc(libX11, "XFree"); |
1190 DllFunction<XFreeFuncPtr> XFreeFunc(libX11, "XFree"); |
1139 |
1191 |
1140 Atom type; |
1192 Atom type; |
1141 int format; |
1193 int format; |
1142 unsigned long num, bytesAfter; |
1194 unsigned long num, bytesAfter; |
1143 unsigned char* propPid = 0; |
1195 unsigned char* propPid = 0; |
1144 if (Success == XGetWindowPropertyFunc(_display, w, _atomPid, 0, 1, False, XA_CARDINAL, |
1196 if (Success == XGetWindowPropertyFunc(_display, w, _atomPid, 0, 1, |
1145 &type, &format, &num, &bytesAfter, &propPid)) { |
1197 False, XA_CARDINAL, &type, &format, &num, &bytesAfter, &propPid)) { |
1146 if (propPid != 0) { |
1198 if (propPid != 0) { |
1147 if (_pid == *((pid_t *)propPid)) { |
1199 if (_pid == *((pid_t *)propPid)) { |
1148 _result.push_back(w); |
1200 _result.push_back(w); |
1149 } |
1201 } |
1150 XFreeFunc(propPid); |
1202 XFreeFunc(propPid); |
1174 typedef int (*XRaiseWindowFuncPtr)(Display *display, Window w); |
1227 typedef int (*XRaiseWindowFuncPtr)(Display *display, Window w); |
1175 } |
1228 } |
1176 |
1229 |
1177 void ProcessReactivator::reactivateProcess() { |
1230 void ProcessReactivator::reactivateProcess() { |
1178 |
1231 |
1179 DllFunction<XGetWindowAttributesFuncPtr> XGetWindowAttributesFunc(libX11, "XGetWindowAttributes"); |
1232 DllFunction<XGetWindowAttributesFuncPtr> XGetWindowAttributesFunc(libX11, |
|
1233 "XGetWindowAttributes"); |
1180 |
1234 |
1181 DllFunction<XSendEventFuncPtr> XSendEventFunc(libX11, "XSendEvent"); |
1235 DllFunction<XSendEventFuncPtr> XSendEventFunc(libX11, "XSendEvent"); |
1182 |
1236 |
1183 DllFunction<XRaiseWindowFuncPtr> XRaiseWindowFunc(libX11, "XRaiseWindow"); |
1237 DllFunction<XRaiseWindowFuncPtr> XRaiseWindowFunc(libX11, "XRaiseWindow"); |
1184 |
1238 |
1185 DllFunction<XInternAtomFuncPtr> XInternAtomFunc(libX11, "XInternAtom"); |
1239 DllFunction<XInternAtomFuncPtr> XInternAtomFunc(libX11, "XInternAtom"); |
1186 |
1240 |
1187 for (std::list<Window>::const_iterator it = _result.begin(); it != _result.end(); it++) { |
1241 for (std::list<Window>::const_iterator it = _result.begin(); |
|
1242 it != _result.end(); it++) { |
1188 // try sending an event to activate window, |
1243 // try sending an event to activate window, |
1189 // after that we can try to raise it. |
1244 // after that we can try to raise it. |
1190 XEvent xev; |
1245 XEvent xev; |
1191 Atom atom = XInternAtomFunc (_display, (char*)"_NET_ACTIVE_WINDOW", False); |
1246 Atom atom = XInternAtomFunc ( |
|
1247 _display, (char*)"_NET_ACTIVE_WINDOW", False); |
1192 xev.xclient.type = ClientMessage; |
1248 xev.xclient.type = ClientMessage; |
1193 xev.xclient.serial = 0; |
1249 xev.xclient.serial = 0; |
1194 xev.xclient.send_event = True; |
1250 xev.xclient.send_event = True; |
1195 xev.xclient.display = _display; |
1251 xev.xclient.display = _display; |
1196 xev.xclient.window = *it; |
1252 xev.xclient.window = *it; |