106
104
#define strncasecmp(a,b,n) strnicmp(a,b,n)
109
static int detect_mime(htsmoduleStruct* str) {
110
const char* savename = str->filename;
107
static int detect_mime(htsmoduleStruct * str) {
108
const char *savename = str->filename;
112
111
int len = (int) strlen(savename);
113
if (len > 6 && strcasecmp(savename + len - 6,".class") == 0) {
113
if (len > 6 && strcasecmp(savename + len - 6, ".class") == 0) {
120
static int hts_detect_java(t_hts_callbackarg *carg, httrackp *opt,
121
htsmoduleStruct* str)
120
static int hts_detect_java(t_hts_callbackarg * carg, httrackp * opt,
121
htsmoduleStruct * str) {
123
122
/* Call parent functions if multiple callbacks are chained. */
124
123
if (CALLBACKARG_PREV_FUN(carg, detect) != NULL) {
125
if (CALLBACKARG_PREV_FUN(carg, detect)(CALLBACKARG_PREV_CARG(carg), opt, str)) {
126
return 1; /* Found before us, let them have the priority */
124
if (CALLBACKARG_PREV_FUN(carg, detect)
125
(CALLBACKARG_PREV_CARG(carg), opt, str)) {
126
return 1; /* Found before us, let them have the priority */
131
131
if (detect_mime(str)) {
132
str->wrapper_name = libName; /* Our ID */
133
return 1; /* Known format, we take it */
132
str->wrapper_name = libName; /* Our ID */
133
return 1; /* Known format, we take it */
136
return 0; /* Unknown format */
136
return 0; /* Unknown format */
139
static off_t fsize(const char* s) {
139
static off_t fsize(const char *s) {
141
142
if (STAT(s, &st) == 0 && S_ISREG(st.st_mode)) {
142
143
return st.st_size;
165
167
JAVA_HEADER header;
166
168
RESP_STRUCT *tab;
167
const char* file = str->filename;
169
const char *file = str->filename;
169
171
str->relativeToHtmlLink = 1;
172
174
printf("fopen\n");
174
if ((fpout = FOPEN(fconv(catbuff, file), "r+b")) == NULL)
176
if ((fpout = FOPEN(fconv(catbuff, file), "r+b")) == NULL) {
176
177
//fprintf(stderr, "Cannot open input file.\n");
177
sprintf(str->err_msg,"Unable to open file %s",file);
178
return 0; // une erreur..
178
sprintf(str->err_msg, "Unable to open file %s", file);
179
return 0; // une erreur..
182
182
printf("fread\n");
184
184
//if (fread(&header,1,sizeof(JAVA_HEADER),fpout) != sizeof(JAVA_HEADER)) { // pas complet..
185
if (fread(&header,1,10,fpout) != 10) { // pas complet..
185
if (fread(&header, 1, 10, fpout) != 10) { // pas complet..
187
sprintf(str->err_msg,"File header too small (file len = "LLintP")",(LLint)fsize(file));
187
sprintf(str->err_msg, "File header too small (file len = " LLintP ")",
188
(LLint) fsize(file));
192
192
printf("header\n");
195
195
if (reverse_endian()) {
196
196
header.magic = hts_swap32(header.magic);
197
header.count = hts_swap16(header.count);
197
header.count = hts_swap16(header.count);
199
if(header.magic!=0xCAFEBABE) {
200
sprintf(str->err_msg,"non java file");
201
if (fpout) { fclose(fpout); fpout=NULL; }
199
if (header.magic != 0xCAFEBABE) {
200
sprintf(str->err_msg, "non java file");
205
tab =(RESP_STRUCT*)calloc(header.count,sizeof(RESP_STRUCT));
208
tab = (RESP_STRUCT *) calloc(header.count, sizeof(RESP_STRUCT));
207
sprintf(str->err_msg,"Unable to alloc %d bytes",(int)sizeof(RESP_STRUCT));
208
if (fpout) { fclose(fpout); fpout=NULL; }
209
return 0; // erreur..
210
sprintf(str->err_msg, "Unable to alloc %d bytes",
211
(int) sizeof(RESP_STRUCT));
216
return 0; // erreur..
213
219
printf("calchead\n");
218
for (i = 1; i < header.count; i++) {
220
tab[i]=readtable(str,fpout,tab[i],&err);
224
for(i = 1; i < header.count; i++) {
227
tab[i] = readtable(str, fpout, tab[i], &err);
222
if ((tab[i].type == HTS_LONG) ||(tab[i].type == HTS_DOUBLE)) i++; //2 element si double ou float
223
} else { // ++ une erreur est survenue!
224
if (strnotempty(str->err_msg)==0)
225
strcpy(str->err_msg,"Internal readtable error");
229
if ((tab[i].type == HTS_LONG) || (tab[i].type == HTS_DOUBLE))
230
i++; //2 element si double ou float
231
} else { // ++ une erreur est survenue!
232
if (strnotempty(str->err_msg) == 0)
233
strcpy(str->err_msg, "Internal readtable error");
227
if (fpout) { fclose(fpout); fpout=NULL; }
236
246
printf("addfiles\n");
240
250
unsigned int Class;
241
251
unsigned int SClass;
243
254
//acess = readshort(fpout);
244
255
Class = readshort(fpout);
245
256
SClass = readshort(fpout);
247
for (i = 1; i <header.count; i++) {
258
for(i = 1; i < header.count; i++) {
249
260
if (tab[i].type == HTS_CLASS) {
251
if ((tab[i].index1<header.count) && (tab[i].index1>=0)) {
254
if((tab[i].index1!=SClass) && (tab[i].index1!=Class) && (tab[tab[i].index1].name[0]!='[')) {
256
if(!strstr(tab[tab[i].index1].name,"java/")) {
262
if ((tab[i].index1 < header.count) && (tab[i].index1 >= 0)) {
264
if ((tab[i].index1 != SClass) && (tab[i].index1 != Class)
265
&& (tab[tab[i].index1].name[0] != '[')) {
267
if (!strstr(tab[tab[i].index1].name, "java/")) {
257
268
char BIGSTK tempo[1024];
260
sprintf(tempo,"%s.class",tab[tab[i].index1].name);
272
sprintf(tempo, "%s.class", tab[tab[i].index1].name);
262
printf("add %s\n",tempo);
274
printf("add %s\n", tempo);
264
276
if (tab[tab[i].index1].file_position >= 0)
265
str->addLink(str,tempo); /* tab[tab[i].index1].file_position */
277
str->addLink(str, tempo); /* tab[tab[i].index1].file_position */
270
i=header.count; // exit
282
i = header.count; // exit
282
if (fpout) { fclose(fpout); fpout=NULL; }
286
300
strcpy(str->err_msg, "bad MIME type");
289
return 0; /* Error */
303
return 0; /* Error */
293
307
module entry point
295
EXTERNAL_FUNCTION int hts_plug(httrackp *opt, const char* argv);
296
EXTERNAL_FUNCTION int hts_plug(httrackp *opt, const char* argv) {
309
EXTERNAL_FUNCTION int hts_plug(httrackp * opt, const char *argv);
310
EXTERNAL_FUNCTION int hts_plug(httrackp * opt, const char *argv) {
297
311
/* Plug callback functions */
298
312
CHAIN_FUNCTION(opt, detect, hts_detect_java, NULL);
299
313
CHAIN_FUNCTION(opt, parse, hts_parse_java, NULL);
301
return 1; /* success */
315
return 1; /* success */
304
318
// error: !=0 si erreur fatale
305
static RESP_STRUCT readtable(htsmoduleStruct* str,
306
FILE *fp, RESP_STRUCT trans, int* error)
319
static RESP_STRUCT readtable(htsmoduleStruct * str, FILE * fp,
320
RESP_STRUCT trans, int *error) {
309
322
unsigned short int length;
311
*error = 0; // pas d'erreur
312
trans.file_position=-1;
313
trans.type = (int)(unsigned char)fgetc(fp);
325
*error = 0; // pas d'erreur
326
trans.file_position = -1;
327
trans.type = (int) (unsigned char) fgetc(fp);
314
328
switch (trans.type) {
316
strcpy(trans.name,"Class");
330
strcpy(trans.name, "Class");
317
331
trans.index1 = readshort(fp);
320
334
case HTS_FIELDREF:
321
strcpy(trans.name,"Field Reference");
335
strcpy(trans.name, "Field Reference");
322
336
trans.index1 = readshort(fp);
326
340
case HTS_METHODREF:
327
strcpy(trans.name,"Method Reference");
341
strcpy(trans.name, "Method Reference");
328
342
trans.index1 = readshort(fp);
332
346
case HTS_INTERFACE:
333
strcpy(trans.name,"Interface Method Reference");
334
trans.index1 =readshort(fp);
347
strcpy(trans.name, "Interface Method Reference");
348
trans.index1 = readshort(fp);
337
351
case HTS_NAMEANDTYPE:
338
strcpy(trans.name,"Name and Type");
352
strcpy(trans.name, "Name and Type");
339
353
trans.index1 = readshort(fp);
343
case HTS_STRING: // CONSTANT_String
344
strcpy(trans.name,"String");
357
case HTS_STRING: // CONSTANT_String
358
strcpy(trans.name, "String");
345
359
trans.index1 = readshort(fp);
348
362
case HTS_INTEGER:
349
strcpy(trans.name,"Integer");
350
for(j=0;j<4;j++) fgetc(fp);
363
strcpy(trans.name, "Integer");
364
for(j = 0; j < 4; j++)
354
strcpy(trans.name,"Float");
355
for(j=0;j<4;j++) fgetc(fp);
369
strcpy(trans.name, "Float");
370
for(j = 0; j < 4; j++)
359
strcpy(trans.name,"Long");
360
for(j=0;j<8;j++) fgetc(fp);
375
strcpy(trans.name, "Long");
376
for(j = 0; j < 8; j++)
363
strcpy(trans.name,"Double");
364
for(j=0;j<8;j++) fgetc(fp);
380
strcpy(trans.name, "Double");
381
for(j = 0; j < 8; j++)
368
386
case HTS_UNICODE:
370
388
if (trans.type == HTS_ASCIZ)
371
strcpy(trans.name,"HTS_ASCIZ");
389
strcpy(trans.name, "HTS_ASCIZ");
373
strcpy(trans.name,"HTS_UNICODE");
391
strcpy(trans.name, "HTS_UNICODE");
376
char BIGSTK buffer[1024];
394
char BIGSTK buffer[1024];
382
trans.file_position=ftell(fp);
400
trans.file_position = ftell(fp);
383
401
length = readshort(fp);
384
if (length<HTS_URLMAXSIZE) {
402
if (length < HTS_URLMAXSIZE) {
385
403
// while ((length > 0) && (length<500)) {
394
412
// if(tris(buffer)==1) printf("%s\n ",buffer);
395
413
// if(tris(buffer)==2) printf("%s\n ",printname(buffer));
397
if(tris(str->opt,buffer)==1) str->addLink(str, buffer); /* trans.file_position */
398
else if(tris(str->opt,buffer)==2) str->addLink(str, printname(rname,buffer));
415
if (tris(str->opt, buffer) == 1)
416
str->addLink(str, buffer); /* trans.file_position */
417
else if (tris(str->opt, buffer) == 2)
418
str->addLink(str, printname(rname, buffer));
400
strcpy(trans.name,buffer);
402
while ( (length > 0) && (!feof(fp))) {
420
strcpy(trans.name, buffer);
422
while((length > 0) && (!feof(fp))) {
409
sprintf(str->err_msg,"Internal stucture error (ASCII)");
429
sprintf(str->err_msg, "Internal stucture error (ASCII)");
417
437
// printf("Type inconnue\n");
419
sprintf(str->err_msg,"Internal structure unknown (type %d)",trans.type);
439
sprintf(str->err_msg, "Internal structure unknown (type %d)", trans.type);
428
static unsigned short int readshort(FILE *fp)
447
static unsigned short int readshort(FILE * fp) {
430
448
unsigned short int valint;
431
fread(&valint,sizeof(valint),1,fp);
450
fread(&valint, sizeof(valint), 1, fp);
433
452
if (reverse_endian())
434
453
return hts_swap16(valint);
440
static int tris(httrackp *opt,char * buffer)
442
char catbuff[CATBUFF_SIZE];
459
static int tris(httrackp * opt, char *buffer) {
460
char catbuff[CATBUFF_SIZE];
445
if((buffer[0]=='[') && buffer[1]=='L' && (!strstr(buffer,"java/")) )
464
if ((buffer[0] == '[') && buffer[1] == 'L' && (!strstr(buffer, "java/")))
447
if (strstr(buffer,".gif") || strstr(buffer,".jpg") || strstr(buffer,".jpeg") || strstr(buffer,".au") )
466
if (strstr(buffer, ".gif") || strstr(buffer, ".jpg")
467
|| strstr(buffer, ".jpeg") || strstr(buffer, ".au"))
449
469
// Ajouts R.X: test type
450
470
// Autres fichiers
454
get_httptype(opt,type,buffer,0);
455
if (strnotempty(type)) // type reconnu!
475
get_httptype(opt, type, buffer, 0);
476
if (strnotempty(type)) // type reconnu!
457
478
// ajout RX 05/2001
458
else if (is_dyntype(get_ext(catbuff, buffer))) // asp,cgi...
479
else if (is_dyntype(get_ext(catbuff, buffer))) // asp,cgi...
464
static char * printname(char rname[1024], char name[1024])
485
static char *printname(char rname[1024], char name[1024]) {
474
if(*p!='[') return "";
476
498
//rname=(char*)calloct(strlen(name)+8,sizeof(char));
478
for (j = 0; j < (int) strlen(name); j++,p++) {
479
if (*p == '/') *p1='.';
480
if (*p==';'){*p1='\0';
481
strcat(rname,".class");
500
for(j = 0; j < (int) strlen(name); j++, p++) {
505
strcat(rname, ".class");