Exemple #1
0
static unsigned short int readshort(FILE *fp)
{
  unsigned short int valint;
  fread(&valint,sizeof(valint),1,fp);

  if (reverse_endian())
    return hts_swap16(valint);
  else
    return valint;
  
}
Exemple #2
0
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);
    }
    strcpy(str->err_msg,
           "unexpected error: bad wrapper_name and no previous wrapper");
    return 0;                   /* Unexpected error */
  } else {
    if (detect_mime(str)) {

      /* (Legacy code) */
      char catbuff[CATBUFF_SIZE];
      FILE *fpout;
      JAVA_HEADER header;
      RESP_STRUCT *tab;
      const char *file = str->filename;

      str->relativeToHtmlLink = 1;

#if JAVADEBUG
      printf("fopen\n");
#endif
      if ((fpout = FOPEN(fconv(catbuff, sizeof(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..
      }
#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..
        fclose(fpout);
        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);
      }
      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));
      if (!tab) {
        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);
          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");
            free(tab);
            if (fpout) {
              fclose(fpout);
              fpout = NULL;
            }
            return 0;
          }
        }

      }

#if JAVADEBUG
      printf("addfiles\n");
#endif
      {
        //unsigned int acess;
        unsigned int Class;
        unsigned int SClass;
        int i;

        //acess = readshort(fpout);
        Class = readshort(fpout);
        SClass = readshort(fpout);

        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 != SClass) && (tab[i].index1 != Class)
                  && (tab[tab[i].index1].name[0] != '[')) {

                if (!strstr(tab[tab[i].index1].name, "java/")) {
                  char BIGSTK tempo[1024];

                  tempo[0] = '\0';

                  sprintf(tempo, "%s.class", tab[tab[i].index1].name);
#if JAVADEBUG
                  printf("add %s\n", tempo);
#endif
                  if (tab[tab[i].index1].file_position >= 0)
                    str->addLink(str, tempo);   /* tab[tab[i].index1].file_position */
                }

              }
            } else {
              i = header.count; // exit 
            }
          }

        }
      }

#if JAVADEBUG
      printf("end\n");
#endif
      free(tab);
      if (fpout) {
        fclose(fpout);
        fpout = NULL;
      }
      return 1;

    } else {
      strcpy(str->err_msg, "bad MIME type");
    }
  }
  return 0;                     /* Error */
}