Exemple #1
0
// destruction chaine dans s position pos
void cookie_delete(char *s, int pos) {
  char *buff;

  if (strnotempty(s + pos) == 0) {      // rien à faire, effacer
    s[0] = '\0';
  } else {
    buff = (char *) malloct(strlen(s + pos) + 2);
    if (buff) {
      strcpybuff(buff, s + pos);        // copie temporaire
      strcpybuff(s, buff);      // copier
      freet(buff);
    }
  }
}
Exemple #2
0
// insertion chaine ins avant s
void cookie_insert(char *s, char *ins) {
  char *buff;

  if (strnotempty(s) == 0) {    // rien à faire, juste concat
    strcatbuff(s, ins);
  } else {
    buff = (char *) malloct(strlen(s) + 2);
    if (buff) {
      strcpybuff(buff, s);      // copie temporaire
      strcpybuff(s, ins);       // insérer
      strcatbuff(s, buff);      // copier
      freet(buff);
    }
  }
}
Exemple #3
0
void* openFunctionLib(const char* file_) {
  void* handle;
  char *file = malloct(strlen(file_) + 32);
  strcpy(file, file_);
#ifdef _WIN32
  handle = LoadLibraryA(file);
  if (handle == NULL) {
    sprintf(file, "%s.dll", file_);
    handle = LoadLibraryA(file);
  }
#else
  handle = dlopen(file, RTLD_LAZY);
  if (handle == NULL) {
    sprintf(file, "lib%s.so", file_);
    handle = dlopen(file, RTLD_LAZY);
  }
#endif
  freet(file);
  return handle;
}
Exemple #4
0
void help_wizard(httrackp * opt) {
  help_wizard_buffers *buffers = malloct(sizeof(help_wizard_buffers));

#undef urls
#undef mainpath
#undef projname
#undef stropt
#undef stropt2
#undef strwild
#undef cmd
#undef str
#undef argv

#define urls (buffers->urls)
#define mainpath (buffers->mainpath)
#define projname (buffers->projname)
#define stropt (buffers->stropt)
#define stropt2 (buffers->stropt2)
#define strwild (buffers->strwild)
#define cmd (buffers->cmd)
#define str (buffers->str)
#define argv (buffers->argv)

  //char *urls = (char *) malloct(HTS_URLMAXSIZE * 2);
  //char *mainpath = (char *) malloct(256);
  //char *projname = (char *) malloct(256);
  //char *stropt = (char *) malloct(2048);        // options
  //char *stropt2 = (char *) malloct(2048);       // options longues
  //char *strwild = (char *) malloct(2048);       // wildcards
  //char *cmd = (char *) malloct(4096);
  //char *str = (char *) malloct(256);
  //char **argv = (char **) malloct(256 * sizeof(char *));

  //
  char *a;

  //
  if (urls == NULL || mainpath == NULL || projname == NULL || stropt == NULL
      || stropt2 == NULL || strwild == NULL || cmd == NULL || str == NULL
      || argv == NULL) {
    fprintf(stderr, "* memory exhausted in %s, line %d\n", __FILE__, __LINE__);
    return;
  }
  urls[0] = mainpath[0] = projname[0] = stropt[0] = stropt2[0] = strwild[0] =
    cmd[0] = str[0] = '\0';
  //
  strcpybuff(stropt, "-");
  mainpath[0] = projname[0] = stropt2[0] = strwild[0] = '\0';
  //

  printf("\n");
  printf("Welcome to HTTrack Website Copier (Offline Browser) " HTTRACK_VERSION
         "%s\n", hts_get_version_info(opt));
  printf("Copyright (C) 1998-2016 Xavier Roche and other contributors\n");
#ifdef _WIN32
  printf("Note: You are running the commandline version,\n");
  printf("run 'WinHTTrack.exe' to get the GUI version.\n");
#endif
#ifdef HTTRACK_AFF_WARNING
  printf("NOTE: " HTTRACK_AFF_WARNING "\n");
#endif
#ifdef HTS_PLATFORM_NAME
#if USE_BEGINTHREAD
  printf("[compiled: " HTS_PLATFORM_NAME " - MT]\n");
#else
  printf("[compiled: " HTS_PLATFORM_NAME "]\n");
#endif
#endif
  printf("To see the option list, enter a blank line or try httrack --help\n");
  //
  // Project name
  while(strnotempty(projname) == 0) {
    printf("\n");
    printf("Enter project name :");
    fflush(stdout);
    linput(stdin, projname, 250);
    if (strnotempty(projname) == 0)
      help("httrack", 1);
  }
  //
  // Path
  if (strnotempty(hts_gethome()))
    printf("\nBase path (return=%s/websites/) :", hts_gethome());
  else
    printf("\nBase path (return=current directory) :");
  linput(stdin, str, 250);
  if (!strnotempty(str)) {
    strcatbuff(str, hts_gethome());
    strcatbuff(str, "/websites/");
  }
  if (strnotempty(str))
    if ((str[strlen(str) - 1] != '/') && (str[strlen(str) - 1] != '\\'))
      strcatbuff(str, "/");
  strcatbuff(stropt2, "-O \"");
  strcatbuff(stropt2, str);
  strcatbuff(stropt2, projname);
  strcatbuff(stropt2, "\" ");
  // Créer si ce n'est fait un index.html 1er niveau
  make_empty_index(str);
  //
  printf("\n");
  printf("Enter URLs (separated by commas or blank spaces) :");
  fflush(stdout);
  linput(stdin, urls, 250);
  if (strnotempty(urls)) {
    while((a = strchr(urls, ',')))
      *a = ' ';
    while((a = strchr(urls, '\t')))
      *a = ' ';

    // Action
    printf("\nAction:\n");
    switch (help_query
            ("Mirror Web Site(s)|Mirror Web Site(s) with Wizard|Just Get Files Indicated|Mirror ALL links in URLs (Multiple Mirror)|Test Links In URLs (Bookmark Test)|Update/Continue a Mirror",
             1)) {
    case 1:
      break;
    case 2:
      strcatbuff(stropt, "W");
      break;
    case 3:
      strcatbuff(stropt2, "--get ");
      break;
    case 4:
      strcatbuff(stropt2, "--mirrorlinks ");
      break;
    case 5:
      strcatbuff(stropt2, "--testlinks ");
      break;
    case 6:
      strcatbuff(stropt2, "--update ");
      break;
    case 0:
      return;
      break;
    }

    // Proxy
    printf("\nProxy (return=none) :");
    linput(stdin, str, 250);
    if (strnotempty(str)) {
      while((a = strchr(str, ' ')))
        *a = ':';               // port
      if (!strchr(jump_identification_const(str), ':')) {
        char str2[256];

        printf("\nProxy port (return=8080) :");
        linput(stdin, str2, 250);
        strcatbuff(str, ":");
        if (strnotempty(str2) == 0)
          strcatbuff(str, "8080");
        else
          strcatbuff(str, str2);
      }
      strcatbuff(stropt2, "-P ");
      strcatbuff(stropt2, str);
      strcatbuff(stropt2, " ");
    }
    // Display
    strcatbuff(stropt2, " -%v ");

    // Wildcards
    printf
      ("\nYou can define wildcards, like: -*.gif +www.*.com/*.zip -*img_*.zip\n");
    printf("Wildcards (return=none) :");
    linput(stdin, strwild, 250);

    // Options
    do {
      printf
        ("\nYou can define additional options, such as recurse level (-r<number>), separated by blank spaces\n");
      printf("To see the option list, type help\n");
      printf("Additional options (return=none) :");
      linput(stdin, str, 250);
      if (strfield2(str, "help")) {
        help("httrack", 2);
      } else if (strnotempty(str)) {
        strcatbuff(stropt2, str);
        strcatbuff(stropt2, " ");
      }
    } while(strfield2(str, "help"));

    {
      int argc = 1;
      int g = 0;
      int i = 0;

      //
      printf("\n");
      if (strlen(stropt) == 1)
        stropt[0] = '\0';       // aucune
      sprintf(cmd, "%s %s %s %s", urls, stropt, stropt2, strwild);
      printf("---> Wizard command line: httrack %s\n\n", cmd);
      printf("Ready to launch the mirror? (Y/n) :");
      fflush(stdout);
      linput(stdin, str, 250);
      if (strnotempty(str)) {
        if (!((str[0] == 'y') || (str[0] == 'Y')))
          return;
      }
      printf("\n");

      // couper en morceaux
      argv[0] = strdup("winhttrack");
      argv[1] = cmd;
      argc++;
      while(cmd[i]) {
        if (cmd[i] == '\"')
          g = !g;
        if (cmd[i] == ' ') {
          if (!g) {
            cmd[i] = '\0';
            argv[argc++] = cmd + i + 1;
          }
        }
        i++;
      }
      hts_main(argc, argv);
    }
    //} else {
    //  help("httrack",1);
  }

  /* Free buffers */
  free(buffers);
#undef urls
#undef mainpath
#undef projname
#undef stropt
#undef stropt2
#undef strwild
#undef cmd
#undef str
#undef argv
}
Exemple #5
0
/*
  Sort index!
*/
void index_finish(const char* indexpath,int mode) {
#if HTS_MAKE_KEYWORD_INDEX
	char catbuff[CATBUFF_SIZE];
  char** tab;
  char* blk;
  off_t size = fpsize(fp_tmpproject);
  if (size>0) {
    //FILE* fp=fopen(concat(indexpath,"index.txt"),"rb");
    if (fp_tmpproject) {
      tab=(char**)malloct(sizeof(char*) * (hts_primindex_size+2) );
      if (tab) {
        blk = malloct(size+4);
        if (blk) {
          fseek(fp_tmpproject,0,SEEK_SET);
          if ((INTsys)fread(blk,1,size,fp_tmpproject) == size) {
            char *a=blk,*b;
            int index=0;
            int i;
            FILE* fp;

            while( (b=strchr(a,'\n')) && (index < hts_primindex_size) ) {
              tab[index++]=a;
              *b='\0';
              a=b+1;
            }
            
            // Sort it!
            qsort(tab,index,sizeof(char*),mystrcmp);

            // Delete fp_tmpproject
            fclose(fp_tmpproject);
            fp_tmpproject=NULL;

            // Write new file
            if (mode == 1)      // TEXT
              fp=fopen(concat(catbuff,indexpath,"index.txt"),"wb");
            else                // HTML
              fp=fopen(concat(catbuff,indexpath,"sindex.html"),"wb");
            if (fp) {
              char current_word[KEYW_LEN + 32];
              char word[KEYW_LEN + 32];
              int hit;
              int total_hit=0;
              int total_line=0;
              int last_pos=0;
              char word0='\0';
              current_word[0]='\0';

              if (mode == 2) {         // HTML
                for(i=0;i<index;i++) {
                  if (word0 != tab[i][0]) {
                    word0 = tab[i][0];
                    fprintf(fp," <a href=\"#%c\">%c</a>\r\n",word0,word0);
                  }
                }
                word0='\0';
                fprintf(fp,"<br><br>\r\n");
                fprintf(fp,"<table width=\"100%%\" border=\"0\">\r\n<tr>\r\n<td>word</td>\r\n<td>location\r\n");
              }

              for(i=0;i<index;i++) {
                if (sscanf(tab[i],"%s %d",word,&hit) == 2) {
                  char*  a=strchr(tab[i],' ');
                  if (a) a=strchr(a+1,' ');
                  if (a++) {                            /* Yes, a++, not ++a :) */
                    hit=KEYW_SORT_MAXCOUNT-hit;
                    if (strcmp(word,current_word)) {    /* New word */
                      if (total_hit) {
                        if (mode == 1)      // TEXT
                          fprintf(fp,"\t=%d\r\n",total_hit);
                        //else                // HTML
                        //  fprintf(fp,"<br>(%d total hits)\r\n",total_hit);
                        if ( 
                              ( ((total_hit*1000 ) / hts_primindex_words) >= KEYW_USELESS1K   )
                            ||
                              ( ((total_line*1000) / index              ) >= KEYW_USELESS1KPG )
                          ) {
                          fseek(fp,last_pos,SEEK_SET);
                          if (mode == 1)      // TEXT
                            fprintf(fp,"\tignored (%d)\r\n",((total_hit*1000)/hts_primindex_words));
                          else
                            fprintf(fp,"(ignored) [%d hits]<br>\r\n",total_hit);
                        }
                        else {
                          if (mode == 1)      // TEXT
                            fprintf(fp,"\t(%d)\r\n",((total_hit*1000)/hts_primindex_words));
                          //else                // HTML
                          //  fprintf(fp,"(%d)\r\n",((total_hit*1000)/hts_primindex_words));
                        }
                      }
                      if (mode == 1)      // TEXT
                        fprintf(fp,"%s\r\n",word);
                      else {              // HTML
                        fprintf(fp,"</td></tr>\r\n");
                        if (word0 != word[0]) {
                          word0 = word[0];
                          fprintf(fp,"<th>%c</th>\r\n",word0);
                          fprintf(fp,"<a name=\"%c\"></a>\r\n",word0);
                        }
                        fprintf(fp,"<tr>\r\n<td>%s</td>\r\n<td>\r\n",word);
                      }
                      fflush(fp); last_pos=ftell(fp);
                      strcpybuff(current_word,word);
                      total_hit=total_line=0;
                    }
                    total_hit+=hit;
                    total_line++;
                    if (mode == 1)      // TEXT
                      fprintf(fp,"\t%d %s\r\n",hit,a);
                    else                // HTML
                      fprintf(fp,"<a href=\"%s\">%s</a> [%d hits]<br>\r\n",a,a,hit);
                  }
                }
              }
              if (mode == 2)         // HTML
                fprintf(fp,"</td></tr>\r\n</table>\r\n");
              fclose(fp);
            }
            
          }
          freet(blk);
        }
        freet(tab);
      }

    }
    //qsort
  }
  if (fp_tmpproject)
    fclose(fp_tmpproject);
  fp_tmpproject=NULL;
#endif
}
Exemple #6
0
static void back_launch_cmd( void* pP ) {
  char* cmd = (char*) pP;
  char** argv = (char**) malloct(1024 * sizeof(char*));
  int argc = 0;
  int i = 0;
  int g = 0;
	//
  httrackp *opt;

  /* copy commandline */
  if (commandReturnCmdl)
    free(commandReturnCmdl);
  commandReturnCmdl = strdup(cmd);

  /* split */
  argv[0]="webhttrack";
  argv[1]=cmd;
  argc++;    
  i = 0;
  while(cmd[i]) {
    if (cmd[i] == '\t' || cmd[i] == '\r' || cmd[i] == '\n') {
      cmd[i] = ' ';
    }
    i++;
  }
  i = 0;
  while(cmd[i])  {
    if(cmd[i]=='\"') g=!g;
    if(cmd[i]==' ') {
      if(!g){
        cmd[i]='\0';
        argv[argc++]=cmd+i+1;
      }
    }  
    i++;
  }

	/* init */
	hts_init();
  global_opt = opt = hts_create_opt();

  /* run */
  commandReturn = webhttrack_runmain(opt, argc, argv);
  if (commandReturn) {
    if (commandReturnMsg)
      free(commandReturnMsg);
    commandReturnMsg = strdup(hts_errmsg(opt));
  }

	/* free */
	global_opt = NULL;
	hts_free_opt(opt);
  hts_uninit();

  /* okay */
  commandRunning = 0;

  /* finished */
  commandEnd = 1;

  /* free */
  free(cmd);
  freet(argv);
  return ;
}