Esempio n. 1
0
static int webhttrack_runmain(httrackp *opt, int argc, char** argv) {
	int ret;

  CHAIN_FUNCTION(opt, init, htsshow_init, NULL);
  CHAIN_FUNCTION(opt, uninit, htsshow_uninit, NULL);
  CHAIN_FUNCTION(opt, start, htsshow_start, NULL);
  CHAIN_FUNCTION(opt, end, htsshow_end, NULL);
  CHAIN_FUNCTION(opt, chopt, htsshow_chopt, NULL);
  CHAIN_FUNCTION(opt, preprocess, htsshow_preprocesshtml, NULL);
  CHAIN_FUNCTION(opt, postprocess, htsshow_postprocesshtml, NULL);
  CHAIN_FUNCTION(opt, check_html, htsshow_checkhtml, NULL);
  CHAIN_FUNCTION(opt, query, htsshow_query, NULL);
  CHAIN_FUNCTION(opt, query2, htsshow_query2, NULL);
  CHAIN_FUNCTION(opt, query3, htsshow_query3, NULL);
  CHAIN_FUNCTION(opt, loop, htsshow_loop, NULL);
  CHAIN_FUNCTION(opt, check_link, htsshow_check, NULL);
  CHAIN_FUNCTION(opt, check_mime, htsshow_check_mime, NULL);
  CHAIN_FUNCTION(opt, pause, htsshow_pause, NULL);
  CHAIN_FUNCTION(opt, filesave, htsshow_filesave, NULL);
  CHAIN_FUNCTION(opt, filesave2, htsshow_filesave2, NULL);
  CHAIN_FUNCTION(opt, linkdetected, htsshow_linkdetected, NULL);
  CHAIN_FUNCTION(opt, linkdetected2, htsshow_linkdetected2, NULL);
  CHAIN_FUNCTION(opt, xfrstatus, htsshow_xfrstatus, NULL);
  CHAIN_FUNCTION(opt, savename, htsshow_savename, NULL);
  CHAIN_FUNCTION(opt, sendhead, htsshow_sendheader, NULL);
  CHAIN_FUNCTION(opt, receivehead, htsshow_receiveheader, NULL);

	ret = hts_main2(argc, argv, opt);
  htsthread_wait_n(1);
	
	return ret;
}
Esempio n. 2
0
HTSEXT_API void htsthread_wait(void) {
  htsthread_wait_n(0);
}
Esempio n. 3
0
int main(int argc, char *argv[]) {
  int i;
  int ret = 0;
  int defaultPort = 0;
  int parentPid = 0;

  printf("Initialzing the server..\n");

#ifdef _WIN32
  {
    WORD wVersionRequested;     // requested version WinSock API
    WSADATA wsadata;            // Windows Sockets API data
    int stat;

    wVersionRequested = 0x0101;
    stat = WSAStartup(wVersionRequested, &wsadata);
    if (stat != 0) {
      fprintf(stderr, "Winsock not found!\n");
      return -1;
    } else if (LOBYTE(wsadata.wVersion) != 1 && HIBYTE(wsadata.wVersion) != 1) {
      fprintf(stderr, "WINSOCK.DLL does not support version 1.1\n");
      WSACleanup();
      return -1;
    }
  }
#endif

  if (argc < 2 || (argc % 2) != 0) {
    fprintf(stderr, "** Warning: use the webhttrack frontend if available\n");
    fprintf(stderr,
            "usage: %s [--port <port>] [--ppid parent-pid] <path-to-html-root-dir> [key value [key value]..]\n",
            argv[0]);
    fprintf(stderr, "example: %s /usr/share/httrack/\n", argv[0]);
    return 1;
  }

  /* init and launch */
  hts_init();
  htslang_init();

  /* set general keys */
#ifdef HTS_ETCPATH
  smallserver_setkey("ETCPATH", HTS_ETCPATH);
#endif
#ifdef HTS_BINPATH
  smallserver_setkey("BINPATH", HTS_BINPATH);
#endif
#ifdef HTS_LIBPATH
  smallserver_setkey("LIBPATH", HTS_LIBPATH);
#endif
#ifdef HTS_PREFIX
  smallserver_setkey("PREFIX", HTS_PREFIX);
#endif
#ifdef HTS_HTTRACKCNF
  smallserver_setkey("HTTRACKCNF", HTS_HTTRACKCNF);
#endif
#ifdef HTS_HTTRACKDIR
  smallserver_setkey("HTTRACKDIR", HTS_HTTRACKDIR);
#endif
#ifdef HTS_INET6
  smallserver_setkey("INET6", "1");
#endif
#ifdef HTS_USEOPENSSL
  smallserver_setkey("USEOPENSSL", "1");
#endif
#ifdef HTS_DLOPEN
  smallserver_setkey("DLOPEN", "1");
#endif
#ifdef HTS_USESWF
  smallserver_setkey("USESWF", "1");
#endif
#ifdef HTS_USEZLIB
  smallserver_setkey("USEZLIB", "1");
#endif
#ifdef _WIN32
  smallserver_setkey("WIN32", "1");
#endif
  smallserver_setkey("HTTRACK_VERSION", HTTRACK_VERSION);
  smallserver_setkey("HTTRACK_VERSIONID", HTTRACK_VERSIONID);
  smallserver_setkey("HTTRACK_AFF_VERSION", HTTRACK_AFF_VERSION);
  {
    char tmp[32];

    sprintf(tmp, "%d", -1);
    smallserver_setkey("HTS_PLATFORM", tmp);
  }
  smallserver_setkey("HTTRACK_WEB", HTTRACK_WEB);

  /* Check version compatibility */
  if (hts_sizeof_opt() != sizeof(httrackp)) {
    fprintf(stderr,
      "** CRITICAL: incompatible current httrack library version %s, expected version %s",
      hts_version(), HTTRACK_VERSIONID);
    smallserver_setkey("HTTRACK_INCOMPATIBLE_VERSIONID", hts_version());
  }

  /* protected session-id */
  {
    char buff[1024];
    char digest[32 + 2];

    srand((unsigned int) time(NULL));
    sprintf(buff, "%d-%d", (int) time(NULL), (int) rand());
    domd5mem(buff, strlen(buff), digest, 1);
    smallserver_setkey("sid", digest);
    smallserver_setkey("_sid", digest);
  }

  /* set commandline keys */
  for(i = 2; i < argc; i += 2) {
    if (strcmp(argv[i], "--port") == 0 && i + 1 < argc) {
      if (sscanf(argv[i + 1], "%d", &defaultPort) != 1 || defaultPort < 0
          || defaultPort >= 65535) {
        fprintf(stderr, "couldn't set the port number to %s\n", argv[i + 1]);
        return -1;
      }
    } else if (strcmp(argv[i], "--ppid") == 0 && i + 1 < argc) {
      if (sscanf(argv[i + 1], "%u", &parentPid) != 1) {
        fprintf(stderr, "couldn't set the parent PID to %s\n", argv[i + 1]);
        return -1;
      }
    } else if (i + 1 < argc) {
      smallserver_setkey(argv[i], argv[i + 1]);
    } else {
      fprintf(stderr, "Error in commandline!\n");
      return -1;
    }
  }

  /* sigpipe */
#ifndef _WIN32
  signal(SIGPIPE, htsweb_sig_brpipe);   // broken pipe (write into non-opened socket)
#endif

  /* pinger */
  if (parentPid > 0) {
    hts_newthread(client_ping, (void *) (uintptr_t) parentPid);
    background_threads++; /* Do not wait for this thread! */
    smallserver_setpinghandler(pingHandler, NULL);
  }

  /* launch */
  ret = help_server(argv[1], defaultPort);

  htsthread_wait_n(background_threads - 1);
  hts_uninit();

#ifdef _WIN32
  WSACleanup();
#endif

  return ret;
}