summaryrefslogtreecommitdiff
path: root/src/htsjava.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/htsjava.c')
-rw-r--r--src/htsjava.c349
1 files changed, 187 insertions, 162 deletions
diff --git a/src/htsjava.c b/src/htsjava.c
index 2a3d648..16ec55c 100644
--- a/src/htsjava.c
+++ b/src/htsjava.c
@@ -17,24 +17,20 @@ You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
Important notes:
- We hereby ask people using this source NOT to use it in purpose of grabbing
emails addresses, or collecting any other private information on persons.
This would disgrace our work, and spoil the many hours we spent on it.
-
Please visit our Website: http://www.httrack.com
*/
-
/* ------------------------------------------------------------ */
/* File: Java classes parser */
/* Author: Yann Philippot */
/* ------------------------------------------------------------ */
-
/* Version: Oct/2000 */
/* Fixed: problems with class structure (10/2000) */
@@ -69,8 +65,9 @@ Please visit our Website: http://www.httrack.com
#include "htsjava.h"
static int reverse_endian(void) {
- int endian = 1;
- return ( * ( (char*) &endian) == 1);
+ int endian = 1;
+
+ return (*((char *) &endian) == 1);
}
/* big/little endian swap */
@@ -78,10 +75,11 @@ static int reverse_endian(void) {
#define hts_swap32(A) ( (( (hts_swap16(A)) & 0xFFFF)<<16) | (( (hts_swap16(A>>16)) & 0xFFFF)) )
/* Static definitions */
-static RESP_STRUCT readtable(htsmoduleStruct* str,FILE *fp,RESP_STRUCT,int*);
-static unsigned short int readshort(FILE *fp);
-static int tris(httrackp *opt,char*);
-static char * printname(char [1024],char [1024]);
+static RESP_STRUCT readtable(htsmoduleStruct * str, FILE * fp, RESP_STRUCT,
+ int *);
+static unsigned short int readshort(FILE * fp);
+static int tris(httrackp * opt, char *);
+static char *printname(char[1024], char[1024]);
// ** HTS_xx sinon pas pris par VC++
#define HTS_CLASS 7
@@ -106,38 +104,41 @@ static const char *libName = "htsjava";
#define strncasecmp(a,b,n) strnicmp(a,b,n)
#endif
-static int detect_mime(htsmoduleStruct* str) {
- const char* savename = str->filename;
+static int detect_mime(htsmoduleStruct * str) {
+ const char *savename = str->filename;
+
if (savename) {
int len = (int) strlen(savename);
- if (len > 6 && strcasecmp(savename + len - 6,".class") == 0) {
+
+ if (len > 6 && strcasecmp(savename + len - 6, ".class") == 0) {
return 1;
}
}
return 0;
}
-static int hts_detect_java(t_hts_callbackarg *carg, httrackp *opt,
- htsmoduleStruct* str)
-{
+static int hts_detect_java(t_hts_callbackarg * carg, httrackp * opt,
+ htsmoduleStruct * str) {
/* Call parent functions if multiple callbacks are chained. */
if (CALLBACKARG_PREV_FUN(carg, detect) != NULL) {
- if (CALLBACKARG_PREV_FUN(carg, detect)(CALLBACKARG_PREV_CARG(carg), opt, str)) {
- return 1; /* Found before us, let them have the priority */
+ if (CALLBACKARG_PREV_FUN(carg, detect)
+ (CALLBACKARG_PREV_CARG(carg), opt, str)) {
+ return 1; /* Found before us, let them have the priority */
}
}
/* Check MIME */
if (detect_mime(str)) {
- str->wrapper_name = libName; /* Our ID */
- return 1; /* Known format, we take it */
+ str->wrapper_name = libName; /* Our ID */
+ return 1; /* Known format, we take it */
}
- return 0; /* Unknown format */
+ return 0; /* Unknown format */
}
-static off_t fsize(const char* s) {
+static off_t fsize(const char *s) {
STRUCT_STAT st;
+
if (STAT(s, &st) == 0 && S_ISREG(st.st_mode)) {
return st.st_size;
} else {
@@ -145,17 +146,18 @@ static off_t fsize(const char* s) {
}
}
-static int hts_parse_java(t_hts_callbackarg *carg, httrackp *opt,
- htsmoduleStruct* str)
-{
+static int hts_parse_java(t_hts_callbackarg * carg, httrackp * opt,
+ htsmoduleStruct * str) {
/* The wrapper_name memebr has changed: not for us anymore */
if (str->wrapper_name == NULL || strcmp(str->wrapper_name, libName) != 0) {
/* Call parent functions if multiple callbacks are chained. */
if (CALLBACKARG_PREV_FUN(carg, parse) != NULL) {
- return CALLBACKARG_PREV_FUN(carg, parse)(CALLBACKARG_PREV_CARG(carg), opt, str);
+ return CALLBACKARG_PREV_FUN(carg, parse) (CALLBACKARG_PREV_CARG(carg),
+ opt, str);
}
- strcpy(str->err_msg, "unexpected error: bad wrapper_name and no previous wrapper");
- return 0; /* Unexpected error */
+ strcpy(str->err_msg,
+ "unexpected error: bad wrapper_name and no previous wrapper");
+ return 0; /* Unexpected error */
} else {
if (detect_mime(str)) {
@@ -164,74 +166,82 @@ static int hts_parse_java(t_hts_callbackarg *carg, httrackp *opt,
FILE *fpout;
JAVA_HEADER header;
RESP_STRUCT *tab;
- const char* file = str->filename;
+ const char *file = str->filename;
str->relativeToHtmlLink = 1;
#if JAVADEBUG
printf("fopen\n");
#endif
- if ((fpout = FOPEN(fconv(catbuff, file), "r+b")) == NULL)
- {
+ if ((fpout = FOPEN(fconv(catbuff, file), "r+b")) == NULL) {
//fprintf(stderr, "Cannot open input file.\n");
- sprintf(str->err_msg,"Unable to open file %s",file);
- return 0; // une erreur..
+ sprintf(str->err_msg, "Unable to open file %s", file);
+ return 0; // une erreur..
}
-
#if JAVADEBUG
printf("fread\n");
#endif
//if (fread(&header,1,sizeof(JAVA_HEADER),fpout) != sizeof(JAVA_HEADER)) { // pas complet..
- if (fread(&header,1,10,fpout) != 10) { // pas complet..
+ if (fread(&header, 1, 10, fpout) != 10) { // pas complet..
fclose(fpout);
- sprintf(str->err_msg,"File header too small (file len = "LLintP")",(LLint)fsize(file));
+ sprintf(str->err_msg, "File header too small (file len = " LLintP ")",
+ (LLint) fsize(file));
return 0;
}
-
#if JAVADEBUG
printf("header\n");
#endif
// tester en tĂȘte
if (reverse_endian()) {
header.magic = hts_swap32(header.magic);
- header.count = hts_swap16(header.count);
+ header.count = hts_swap16(header.count);
}
- if(header.magic!=0xCAFEBABE) {
- sprintf(str->err_msg,"non java file");
- if (fpout) { fclose(fpout); fpout=NULL; }
+ if (header.magic != 0xCAFEBABE) {
+ sprintf(str->err_msg, "non java file");
+ if (fpout) {
+ fclose(fpout);
+ fpout = NULL;
+ }
return 0;
}
- tab =(RESP_STRUCT*)calloc(header.count,sizeof(RESP_STRUCT));
+ tab = (RESP_STRUCT *) calloc(header.count, sizeof(RESP_STRUCT));
if (!tab) {
- sprintf(str->err_msg,"Unable to alloc %d bytes",(int)sizeof(RESP_STRUCT));
- if (fpout) { fclose(fpout); fpout=NULL; }
- return 0; // erreur..
+ sprintf(str->err_msg, "Unable to alloc %d bytes",
+ (int) sizeof(RESP_STRUCT));
+ if (fpout) {
+ fclose(fpout);
+ fpout = NULL;
+ }
+ return 0; // erreur..
}
-
#if JAVADEBUG
printf("calchead\n");
#endif
{
int i;
- for (i = 1; i < header.count; i++) {
- int err=0; // ++
- tab[i]=readtable(str,fpout,tab[i],&err);
+ for(i = 1; i < header.count; i++) {
+ int err = 0; // ++
+
+ tab[i] = readtable(str, fpout, tab[i], &err);
if (!err) {
- if ((tab[i].type == HTS_LONG) ||(tab[i].type == HTS_DOUBLE)) i++; //2 element si double ou float
- } else { // ++ une erreur est survenue!
- if (strnotempty(str->err_msg)==0)
- strcpy(str->err_msg,"Internal readtable error");
+ if ((tab[i].type == HTS_LONG) || (tab[i].type == HTS_DOUBLE))
+ i++; //2 element si double ou float
+ } else { // ++ une erreur est survenue!
+ if (strnotempty(str->err_msg) == 0)
+ strcpy(str->err_msg, "Internal readtable error");
free(tab);
- if (fpout) { fclose(fpout); fpout=NULL; }
+ if (fpout) {
+ fclose(fpout);
+ fpout = NULL;
+ }
return 0;
}
}
}
-
#if JAVADEBUG
printf("addfiles\n");
#endif
@@ -240,251 +250,266 @@ static int hts_parse_java(t_hts_callbackarg *carg, httrackp *opt,
unsigned int Class;
unsigned int SClass;
int i;
+
//acess = readshort(fpout);
Class = readshort(fpout);
SClass = readshort(fpout);
- for (i = 1; i <header.count; i++) {
+ for(i = 1; i < header.count; i++) {
if (tab[i].type == HTS_CLASS) {
- if ((tab[i].index1<header.count) && (tab[i].index1>=0)) {
-
+ if ((tab[i].index1 < header.count) && (tab[i].index1 >= 0)) {
- if((tab[i].index1!=SClass) && (tab[i].index1!=Class) && (tab[tab[i].index1].name[0]!='[')) {
+ if ((tab[i].index1 != SClass) && (tab[i].index1 != Class)
+ && (tab[tab[i].index1].name[0] != '[')) {
- if(!strstr(tab[tab[i].index1].name,"java/")) {
+ if (!strstr(tab[tab[i].index1].name, "java/")) {
char BIGSTK tempo[1024];
- tempo[0]='\0';
- sprintf(tempo,"%s.class",tab[tab[i].index1].name);
+ tempo[0] = '\0';
+
+ sprintf(tempo, "%s.class", tab[tab[i].index1].name);
#if JAVADEBUG
- printf("add %s\n",tempo);
+ printf("add %s\n", tempo);
#endif
if (tab[tab[i].index1].file_position >= 0)
- str->addLink(str,tempo); /* tab[tab[i].index1].file_position */
+ str->addLink(str, tempo); /* tab[tab[i].index1].file_position */
}
}
- } else {
- i=header.count; // exit
+ } else {
+ i = header.count; // exit
}
}
}
}
-
#if JAVADEBUG
printf("end\n");
#endif
free(tab);
- if (fpout) { fclose(fpout); fpout=NULL; }
+ if (fpout) {
+ fclose(fpout);
+ fpout = NULL;
+ }
return 1;
} else {
strcpy(str->err_msg, "bad MIME type");
}
}
- return 0; /* Error */
+ return 0; /* Error */
}
/*
module entry point
*/
-EXTERNAL_FUNCTION int hts_plug(httrackp *opt, const char* argv);
-EXTERNAL_FUNCTION int hts_plug(httrackp *opt, const char* argv) {
+EXTERNAL_FUNCTION int hts_plug(httrackp * opt, const char *argv);
+EXTERNAL_FUNCTION int hts_plug(httrackp * opt, const char *argv) {
/* Plug callback functions */
CHAIN_FUNCTION(opt, detect, hts_detect_java, NULL);
CHAIN_FUNCTION(opt, parse, hts_parse_java, NULL);
- return 1; /* success */
+ return 1; /* success */
}
// error: !=0 si erreur fatale
-static RESP_STRUCT readtable(htsmoduleStruct* str,
- FILE *fp, RESP_STRUCT trans, int* error)
-{
- char rname[1024];
+static RESP_STRUCT readtable(htsmoduleStruct * str, FILE * fp,
+ RESP_STRUCT trans, int *error) {
+ char rname[1024];
unsigned short int length;
int j;
- *error = 0; // pas d'erreur
- trans.file_position=-1;
- trans.type = (int)(unsigned char)fgetc(fp);
+
+ *error = 0; // pas d'erreur
+ trans.file_position = -1;
+ trans.type = (int) (unsigned char) fgetc(fp);
switch (trans.type) {
case HTS_CLASS:
- strcpy(trans.name,"Class");
+ strcpy(trans.name, "Class");
trans.index1 = readshort(fp);
break;
-
+
case HTS_FIELDREF:
- strcpy(trans.name,"Field Reference");
+ strcpy(trans.name, "Field Reference");
trans.index1 = readshort(fp);
readshort(fp);
break;
-
+
case HTS_METHODREF:
- strcpy(trans.name,"Method Reference");
+ strcpy(trans.name, "Method Reference");
trans.index1 = readshort(fp);
readshort(fp);
break;
-
+
case HTS_INTERFACE:
- strcpy(trans.name,"Interface Method Reference");
- trans.index1 =readshort(fp);
+ strcpy(trans.name, "Interface Method Reference");
+ trans.index1 = readshort(fp);
readshort(fp);
break;
case HTS_NAMEANDTYPE:
- strcpy(trans.name,"Name and Type");
+ strcpy(trans.name, "Name and Type");
trans.index1 = readshort(fp);
readshort(fp);
break;
-
- case HTS_STRING: // CONSTANT_String
- strcpy(trans.name,"String");
+
+ case HTS_STRING: // CONSTANT_String
+ strcpy(trans.name, "String");
trans.index1 = readshort(fp);
break;
-
+
case HTS_INTEGER:
- strcpy(trans.name,"Integer");
- for(j=0;j<4;j++) fgetc(fp);
+ strcpy(trans.name, "Integer");
+ for(j = 0; j < 4; j++)
+ fgetc(fp);
break;
-
+
case HTS_FLOAT:
- strcpy(trans.name,"Float");
- for(j=0;j<4;j++) fgetc(fp);
+ strcpy(trans.name, "Float");
+ for(j = 0; j < 4; j++)
+ fgetc(fp);
break;
-
+
case HTS_LONG:
- strcpy(trans.name,"Long");
- for(j=0;j<8;j++) fgetc(fp);
+ strcpy(trans.name, "Long");
+ for(j = 0; j < 8; j++)
+ fgetc(fp);
break;
case HTS_DOUBLE:
- strcpy(trans.name,"Double");
- for(j=0;j<8;j++) fgetc(fp);
+ strcpy(trans.name, "Double");
+ for(j = 0; j < 8; j++)
+ fgetc(fp);
break;
-
+
case HTS_ASCIZ:
case HTS_UNICODE:
-
+
if (trans.type == HTS_ASCIZ)
- strcpy(trans.name,"HTS_ASCIZ");
+ strcpy(trans.name, "HTS_ASCIZ");
else
- strcpy(trans.name,"HTS_UNICODE");
-
+ strcpy(trans.name, "HTS_UNICODE");
+
{
- char BIGSTK buffer[1024];
+ char BIGSTK buffer[1024];
char *p;
-
- p=&buffer[0];
+
+ p = &buffer[0];
//fflush(fp);
- trans.file_position=ftell(fp);
+ trans.file_position = ftell(fp);
length = readshort(fp);
- if (length<HTS_URLMAXSIZE) {
+ if (length < HTS_URLMAXSIZE) {
// while ((length > 0) && (length<500)) {
- while (length > 0) {
- *p++ =fgetc(fp);
-
+ while(length > 0) {
+ *p++ = fgetc(fp);
+
length--;
}
- *p='\0';
-
+ *p = '\0';
+
//#if JDEBUG
// if(tris(buffer)==1) printf("%s\n ",buffer);
// if(tris(buffer)==2) printf("%s\n ",printname(buffer));
//#endif
- if(tris(str->opt,buffer)==1) str->addLink(str, buffer); /* trans.file_position */
- else if(tris(str->opt,buffer)==2) str->addLink(str, printname(rname,buffer));
-
- strcpy(trans.name,buffer);
- } else { // gros pb
- while ( (length > 0) && (!feof(fp))) {
+ if (tris(str->opt, buffer) == 1)
+ str->addLink(str, buffer); /* trans.file_position */
+ else if (tris(str->opt, buffer) == 2)
+ str->addLink(str, printname(rname, buffer));
+
+ strcpy(trans.name, buffer);
+ } else { // gros pb
+ while((length > 0) && (!feof(fp))) {
fgetc(fp);
length--;
}
if (!feof(fp)) {
- trans.type=-1;
+ trans.type = -1;
} else {
- sprintf(str->err_msg,"Internal stucture error (ASCII)");
+ sprintf(str->err_msg, "Internal stucture error (ASCII)");
*error = 1;
}
- return(trans);
+ return (trans);
}
}
break;
default:
// printf("Type inconnue\n");
// on arrĂȘte tout
- sprintf(str->err_msg,"Internal structure unknown (type %d)",trans.type);
+ sprintf(str->err_msg, "Internal structure unknown (type %d)", trans.type);
*error = 1;
- return(trans);
+ return (trans);
break;
- }
- return(trans);
+ }
+ return (trans);
}
-
-static unsigned short int readshort(FILE *fp)
-{
+static unsigned short int readshort(FILE * fp) {
unsigned short int valint;
- fread(&valint,sizeof(valint),1,fp);
+
+ fread(&valint, sizeof(valint), 1, fp);
if (reverse_endian())
return hts_swap16(valint);
else
return valint;
-
+
}
-static int tris(httrackp *opt,char * buffer)
-{
- char catbuff[CATBUFF_SIZE];
+static int tris(httrackp * opt, char *buffer) {
+ char catbuff[CATBUFF_SIZE];
+
//
// Java
- if((buffer[0]=='[') && buffer[1]=='L' && (!strstr(buffer,"java/")) )
+ if ((buffer[0] == '[') && buffer[1] == 'L' && (!strstr(buffer, "java/")))
return 2;
- if (strstr(buffer,".gif") || strstr(buffer,".jpg") || strstr(buffer,".jpeg") || strstr(buffer,".au") )
+ if (strstr(buffer, ".gif") || strstr(buffer, ".jpg")
+ || strstr(buffer, ".jpeg") || strstr(buffer, ".au"))
return 1;
// Ajouts R.X: test type
// Autres fichiers
{
char type[256];
- type[0]='\0';
- get_httptype(opt,type,buffer,0);
- if (strnotempty(type)) // type reconnu!
+
+ type[0] = '\0';
+ get_httptype(opt, type, buffer, 0);
+ if (strnotempty(type)) // type reconnu!
return 1;
// ajout RX 05/2001
- else if (is_dyntype(get_ext(catbuff, buffer))) // asp,cgi...
+ else if (is_dyntype(get_ext(catbuff, buffer))) // asp,cgi...
return 1;
}
return 0;
}
-static char * printname(char rname[1024], char name[1024])
-{
+static char *printname(char rname[1024], char name[1024]) {
char *p;
char *p1;
int j;
- rname[0]='\0';
+
+ rname[0] = '\0';
//
-
- p=&name[0];
-
- if(*p!='[') return "";
- p+=2;
+
+ p = &name[0];
+
+ if (*p != '[')
+ return "";
+ p += 2;
//rname=(char*)calloct(strlen(name)+8,sizeof(char));
- p1=rname;
- for (j = 0; j < (int) strlen(name); j++,p++) {
- if (*p == '/') *p1='.';
- if (*p==';'){*p1='\0';
- strcat(rname,".class");
- return (rname);}
- else *p1=*p;
+ p1 = rname;
+ for(j = 0; j < (int) strlen(name); j++, p++) {
+ if (*p == '/')
+ *p1 = '.';
+ if (*p == ';') {
+ *p1 = '\0';
+ strcat(rname, ".class");
+ return (rname);
+ } else
+ *p1 = *p;
p1++;
}
- p1-=3;
- *p1='\0';
+ p1 -= 3;
+ *p1 = '\0';
return (rname);
-
+
}