void back_launch_ftp(void *pP) { FTPDownloadStruct *pStruct = (FTPDownloadStruct *) pP; if (pStruct == NULL) return; if (pStruct == NULL) { #if FTP_DEBUG printf("[ftp error: no args]\n"); #endif return; } /* Initialize */ hts_init(); // lancer ftp #if FTP_DEBUG printf("[Launching main ftp routine]\n"); #endif run_launch_ftp(pStruct); // prêt pStruct->pBack->status = STATUS_FTP_READY; /* Delete structure */ free(pP); /* Uninitialize */ hts_uninit(); return; }
int main(int argc, char **argv) { int ret = 0; httrackp *opt; signal_handlers(); hts_init(); opt = global_opt = hts_create_opt(); 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); if (ret) { fprintf(stderr, "* %s\n", hts_errmsg(opt)); } global_opt = NULL; hts_free_opt(opt); htsthread_wait(); /* wait for pending threads */ hts_uninit(); return ret; }
static void back_launch_mms( void* pP ) { MMSDownloadStruct *pStruct = (MMSDownloadStruct*)pP; if (pStruct == NULL) return ; /* Initialize */ hts_init(); /* Run */ run_launch_mms(pStruct); /* Set as ready */ { lien_back* back = pStruct->pBack; back->status=FTP_STATUS_READY; } /* Delete structure */ free(pP); /* Uninitialize */ hts_uninit(); return ; }
BOOL CWinHTTrackApp::InitInstance() { /* See <https://msdn.microsoft.com/library/ff919712> */ #if (defined(_WIN32) && (!defined(_DEBUG))) { /* See KB 2389418 "If this parameter is an empty string (""), the call removes the current directory from the default DLL search order" */ BOOL (WINAPI*const k32_SetDllDirectoryA)(LPCSTR) = (BOOL (WINAPI *)(LPCSTR)) GetProcAddress(GetModuleHandle("kernel32.dll"), "SetDllDirectoryA"); if (k32_SetDllDirectoryA != NULL && !k32_SetDllDirectoryA("")) { /* Do no choke on NT or 98SE with KernelEx NT API (James Blough) */ const DWORD dwVersion = GetVersion(); const DWORD dwMajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion))); const DWORD dwMinorVersion = (DWORD)(HIBYTE(LOWORD(dwVersion))); if (dwMajorVersion >= 5) { assertf(!"SetDllDirectory failed"); } } } #endif /* No error messageboxes */ SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOALIGNMENTFAULTEXCEPT | SEM_NOGPFAULTERRORBOX); /* Inits */ CrashReportInit(); hts_set_error_callback(httrackErrorCallback); hts_init(); WhttMutex = CreateMutex(NULL,FALSE,NULL); // Change the registry key under which our settings are stored. // TODO: You should modify this string to be something appropriate // such as the name of your company or organization. SetRegistryKey("WinHTTrack Website Copier"); LANG_INIT(); // petite init langue /* INDISPENSABLE pour le drag&drop! */ InitCommonControls(); if (!AfxOleInit()) { AfxMessageBox(LANG(LANG_F1)); return FALSE; } AfxEnableControlContainer(); // Pointeur sur CShellApp CShellApp_app=&app; this_app=this; _Cinprogress_inst=NULL; LibRasUse=0; // Standard initialization // If you are not using these features and wish to reduce the size // of your final executable, you should remove from the following // the specific initialization routines you do not need. httrack_icon=AfxGetApp()->LoadIcon(IDR_MAINFRAME); LoadStdProfileSettings(); // Load standard INI file options (including MRU) // Register the application's document templates. Document templates // serve as the connection between documents, frame windows and views. // DOC // CMultiDocTemplate* pDocTemplate; pDocTemplate = new CMultiDocTemplate( IDR_MAINFRAME, RUNTIME_CLASS(CWinHTTrackDoc), RUNTIME_CLASS(CSplitterFrame), // main SDI frame window RUNTIME_CLASS(CView)); AddDocTemplate(pDocTemplate); /* CMDIFrameWnd* pMainFrame = new CMDIFrameWnd; if (!pMainFrame->LoadFrame(IDR_MAINFRAME)) return FALSE; */ // create main window CMainFrame* pMainFrame = new CMainFrame; if (!pMainFrame->LoadFrame(IDR_MAINFRAME)) return FALSE; m_pMainWnd = pMainFrame; int nCmdShow = m_nCmdShow; // Also in this example, there is only one menubar shared between // all the views. The automatic menu enabling support of MFC // will disable the menu items that don't apply based on the // currently active view. The one MenuBar is used for all // document types, including when there are no open documents. // enable file manager drag/drop and DDE Execute open pMainFrame->DragAcceptFiles(); // Now finally show the main menu //pMainFrame->ShowWindow(m_nCmdShow); //pMainFrame->UpdateWindow(); m_pMainWnd = pMainFrame; // command line arguments are ignored, create a new (empty) document //OnFileNew(); // DOC // // Parse command line for standard shell commands, DDE, file open CCommandLineInfo cmdInfo; ParseCommandLine(cmdInfo); TCHAR ModulePath[MAX_PATH + 1]; ModulePath[0] = '\0'; ::GetModuleFileName(NULL, ModulePath, sizeof(ModulePath)/sizeof(TCHAR) - 1); hts_rootdir(ModulePath); // Restore position ((CMainFrame*)m_pMainWnd)->InitialShowWindow(nCmdShow); pMainFrame->UpdateWindow(); // Dispatch commands specified on the command line if (!ProcessShellCommand(cmdInfo)) return FALSE; // Init Winsock WSockInit(); // The one and only window has been initialized, so show and update it. //m_pMainWnd->ShowWindow(SW_SHOW); //m_pMainWnd->UpdateWindow(); /*CWinApp* app=AfxGetApp(); POSITION pos; pos=app->GetFirstDocTemplatePosition(); CDocTemplate* templ = app->GetNextDocTemplate(pos); pos=templ->GetFirstDocPosition(); CDocument* doc = templ->GetNextDoc(pos); CRuntimeClass* pRuntimeClass = RUNTIME_CLASS( CTest ); CObject* pObject = pRuntimeClass->CreateObject(); ASSERT( pObject->IsKindOf( RUNTIME_CLASS( CTest ) ) ); doc->AddView((CView*) pObject); */ { // enable file manager drag/drop and DDE Execute open EnableShellOpen(); RegisterShellFileTypes(); CWinApp* pApp = AfxGetApp(); // register "New File" handler if (pApp->GetProfileInt("Interface","SetupRun",0) != 1 || pApp->GetProfileInt("Interface","SetupHasRegistered",0) == 1) { HKEY phkResult; DWORD creResult; if (RegCreateKeyEx(HKEY_CLASSES_ROOT,".whtt",0,NULL,REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,NULL,&phkResult,&creResult)==ERROR_SUCCESS) { RegCloseKey(phkResult); if (RegCreateKeyEx(HKEY_CLASSES_ROOT,".whtt\\ShellNew",0,NULL,REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,NULL,&phkResult,&creResult)==ERROR_SUCCESS) { char voidbuff='\0'; RegSetValueEx(phkResult,"NullFile",0,REG_SZ,(LPBYTE)&voidbuff,1); RegCloseKey(phkResult); } } } // Infos la 1ere fois! if (pApp->GetProfileInt("Interface","FirstRun",0) != 3) { pApp->WriteProfileInt("Interface","FirstRun",3); Cabout about; about.DoModal(); // Default proxy? Check is the current IP looks local or not. BOOL isPublic = FALSE; char hostname[256]; if (gethostname(hostname, sizeof(hostname) - 1) == 0) { struct addrinfo* res = NULL; struct addrinfo hints; memset(&hints, 0, sizeof(hints)); hints.ai_family = PF_UNSPEC; hints.ai_socktype = SOCK_STREAM; hints.ai_protocol = IPPROTO_TCP; if (getaddrinfo(hostname, NULL, &hints, &res) == 0) { if (res->ai_addr != NULL && res->ai_addrlen > 0) { if (res->ai_family == AF_INET) { sockaddr_in *const si = (sockaddr_in*) res->ai_addr; const unsigned char *const ipv4 = (unsigned char*) &si->sin_addr; isPublic = ! ( ipv4[0] == 10 /* 10/8 */ || (ipv4[0] == 192 && ipv4[1] == 168) /* 192.168/16 */ || (ipv4[0] == 172 && ipv4[1] >= 16 && ipv4[1] <= 31) /* 172.16/12 */ ); } else if (res->ai_family == AF_INET6) { /* assume no more proxy */ isPublic = TRUE; } } } if (res) { freeaddrinfo(res); } } if (!isPublic && maintab) { maintab->DefineDefaultProxy(); if (maintab->DoModal()!=IDCANCEL) { // Default proxy values CString strSection = "OptionsValues"; MyWriteProfileString("",strSection, "Proxy",maintab->m_option10.m_proxy); MyWriteProfileString("",strSection, "Port",maintab->m_option10.m_port); } maintab->UnDefineDefaultProxy(); } } } #ifdef HTTRACK_AFF_WARNING #ifndef _DEBUG AfxMessageBox("--WARNING--\r\n"HTTRACK_AFF_WARNING); #endif #endif return TRUE; }
void ht_init(void) { hts_init(); opt = hts_create_opt(); };
int main(int argc, char **argv) { int ret = 0; httrackp *opt; #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) { printf("Winsock not found!\n"); return; } else if (LOBYTE(wsadata.wVersion) != 1 && HIBYTE(wsadata.wVersion) != 1) { printf("WINSOCK.DLL does not support version 1.1\n"); WSACleanup(); return; } } #endif signal_handlers(); hts_init(); // Check version compatibility if (hts_sizeof_opt() != sizeof(httrackp)) { fprintf(stderr, "incompatible current httrack library version %s, expected version %s", hts_version(), HTTRACK_VERSIONID); abortLog("incompatible httrack library version, please update both httrack and its library"); } opt = global_opt = hts_create_opt(); assert(opt->size_httrackp == sizeof(httrackp)); 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); if (ret) { fprintf(stderr, "* %s\n", hts_errmsg(opt)); } global_opt = NULL; hts_free_opt(opt); htsthread_wait(); /* wait for pending threads */ hts_uninit(); #ifdef _WIN32 WSACleanup(); #endif return ret; }
int main(int argc, char* argv[]) { int i; int ret = 0; int defaultPort = 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>] <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); /* 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) { 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 { smallserver_setkey(argv[i], argv[i + 1]); } } /* sigpipe */ #ifndef _WIN32 signal( SIGPIPE , htsweb_sig_brpipe ); // broken pipe (write into non-opened socket) #endif /* launch */ ret = help_server(argv[1], defaultPort); htsthread_wait(); hts_uninit(); #ifdef _WIN32 WSACleanup(); #endif return ret; }
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 ; }
/* * Name: main * Description: main() function * Parameters: None * Should return: error status */ int main(void) { /* First, ask for an URL Note: For the test, option r2 (mirror max depth=1) and --testscan (no index, no cache, do not store, no log files) */ char _argv[][256] = {"httrack_test" , "<URL>" , "-r3" , "--testscan" , "" }; char* argv[] = {NULL , NULL , NULL , NULL , NULL}; int argc = 0; httrackp *opt; int ret; while(strlen(_argv[argc])) { argv[argc]=_argv[argc]; argc++; } argv[argc]=NULL; printf("HTTrackLib test program\n"); printf("Enter URL (example: www.foobar.com/index.html) :"); scanf("%s",argv[1]); printf("Test: 1 depth\n"); /* Initialize the library */ #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) { printf("Winsock not found!\n"); return; } else if (LOBYTE(wsadata.wVersion) != 1 && HIBYTE(wsadata.wVersion) != 1) { printf("WINSOCK.DLL does not support version 1.1\n"); WSACleanup(); return; } } #endif hts_init(); /* Create option settings and set callbacks (wrappers) */ opt = hts_create_opt(); CHAIN_FUNCTION(opt, init, httrack_wrapper_init, NULL); CHAIN_FUNCTION(opt, uninit, httrack_wrapper_uninit, NULL); CHAIN_FUNCTION(opt, start, httrack_wrapper_start, NULL); CHAIN_FUNCTION(opt, end, httrack_wrapper_end, NULL); CHAIN_FUNCTION(opt, chopt, httrack_wrapper_chopt, NULL); CHAIN_FUNCTION(opt, preprocess, httrack_wrapper_preprocesshtml, NULL); CHAIN_FUNCTION(opt, postprocess, httrack_wrapper_postprocesshtml, NULL); CHAIN_FUNCTION(opt, check_html, httrack_wrapper_checkhtml, NULL); CHAIN_FUNCTION(opt, query, httrack_wrapper_query, NULL); CHAIN_FUNCTION(opt, query2, httrack_wrapper_query2, NULL); CHAIN_FUNCTION(opt, query3, httrack_wrapper_query3, NULL); CHAIN_FUNCTION(opt, loop, httrack_wrapper_loop, NULL); CHAIN_FUNCTION(opt, check_link, httrack_wrapper_check, NULL); CHAIN_FUNCTION(opt, check_mime, httrack_wrapper_check_mime, NULL); CHAIN_FUNCTION(opt, pause, httrack_wrapper_pause, NULL); CHAIN_FUNCTION(opt, filesave, httrack_wrapper_filesave, NULL); CHAIN_FUNCTION(opt, filesave2, httrack_wrapper_filesave2, NULL); CHAIN_FUNCTION(opt, linkdetected, httrack_wrapper_linkdetected, NULL); CHAIN_FUNCTION(opt, linkdetected2, httrack_wrapper_linkdetected2, NULL); CHAIN_FUNCTION(opt, xfrstatus, httrack_wrapper_xfrstatus, NULL); CHAIN_FUNCTION(opt, savename, httrack_wrapper_savename, NULL); CHAIN_FUNCTION(opt, sendhead, httrack_wrapper_sendheader, NULL); CHAIN_FUNCTION(opt, receivehead, httrack_wrapper_receiveheader, NULL); /* Then, launch the mirror */ ret = hts_main2(argc, argv, opt); /* Wait for a key */ printf("\nPress ENTER key to exit\n"); scanf("%s",argv[1]); /* Clear option state */ hts_free_opt(opt); hts_uninit(); #ifdef _WIN32 WSACleanup(); #endif /* That's all! */ return 0; }