int load_config (void) { char *cfg, *sp; int res, val, i; g_assert(check_config_dir () == 0); if (!g_file_get_contents (default_file (), &cfg, NULL, NULL)) return -1; /* If the config is incomplete we have the default values loaded */ load_default_config(); i = 0; do { switch (vars[i].type) { case TYPE_STR: cfg_get_str (cfg, vars[i].name, (char *) &prefs + vars[i].offset, vars[i].len); break; case TYPE_BOOL: case TYPE_INT: val = cfg_get_int_with_result (cfg, vars[i].name, &res); if (res) *((int *) &prefs + vars[i].offset) = val; break; } i++; } while (vars[i].name); g_free (cfg); if (prefs.hex_gui_win_height < 138) prefs.hex_gui_win_height = 138; if (prefs.hex_gui_win_width < 106) prefs.hex_gui_win_width = 106; sp = strchr (prefs.hex_irc_user_name, ' '); if (sp) sp[0] = 0; /* spaces in username would break the login */ return 0; }
int Read_ConfigFile() { int i, tmp; GKeyFile * keyfile = g_key_file_new(); GError * error = NULL; load_default_config(); g_key_file_load_from_file(keyfile, CONFIG_FILE, G_KEY_FILE_NONE, 0); const char *c; /* Load keypad keys */ for(i = 0; i < NB_KEYS; i++) { tmp = g_key_file_get_integer(keyfile, "KEYS", key_names[i], &error); if (error != NULL) { g_error_free(error); error = NULL; } else { keyboard_cfg[i] = tmp; } } /* Load joypad keys */ for(i = 0; i < NB_KEYS; i++) { tmp = g_key_file_get_integer(keyfile, "JOYKEYS", key_names[i], &error); if (error != NULL) { g_error_free(error); error = NULL; } else { joypad_cfg[i] = tmp; } } g_key_file_free(keyfile); return 0; }
GKeyFile *desmume_config_read_file() { gchar *config_file; GKeyFile *keyfile; GError *error = NULL; gboolean ret; config_file = g_build_filename(g_get_home_dir(), desmume_config_file, NULL); keyfile = g_key_file_new(); ret = g_key_file_load_from_file(keyfile, config_file, G_KEY_FILE_NONE, &error); if (!ret) { g_error_free(error); } g_free(config_file); load_default_config(gtk_kb_cfg); desmume_config_read_keys(keyfile); desmume_config_read_joykeys(keyfile); return keyfile; }
GKeyFile *desmume_config_read_file(const u16 *kb_cfg) { gchar *config_file, *config_dir, *old_config_file; GKeyFile *keyfile; GError *error = NULL; gboolean ret; old_config_file = g_build_filename(g_get_home_dir(), desmume_old_config_file, NULL); config_file = g_build_filename(g_get_user_config_dir(), desmume_config_dir, desmume_config_file, NULL); config_dir = g_build_filename(g_get_user_config_dir(), desmume_config_dir, NULL); g_mkdir_with_parents(config_dir, 0755); if (!g_file_test(config_file, G_FILE_TEST_IS_REGULAR) && g_file_test(old_config_file, G_FILE_TEST_IS_REGULAR)) { ret = g_rename(old_config_file, config_file); if (ret) { g_printerr("Failed to move old config file %s to new location %s \n", old_config_file, config_file); } } keyfile = g_key_file_new(); ret = g_key_file_load_from_file(keyfile, config_file, G_KEY_FILE_NONE, &error); if (!ret) { g_error_free(error); } g_free(config_file); g_free(config_dir); g_free(old_config_file); load_default_config(kb_cfg); desmume_config_read_keys(keyfile); desmume_config_read_joykeys(keyfile); return keyfile; }
int main (int argc, char *argv[]) { int i; int ret; srand (time (0)); /* CL: do this only once! */ /* We must check for the config dir parameter, otherwise load_config() will behave incorrectly. * load_config() must come before fe_args() because fe_args() calls gtk_init() which needs to * know the language which is set in the config. The code below is copy-pasted from fe_args() * for the most part. */ if (argc >= 3) { for (i = 1; i < argc - 1; i++) { if (strcmp (argv[i], "-d") == 0) { if (xdir) { g_free (xdir); } xdir = strdup (argv[i + 1]); if (xdir[strlen (xdir) - 1] == G_DIR_SEPARATOR) { xdir[strlen (xdir) - 1] = 0; } } } } #if ! GLIB_CHECK_VERSION (2, 36, 0) g_type_init (); #endif if (check_config_dir () == 0) { if (load_config () != 0) load_default_config (); } else { /* this is probably the first run */ load_default_config (); make_config_dirs (); make_dcc_dirs (); } /* we MUST do this after load_config () AND before fe_init (thus gtk_init) otherwise it will fail */ set_locale (); #ifdef SOCKS SOCKSinit (argv[0]); #endif ret = fe_args (argc, argv); if (ret != -1) return ret; #ifdef USE_DBUS hexchat_remote (); #endif #ifdef USE_LIBPROXY libproxy_factory = px_proxy_factory_new(); #endif fe_init (); /* This is done here because cfgfiles.c is too early in * the startup process to use gtk functions. */ if (g_access (get_xdir (), W_OK) != 0) { char buf[2048]; g_snprintf (buf, sizeof(buf), _("You do not have write access to %s. Nothing from this session can be saved."), get_xdir ()); fe_message (buf, FE_MSG_ERROR); } #ifndef WIN32 #ifndef __EMX__ /* OS/2 uses UID 0 all the time */ if (getuid () == 0) fe_message (_("* Running IRC as root is stupid! You should\n" " create a User Account and use that to login.\n"), FE_MSG_WARN|FE_MSG_WAIT); #endif #endif /* !WIN32 */ xchat_init (); fe_main (); #ifdef USE_LIBPROXY px_proxy_factory_free(libproxy_factory); #endif #ifdef WIN32 WSACleanup (); #endif return 0; }
int main (int argc, char *argv[]) { int i; int ret; srand (time (0)); /* CL: do this only once! */ /* We must check for the config dir parameter, otherwise load_config() will behave incorrectly. * load_config() must come before fe_args() because fe_args() calls gtk_init() which needs to * know the language which is set in the config. The code below is copy-pasted from fe_args() * for the most part. */ if (argc >= 3) { for (i = 1; i < argc - 1; i++) { if (strcmp (argv[i], "-d") == 0) { if (xdir) { g_free (xdir); } xdir = strdup (argv[i + 1]); if (xdir[strlen (xdir) - 1] == G_DIR_SEPARATOR) { xdir[strlen (xdir) - 1] = 0; } } } } #if ! GLIB_CHECK_VERSION (2, 36, 0) g_type_init (); #endif if (check_config_dir () == 0) { if (load_config () != 0) load_default_config (); } else { /* this is probably the first run */ load_default_config (); make_config_dirs (); /* FIXME: if this fail display an error (?) */ make_dcc_dirs (); } /* we MUST do this after load_config () AND before fe_init (thus gtk_init) otherwise it will fail */ set_locale (); #ifdef SOCKS SOCKSinit (argv[0]); #endif ret = fe_args (argc, argv); if (ret != -1) return ret; #ifdef USE_DBUS hexchat_remote (); #endif #ifdef USE_LIBPROXY libproxy_factory = px_proxy_factory_new(); #endif fe_init (); #ifndef WIN32 #ifndef __EMX__ /* OS/2 uses UID 0 all the time */ if (getuid () == 0) fe_message (_("* Running IRC as root is stupid! You should\n" " create a User Account and use that to login.\n"), FE_MSG_WARN|FE_MSG_WAIT); #endif #endif /* !WIN32 */ xchat_init (); fe_main (); #ifdef USE_LIBPROXY px_proxy_factory_free(libproxy_factory); #endif #ifdef USE_OPENSSL if (ctx) _SSL_context_free (ctx); #endif #ifdef USE_DEBUG hexchat_mem_list (); #endif #ifdef WIN32 WSACleanup (); #endif return 0; }
int main (int argc, char *argv[]) { int i; int ret; // BEGIN NEW CODE server *fake_serv; GIOChannel *channel; session *sess; // END NEW CODE #ifdef WIN32 HRESULT coinit_result; #endif srand ((unsigned int) time (NULL)); /* CL: do this only once! */ /* We must check for the config dir parameter, otherwise load_config() will behave incorrectly. * load_config() must come before fe_args() because fe_args() calls gtk_init() which needs to * know the language which is set in the config. The code below is copy-pasted from fe_args() * for the most part. */ if (argc >= 2) { for (i = 1; i < argc; i++) { if ((strcmp (argv[i], "-d") == 0 || strcmp (argv[i], "--cfgdir") == 0) && i + 1 < argc) { xdir = g_strdup (argv[i + 1]); } else if (strncmp (argv[i], "--cfgdir=", 9) == 0) { xdir = g_strdup (argv[i] + 9); } if (xdir != NULL) { if (xdir[strlen (xdir) - 1] == G_DIR_SEPARATOR) { xdir[strlen (xdir) - 1] = 0; } break; } } } #if ! GLIB_CHECK_VERSION (2, 36, 0) // RFM: Don't think we hit this g_type_init (); #endif if (check_config_dir () == 0) { if (load_config () != 0) load_default_config (); } else { /* this is probably the first run */ load_default_config (); make_config_dirs (); make_dcc_dirs (); } /* we MUST do this after load_config () AND before fe_init (thus gtk_init) otherwise it will fail */ // RFM: Does nothing on *NIX set_locale (); // RFM: Parses some command line crap. Not important ret = fe_args (argc, argv); if (ret != -1) return ret; #ifdef USE_DBUS hexchat_remote (); #endif #ifdef USE_LIBPROXY // RFM: Not using libproxy_factory = px_proxy_factory_new(); #endif #ifdef WIN32 coinit_result = CoInitializeEx (NULL, COINIT_APARTMENTTHREADED); if (SUCCEEDED (coinit_result)) { CoInitializeSecurity (NULL, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_DEFAULT, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE, NULL); } #endif // RFM: Inits some fe-text stuff fe_init (); // RFM: Pretty sure this just allows us to save chats... /* This is done here because cfgfiles.c is too early in * the startup process to use gtk functions. */ if (g_access (get_xdir (), W_OK) != 0) { char buf[2048]; g_snprintf (buf, sizeof(buf), _("You do not have write access to %s. Nothing from this session can be saved."), get_xdir ()); fe_message (buf, FE_MSG_ERROR); } // RFM: Checks if root on *NIX #ifndef WIN32 #ifndef __EMX__ /* OS/2 uses UID 0 all the time */ if (getuid () == 0) fe_message (_("* Running IRC as root is stupid! You should\n" " create a User Account and use that to login.\n"), FE_MSG_WARN|FE_MSG_WAIT); #endif #endif /* !WIN32 */ // RFM: Loads a bunch of configure options xchat_init (); // BEGIN NEW CODE fake_serv = server_new(); fake_serv->sok = STDIN_FILENO; // fake_serv->pos = 0; //??? sess = session_new(fake_serv, "fake_sess", SESS_CHANNEL, 0); fake_serv->server_session = sess; fake_serv->front_session = sess; channel = g_io_channel_unix_new(STDIN_FILENO); g_io_add_watch(channel, G_IO_IN, (GIOFunc)server_read, fake_serv); //g_io_add_watch(channel, G_IO_IN, (GIOFunc)io_callback, fake_serv); g_io_channel_unref(channel); // END NEW CODE fe_main (); #ifdef WIN32 if (SUCCEEDED (coinit_result)) { CoUninitialize (); } #endif #ifdef USE_LIBPROXY px_proxy_factory_free(libproxy_factory); #endif #ifdef WIN32 WSACleanup (); #endif return 0; }
BOOL CKillDBGApp::InitInstance() { // InitCommonControlsEx() is required on Windows XP if an application // manifest specifies use of ComCtl32.dll version 6 or later to enable // visual styles. Otherwise, any window creation will fail. INITCOMMONCONTROLSEX InitCtrls; InitCtrls.dwSize = sizeof(InitCtrls); // Set this to include all the common control classes you want to use // in your application. InitCtrls.dwICC = ICC_WIN95_CLASSES; InitCommonControlsEx(&InitCtrls); Scintilla_RegisterClasses(m_hInstance); CWinApp::InitInstance(); // 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 // 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(_T("KillDBG")); // To create the main window, this code creates a new frame window // object and then sets it as the application's main window object //提升自身到 Debug Privilege HANDLE hProcess=GetCurrentProcess(); HANDLE hToken; BOOL bRet=FALSE; if (OpenProcessToken(hProcess, TOKEN_ADJUST_PRIVILEGES, &hToken)) { LUID luid; if (LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &luid)) { TOKEN_PRIVILEGES tp; tp.PrivilegeCount=1; tp.Privileges[0].Luid=luid; tp.Privileges[0].Attributes=SE_PRIVILEGE_ENABLED; if (AdjustTokenPrivileges(hToken, FALSE, &tp, NULL, (PTOKEN_PRIVILEGES)NULL, (PDWORD)NULL)) { bRet=(GetLastError() == ERROR_SUCCESS); } } CloseHandle(hToken); } if (!bRet) { MessageBox(NULL,_T("提升进程权限到SE_DEBUG_NAME失败,可能会导致部分进程无法调试"),NULL,MB_OK | MB_ICONWARNING); } // 加载配置 if (!load_app_confgi()) { load_default_config(); } //创建主窗口 main_frame = new CMainFrame; if (!main_frame) return FALSE; m_pMainWnd = main_frame; // create and load the frame with its resources main_frame->LoadFrame(IDR_MAINFRAME,WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, NULL,NULL); // The one and only window has been initialized, so show and update it main_frame->ShowWindow(SW_SHOW); main_frame->UpdateWindow(); // call DragAcceptFiles only if there's a suffix // In an SDI app, this should occur after ProcessShellCommand return TRUE; }
/* * Load a set of modules */ void Library_State::initialize(bool thread_safe) { CPUID::initialize(); if(mutex_factory) throw Invalid_State("Library_State has already been initialized"); if(!thread_safe) { mutex_factory = new Noop_Mutex_Factory; } else { #if defined(BOTAN_HAS_MUTEX_PTHREAD) mutex_factory = new Pthread_Mutex_Factory; #elif defined(BOTAN_HAS_MUTEX_WIN32) mutex_factory = new Win32_Mutex_Factory; #else throw Invalid_State("Could not find a thread-safe mutex object to use"); #endif } allocator_lock = get_mutex(); config_lock = get_mutex(); global_rng_lock = get_mutex(); default_allocator_name = has_mlock() ? "locking" : "malloc"; add_allocator(new Malloc_Allocator); add_allocator(new Locking_Allocator(get_mutex())); #if defined(BOTAN_HAS_ALLOC_MMAP) add_allocator(new MemoryMapping_Allocator(get_mutex())); #endif load_default_config(); m_algorithm_factory = new Algorithm_Factory(*mutex_factory); #if defined(BOTAN_HAS_ENGINE_GNU_MP) algorithm_factory().add_engine(new GMP_Engine); #endif #if defined(BOTAN_HAS_ENGINE_OPENSSL) algorithm_factory().add_engine(new OpenSSL_Engine); #endif #if defined(BOTAN_HAS_ENGINE_AES_ISA) algorithm_factory().add_engine(new AES_ISA_Engine); #endif #if defined(BOTAN_HAS_ENGINE_SIMD) algorithm_factory().add_engine(new SIMD_Engine); #endif #if defined(BOTAN_HAS_ENGINE_ASSEMBLER) algorithm_factory().add_engine(new Assembler_Engine); #endif algorithm_factory().add_engine(new Core_Engine); #if defined(BOTAN_HAS_SELFTESTS) confirm_startup_self_tests(algorithm_factory()); #endif }
/*Ceci est un menu special * Il ne suit pas les memes * regles que les autres menus * Accessoirement c'est tres moche*/ void options_menu(config *cfg) { config tmp = *cfg; int i, j=0, nb=9, couleur[nb], available[nb], selection=0; SDL_Surface *pac[2], *ghost[2], *fleche[2]; SDL_Rect pos; POINT p1; Input in; char title[64]; char options[nb][64]; for(i=0; i<nb; i++) { available[i]=1; couleur[i]=blanc; } pac[0] = IMG_Load("image/pacman/2.png"); pac[1] = IMG_Load("image/pacman/3.png"); ghost[0] = IMG_Load("image/ghosts/2.png"); ghost[1] = IMG_Load("image/ghosts/3.png"); fleche[0] = IMG_Load("image/menu/triangler.png"); fleche[1] = IMG_Load("image/menu/trianglel.png"); if(pac == NULL || ghost == NULL) { fprintf(stderr, "Erreur loading pngs in >>options_menu()<<\n"); exit(EXIT_FAILURE); } memset(&in,0,sizeof(in)); strcpy(title, "OPTIONS"); strcpy(options[0], "Nb players"); sprintf(options[1], "%d", cfg->nb_players); strcpy(options[2], "Player 1"); strcpy(options[3], "Player 2"); strcpy(options[4], "Sound"); strcpy(options[5], "Reset score"); strcpy(options[6], "Reset"); strcpy(options[7], "Cancel"); strcpy(options[8], "Save"); available[1]=0; available[4]=0; if(cfg->nb_players==0) { available[2]=0; available[3]=0; } else if(cfg->nb_players==1) available[3]=0; DELAY=60; while(!in.quit) { SDL_Delay(DELAY); for(i=0; i<nb; i++) { if(!available[i] && i!=1) couleur[i]=gris; else couleur[i]=blanc; } couleur[selection]=blanc; UpdateEvents(&in); if(in.key[SDLK_ESCAPE]) exit(EXIT_SUCCESS); else if(in.key[SDLK_RETURN]) { in.key[SDLK_RETURN]=0; if(selection==nb-4) //reset score { reset_score("data/results.txt"); reset_score("data/survivor.txt"); } if(selection==nb-3) { load_default_config(cfg); //default config sprintf(options[1], "%d", cfg->nb_players); available[2]=1; available[3]=0; } else if(selection==nb-2) //Cancel { *cfg=tmp; return; } else if(selection==nb-1) //Save { if(cfg->nb_players==2) { if(cfg->players[0].character == PACMAN && cfg->players[1].character == PACMAN) fprintf(stderr, "Only one pacman is allowed!\n"); //Should not happen else return; } else return; } } else if(in.key[SDLK_DOWN]) { in.key[SDLK_DOWN]=0; selection=(selection+1)%nb; while(!available[selection]) selection=(selection+1)%nb; } else if(in.key[SDLK_UP]) { in.key[SDLK_UP]=0; if(!(selection)) selection=nb-1; else selection=(selection-1)%nb; while(!available[selection]) { if(!selection) selection=nb-1; else selection=(selection-1)%nb; } } else if(in.key[SDLK_LEFT]) { in.key[SDLK_LEFT]=0; if(selection==0) { if(cfg->nb_players>0) { available[cfg->nb_players+1]=0; cfg->nb_players=cfg->nb_players-1; sprintf(options[1], "%d", cfg->nb_players); } } else if(selection==2 || selection==3) { if(cfg->players[selection-2].character == PACMAN) cfg->players[selection-2].character = GHOST; else if(cfg->players[selection-2].character == GHOST) cfg->players[selection-2].character = PACMAN; } } else if(in.key[SDLK_RIGHT]) { in.key[SDLK_RIGHT]=0; if(selection==0) { if(cfg->nb_players<2) { available[cfg->nb_players+2]=1; cfg->nb_players=(cfg->nb_players+1); sprintf(options[1], "%d", cfg->nb_players); } } else if(selection==2 || selection==3) { if(cfg->players[selection-2].character == PACMAN) cfg->players[selection-2].character = GHOST; else if(cfg->players[selection-2].character == GHOST) cfg->players[selection-2].character = PACMAN; } } SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0)); couleur[selection]=jaune; p1.x=300; p1.y=50; aff_pol(title, 50, p1, jaune); //Le titre p1.x=310; p1.y=150; aff_pol(options[0], 30, p1, couleur[0]); //Nb players pos.x=p1.x+120; pos.y=p1.y; SDL_BlitSurface(fleche[1], NULL, screen, &pos); p1.x+=150; aff_pol(options[1], 30, p1, couleur[1]); //Nb players pos.x+=50; SDL_BlitSurface(fleche[0], NULL, screen, &pos); //Afficher des fleches j=(j+1)%2; p1.x=250; p1.y=225; pos.x=p1.x+10; pos.y=p1.y+50; aff_pol(options[2], 30, p1, couleur[2]); //Player 1 SDL_BlitSurface(fleche[1], NULL, screen, &pos); pos.x+=25; if(cfg->players[0].character == GHOST) SDL_BlitSurface(ghost[j], NULL, screen, &pos); else SDL_BlitSurface(pac[j], NULL, screen, &pos); pos.x+=25; SDL_BlitSurface(fleche[0], NULL, screen, &pos); //Afficher des fleches p1.x+=200; pos.x=p1.x+10; aff_pol(options[3], 30, p1, couleur[3]); //Player 2 SDL_BlitSurface(fleche[1], NULL, screen, &pos); pos.x+=25; if(cfg->players[1].character == GHOST) SDL_BlitSurface(ghost[j], NULL, screen, &pos); else SDL_BlitSurface(pac[j], NULL, screen, &pos); pos.x+=25; SDL_BlitSurface(fleche[0], NULL, screen, &pos); //Afficher des fleches p1.x=250; p1.y+=100; aff_pol(options[4], 30, p1, couleur[4]); //Sound //Afficher des images pour le son p1.x=250; p1.y+=75; aff_pol(options[5], 30, p1, couleur[5]); //Reset score p1.x=150; p1.y+=100; for(i=6; i<nb; i++) { aff_pol(options[i], 30, p1, couleur[i]); p1.x+=225; } SDL_Flip(screen); } }
int main (int argc, char *argv[]) { int i; int ret; #ifdef WIN32 HRESULT coinit_result; #endif srand ((unsigned int) time (NULL)); /* CL: do this only once! */ /* We must check for the config dir parameter, otherwise load_config() will behave incorrectly. * load_config() must come before fe_args() because fe_args() calls gtk_init() which needs to * know the language which is set in the config. The code below is copy-pasted from fe_args() * for the most part. */ if (argc >= 2) { for (i = 1; i < argc; i++) { if ((strcmp (argv[i], "-d") == 0 || strcmp (argv[i], "--cfgdir") == 0) && i + 1 < argc) { xdir = g_strdup (argv[i + 1]); } else if (strncmp (argv[i], "--cfgdir=", 9) == 0) { xdir = g_strdup (argv[i] + 9); } if (xdir != NULL) { if (xdir[strlen (xdir) - 1] == G_DIR_SEPARATOR) { xdir[strlen (xdir) - 1] = 0; } break; } } } #if ! GLIB_CHECK_VERSION (2, 36, 0) g_type_init (); #endif if (check_config_dir () == 0) { if (load_config () != 0) load_default_config (); } else { /* this is probably the first run */ load_default_config (); make_config_dirs (); make_dcc_dirs (); } /* we MUST do this after load_config () AND before fe_init (thus gtk_init) otherwise it will fail */ set_locale (); ret = fe_args (argc, argv); if (ret != -1) return ret; #ifdef USE_DBUS hexchat_remote (); #endif #ifdef USE_LIBPROXY libproxy_factory = px_proxy_factory_new(); #endif #ifdef WIN32 coinit_result = CoInitializeEx (NULL, COINIT_APARTMENTTHREADED); if (SUCCEEDED (coinit_result)) { CoInitializeSecurity (NULL, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_DEFAULT, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE, NULL); } #endif fe_init (); /* This is done here because cfgfiles.c is too early in * the startup process to use gtk functions. */ if (g_access (get_xdir (), W_OK) != 0) { char buf[2048]; g_snprintf (buf, sizeof(buf), _("You do not have write access to %s. Nothing from this session can be saved."), get_xdir ()); fe_message (buf, FE_MSG_ERROR); } #ifndef WIN32 #ifndef __EMX__ /* OS/2 uses UID 0 all the time */ if (getuid () == 0) fe_message (_("* Running IRC as root is stupid! You should\n" " create a User Account and use that to login.\n"), FE_MSG_WARN|FE_MSG_WAIT); #endif #endif /* !WIN32 */ xchat_init (); fe_main (); #ifdef WIN32 if (SUCCEEDED (coinit_result)) { CoUninitialize (); } #endif #ifdef USE_LIBPROXY px_proxy_factory_free(libproxy_factory); #endif #ifdef WIN32 WSACleanup (); #endif return 0; }
int main(int argc, char *argv[]) { const char *s, *query_args; time_t if_modified_since = 0; int i; umask(007); load_default_config(); if (parse_configfile(rssrollrc, config_cb) == -1) { render_error("error: cannot open config file: %s", rssrollrc); goto done; } /*if (chdir("/tmp")) { printf("error main: chdir: /tmp: %s", strerror(errno)); render_error("chdir: /tmp: %s", strerror(errno)); goto done; } */ if (sqlite3_open(rssroll->dbpath, &db) != SQLITE_OK) { render_error("cannot load database: %s", rssroll->dbpath); goto done; } // default feeds snprintf(query_category, sizeof(query_string), "%d", rssroll->defcat); snprintf(query_limit, sizeof(query_limit), "0"); if ((q = get_query()) == NULL) { render_error("get_query"); printf("error main: get_query() NULL"); goto done; } if ((s = getenv("QUERY_STRING")) != NULL) { if (strlen(s) > 64) { printf("Status: 400\r\n\r\n You are trying to send very long query!\n"); fflush(stdout); return (0); } else if (strstr(s, "&") != NULL) { printf("warning main: escaped query '%s', user agent '%s', " "referer '%s'", s, q->user_agent ? q->user_agent : "(null)", q->referer ? q->referer : "(null)"); printf("Status: 400\r\n\r\nHTML escaped ampersand in cgi " "query string \"%s\"\n" "This might be a problem in your client \"%s\",\n" "or in the referring document \"%s\"\n" "See http://www.htmlhelp.org/tools/validator/problems.html" "#amp\n", s, q->user_agent ? q->user_agent : "", q->referer ? q->referer : ""); fflush(stdout); return (0); } else { for (i = 0; i < strlen(s); i++) { /* sanity check of the query string, accepts only alpha */ if (!isdigit(s[i])) { if(s[i] != '/') { printf("Status: 400\r\n\r\nYou are trying to send wrong query!\n"); fflush(stdout); return (0); } } } snprintf(query_string, sizeof(query_string), "%s", s); query_args = strtok(query_string, "/"); snprintf(query_category, sizeof(query_category), "%s", query_args); query_args = strtok(NULL, "/"); if (query_args != NULL) snprintf(query_limit, sizeof(query_limit), "%s", query_args); } } if ((q->referer != NULL && strstr(q->referer, "morisit")) || (s != NULL && strstr(s, "http://"))) { printf("Status: 503\r\n\r\nWe are not redirecting, " "nice try.\n"); fflush(stdout); return (0); } if (q->user_agent != NULL && !strncmp(q->user_agent, "Googlebot", 9)) { printf("Status: 503\r\n\r\nGooglebot you are not.\n"); fflush(stdout); return (0); } if ((s = getenv("IF_MODIFIED_SINCE")) != NULL) { if_modified_since = convert_rfc822_time(s); if (!if_modified_since) if_modified_since = (time_t)strtoul(s, NULL, 10); if (!if_modified_since) printf("warning main: invalid IF_MODIFIED_SINCE '%s'", s); } if ((s = getenv("HTTP_ACCEPT_ENCODING")) != NULL) { char *p = strstr(s, "gzip"); if (p != NULL && (strncmp(p, "gzip;q=0", 8) || atoi(p + 7) > 0.0)) { gz = gzdopen(fileno(stdout), "wb9"); if (gz == NULL) printf("error main: gzdopen"); else printf("Content-Encoding: gzip\r\n"); } } char fn[1024]; printf("%s\r\n\r\n", rssroll->ct_html); fflush(stdout); snprintf(fn, sizeof(fn), "%s/main.html", rssroll->htmldir); render_html(fn, &render_front, NULL); done: if (gz != NULL) { if (gzclose(gz) != Z_OK) printf("error main: gzclose"); gz = NULL; } else fflush(stdout); if (q != NULL) free_query(q); sqlite3_close(db); return (0); }