Exemplo n.º 1
0
/*
 * 读取配置文件
 */
boolean login_config_read(struct login_config_struct *config)
{
	FILE *fp;
	char buf[20];
	int i, ret;
	char *config_file;
	struct list_ip *ip, *ip_head;
	struct list_user *user, *user_head;
	debug_where();
	if (!config->inited)
		goto out;
	config_file = find_file("user.conf");
	if (!config_file) {
		print_error(EWARNING, "配置文件不存在");
		goto out;
	}
	if ((fp = fopen(config_file, "r")) == NULL) {
		debug_where();
		print_error(EWARNING, "读取配置文件错误");
		goto out;
	}
	ret = fscanf(fp , "%s %d\n", buf, &config->ip_num);
	debug_print("%s %d\n",buf,config->ip_num);
	ip_head = &config->ip_list;
	for (i = 0; i < config->ip_num; i++) {
		ip = (struct list_ip *)malloc(sizeof(struct list_ip));
		ret = fscanf(fp, "%s\n", ip->ip);
		ip_head->next = ip;
		ip_head = ip_head->next;
		debug_print("%s\n",ip->ip);
	}
	ip_head = NULL;

	ret = fscanf(fp , "%s %d\n", buf, &config->user_num);
	debug_print("%s %d\n",buf,config->user_num);
	user_head = &config->user_list;
	for (i = 0; i < config->ip_num; i++) {
		user = (struct list_user *)malloc(sizeof(struct list_user));
		ret = fscanf(fp, "%s %d",user->user_name, &user->remember);
		if (user->remember)
			ret = fscanf(fp, "%s\n", user->passwd);
		else
			ret = fscanf(fp, "\n");
		user_head->next = user;
		user_head = user_head->next;
		debug_print("%s\n",user->user_name);
	}
	user_head = NULL;
	fclose(fp);
	if (ret < 0)
		goto out;

	config->inited = TRUE;
	return TRUE;
out:
	config->inited = FALSE;
	return FALSE;
}
Exemplo n.º 2
0
Arquivo: cedit.c Projeto: reyesr/lcrt
void lcrt_edit_on_copy_activate(GtkMenuItem *menuitem, gpointer user_data)
{
    struct lcrt_window *lwindow = (struct lcrt_window *)user_data;
    struct lcrt_terminal *lterminal = lwindow->w_notebook->current_terminal;

    debug_where();
    if (lcrt_terminal_has_selection(lwindow) == FALSE)
        return;
    debug_where();
    vte_terminal_copy_clipboard(lterminal->terminal);
}
Exemplo n.º 3
0
static boolean login_config_create(void)
{
	char *home, *p;
	char tmp[80];
	FILE *fp;
	home = get_user_home();
	if (!home)
		return FALSE;
	debug_where();
	snprintf(tmp, 80, "%s/."USER_CONFIG_DIR_NAME,home);
        if (access(tmp, F_OK) == -1) {
		if (mkdir(tmp, 0755) == -1)
			return FALSE;
	}
	strcat(tmp,"/config");
        if (access(tmp, F_OK) == -1) {
		if (mkdir(tmp, 0755) == -1)
			return FALSE;
	}
	strcat(tmp, "/user.conf");
        if (access(tmp,F_OK) == -1) {
		if ((fp = fopen(tmp, "w")) == NULL)
			return FALSE;
		fprintf(fp, "SERVERIP 0\nUSER 0\n");
		fclose(fp);
	}
	p = strrchr(tmp, '/');
	*p = '\0';
	add_file_directory(tmp);
	return TRUE;
}
Exemplo n.º 4
0
void lcrt_popup_on_deactivate(GtkObject *object, gpointer user_data)
{
    struct lcrt_popup *lpopup = (struct lcrt_popup *)user_data;
    debug_where();

    free(lpopup);
}
Exemplo n.º 5
0
Arquivo: cedit.c Projeto: reyesr/lcrt
void lcrt_edit_on_popup_menu_deactivate(GtkObject *object, gpointer user_data)
{
    struct lcrt_edit *ledit = (struct lcrt_edit *)user_data;
    debug_where();

    free(ledit);
}
Exemplo n.º 6
0
boolean login_config_free(struct login_config_struct *config)
{
	
	int i;
	struct list_ip *ip,*ip_tmp;
	struct list_user *user, *user_tmp;
	
	if (!login_config_error(config))
		return FALSE;
	ip = &config->ip_list;
	ip_tmp = ip->next;
	for (i = 0; i < config->ip_num; i++) {
		ip = ip_tmp->next;
		free(ip_tmp);
		ip_tmp = ip;
	}
	user = &config->user_list;
	user_tmp = user->next;
	for (i = 0; i < config->user_num; i++) {
		user = user_tmp->next;
		free(user_tmp);
		user_tmp = user;
	}
	debug_where();
	return TRUE;
}
Exemplo n.º 7
0
Arquivo: serial.c Projeto: reyesr/lcrt
/**
 * @brief the callback to write data to serial port.
 * @param widget
 * @param text the data to be write
 * @param length data length
 * @param point to struct lcrt_terminal.
 */
static void lcrt_serial_write(VteTerminal *widget, gchar *text, guint length, gpointer user_data)
{
    struct lcrt_terminal *lterminal = (struct lcrt_terminal *)user_data;
    struct lcrt_serial_tm *tserial = (struct lcrt_serial_tm *)lterminal->private_data;
    int fd = tserial->fd;

    debug_where();
    if (tserial->fd)
        write(fd, text, length);
}
Exemplo n.º 8
0
Arquivo: serial.c Projeto: reyesr/lcrt
static void lcrt_serial_disconnect(struct lcrt_terminal *lterminal)
{
    struct lcrt_serial_tm *tserial = lterminal->private_data;
    debug_where();
    if (lterminal->connected) {
        if (tserial && tserial->fd > 0) {
            close(tserial->fd);
        }
        lcrt_terminal_on_child_exited(NULL, lterminal);
        lcrt_terminal_set_status(lterminal, NULL, LCRT_TERMINAL_DISCONNECT);
    }
    if (tserial) {
        g_signal_handler_disconnect(lterminal->terminal, tserial->commit);
        gtk_input_remove(tserial->input);
        free(tserial);
        lterminal->private_data = NULL;
    }
    debug_where();
}
Exemplo n.º 9
0
Arquivo: serial.c Projeto: reyesr/lcrt
static void lcrt_serial_receive(struct lcrt_terminal *lterminal)
{
#if 0
    VteTerminal *vteterminal = lterminal->terminal;
    struct lcrt_window *lwindow = lterminal->parent->parent;
    struct lcrtc_user *user = lterminal->user;
#endif
    debug_where();
    lcrt_terminal_set_connected_status(lterminal);
}
Exemplo n.º 10
0
/*
 * do_config : do the config work after read config file or
 * do the default config
 *
 * do_config(struct server_env *server_env)
 * @ *server_env : the point of server_env that used in all files
 *
 * return : 0 is ok ,-1 is error
 *
 */
int do_config(struct server_env *s_env)
{
	int ret=0;
	char *tmp = NULL;
	struct stat statbuf;
	s_env->port = 0;
	s_env->set_mod = 0;
	s_env->start_time = 0;
	s_env->connection_timeout = 0;
	s_env->max_connect = 0;
	memset(s_env->version, '\0', sizeof(s_env->version));
	memset(s_env->name, '\0', sizeof(s_env->name));
	memset(s_env->index, '\0', sizeof(s_env->index));
	memset(s_env->author, '\0', sizeof(s_env->author));
	memset(s_env->log_file, '\0', sizeof(s_env->log_file));
	memset(s_env->root_dir, '\0', sizeof(s_env->root_dir));

	tmp = (char *)XHTTPD_NAME;
	strncpy(s_env->name, tmp, strlen(tmp));
	tmp = (char *)XHTTPD_VERSION;
	strncpy(s_env->version, tmp, strlen(tmp));
	tmp = (char *)XHTTPD_AUTHOR;
	strncpy(s_env->author, tmp, strlen(tmp));
	
        if (uname(&s_env->host_info) == -1) {
		debug_print("can't get host info\n");
                return -1;
	}
	if(stat(CONFIG_FILE,&statbuf) == 0) {
		debug_where();
		ret = read_config(s_env);
		if(ret < 0)
			do_default_config(s_env);
	} else {
		debug_where();
		do_default_config(s_env);
	}
	
	check_config(s_env);
	return 0;
}
Exemplo n.º 11
0
Arquivo: cedit.c Projeto: reyesr/lcrt
void lcrt_edit_on_copy_and_paste_activate(GtkMenuItem *menuitem, gpointer user_data)
{
    struct lcrt_window *lwindow = (struct lcrt_window *)user_data;
    struct lcrt_terminal *lterminal = lwindow->w_notebook->current_terminal;

    if (lterminal == NULL)
        return;

    debug_where();
    vte_terminal_copy_clipboard(lterminal->terminal);
    vte_terminal_paste_clipboard(lterminal->terminal);
}
Exemplo n.º 12
0
gboolean lcrt_terminal_on_key_press_event(GtkWidget*widget,
            GdkEventKey *event, gpointer user_data)
{
    struct lcrt_terminal *lterminal = (struct lcrt_terminal *)user_data;
    debug_where();
    if (event->type == GDK_KEY_PRESS && event->keyval == GDK_Return) {
        debug_print("reconnect...\n");
        if (lterminal->ops && lterminal->ops->connect)
            lterminal->ops->connect(lterminal);
    }
    return FALSE;
}
Exemplo n.º 13
0
Arquivo: cedit.c Projeto: reyesr/lcrt
void lcrt_edit_on_paste_activate(GtkMenuItem *menuitem, gpointer user_data)
{
    struct lcrt_window *lwindow = (struct lcrt_window *)user_data;
    struct lcrt_terminal *lterminal = lwindow->w_notebook->current_terminal;

    debug_where();
    if (lterminal == NULL || lterminal->connected != LCRT_TERMINAL_CONNECTED)
        return;

    debug_print("current_terminal = %p\n", lterminal);
    vte_terminal_paste_clipboard(lterminal->terminal);
}
Exemplo n.º 14
0
void lcrt_terminal_on_child_exited(VteTerminal *vteterminal, gpointer user_data)
{
    debug_where();
    struct lcrt_terminal *lterminal = (struct lcrt_terminal *)user_data;
    debug_where();

    if (lterminal->connected != LCRT_TERMINAL_CONNECTED)
        return;
    lterminal->child_pid = 0;
    debug_where();
    lcrt_terminal_set_status(lterminal, NULL, LCRT_TERMINAL_CHILD_EXIT);
    g_signal_connect ((gpointer) lterminal->terminal, "key-press-event",
                       G_CALLBACK (lcrt_terminal_on_key_press_event),
                       lterminal);
    debug_where();
    gtk_window_set_focus(GTK_WINDOW(lterminal->parent->parent->window), 
                     GTK_WIDGET(lterminal->terminal));
    debug_where();
    lterminal->signal_connected = TRUE;
    debug_print("child exit\n");
}
Exemplo n.º 15
0
boolean asprocess_trans_set_protocol(struct asprocess_trans *astrans, 
					protocol_sthread protocol)
{
	LINUXARMS_POINTER(astrans);
	if (!PROTOCOL_IS_STHREAD(protocol)) {
		debug_where();
		print_error(EWARNING, "无效的协议");
		astrans->protocol = SMAX;
		return FALSE;
	}
	astrans->protocol = protocol;
	return TRUE;
}
Exemplo n.º 16
0
gboolean lcrt_terminal_on_label_title_button_press_event(GtkWidget *widget,
            GdkEventButton  *event, gpointer user_data)
{
    struct lcrt_terminal *lterminal = (struct lcrt_terminal *)user_data;
    debug_where();
    if (event->type == GDK_BUTTON_PRESS && event->button == BUTTON_RIGHT) {
        struct lcrt_popup *lpopup = lcrt_create_popup_menu(lterminal);
		gtk_menu_popup (GTK_MENU(lpopup->popup_menu),
			     NULL, NULL, NULL, NULL,
			     event->button, event->time);
        debug_print("Create popup menu\n");
    }
    return FALSE;
}
Exemplo n.º 17
0
void lcrt_terminal_on_contents_changed(VteTerminal *vteterminal, gpointer user_data)
{
    debug_where();
    struct lcrt_terminal *lterminal = (struct lcrt_terminal *)user_data;
    struct lcrtc_user *user = lterminal->user;
    lcrt_protocol_t protocol = user->protocol;

    if (lterminal->connected == TRUE)
        return;
    lcrtc_user_dump(user, __func__);
    if (lterminal->ops && lterminal->ops->receive) 
        lterminal->ops->receive(lterminal);

}
Exemplo n.º 18
0
/*
 * 进程信息显示主调模块
 */
boolean do_show_asprocess(struct asthread_struct *asthread)
{
	/*
	 * 调用其他模块完成读取进程信息,发送进程信息,
	 * 接收反馈信息等。
	 */
	struct asprocess_struct *asprocess = asthread->asprocess;
	struct dirent *ent;
	DIR *dir;
	dir = opendir("/proc");
	debug_where();
	while ((ent = readdir(dir))) {
		if (asthread->proc.state == STOP)
			goto out;
		if(*ent->d_name < '0' || *ent->d_name > '9') 
			continue;
		if (!asprocess_read_info(asprocess, atoi(ent->d_name)))
			continue;
		asprocess->set_protocol(asprocess, SPROCESS);
		asprocess->send(asprocess);
		debug_print("%s\t%d\t%s\t%c\t%f\t%f\n", asprocess->trans.name, 
				asprocess->trans.pid, asprocess->trans.user,
				asprocess->trans.state, asprocess->trans.cpu,
				asprocess->trans.mem);
		/* 接收反馈信息,如果没有成功接收,则不再发送 */
		/*asprocess->recv(asprocess);
		if (asprocess->trans.protocol != SRECVSUC)
			break;
		*/
	}
out:
	closedir(dir);
	debug_where();
	asprocess->set_protocol(asprocess, SSENDALL);
	asprocess->send(asprocess);
	return TRUE;
}
Exemplo n.º 19
0
void lcrt_terminal_on_button_close_clicked(GtkButton *button, gpointer user_data)
{
    debug_where();
    struct lcrt_terminal *lterminal = (struct lcrt_terminal *)user_data;
    int rv = TRUE;

    if (lterminal->user->protocol != LCRT_PROTOCOL_SHELL && lterminal->connected == LCRT_TERMINAL_CONNECTED) {
        rv = lcrt_message_choose(lterminal->parent->parent->window,
                             GTK_MESSAGE_WARNING,
                             lterminal->parent->parent->w_status->config.value[LCRT_S_SESSION_DISCONNECT],
                             lterminal->user->hostname);
    }
    if (rv == TRUE)
        lcrt_destroy_terminal(lterminal);
}
Exemplo n.º 20
0
Arquivo: serial.c Projeto: reyesr/lcrt
/**
 * @brief the callback to read data from serial port and put the data to terminal.
 * @param user_data we use it to point to struct lcrt_terminal.
 * @param fd file descriptor of serial port.
 * @condition
 */
static void lcrt_serial_read(gpointer user_data, gint fd, GdkInputCondition condition)
{
    struct lcrt_terminal *lterminal = (struct lcrt_terminal *)user_data;
    int len = 0;
    unsigned char buffer[1024] = {0};    
    debug_where();
    len = read(fd, buffer, 1024);
    if (len <= 0) {
        /** serial device may be pull out  */
        if (errno == EAGAIN) {
            lcrt_serial_disconnect(lterminal);
            return;
        }
        return ;
    }
    vte_terminal_feed(VTE_TERMINAL(lterminal->terminal), (const char *)buffer, len);
}
Exemplo n.º 21
0
Arquivo: serial.c Projeto: reyesr/lcrt
static int lcrt_serial_connect(struct lcrt_terminal *lterminal)
{
    struct lcrtc_user *user;
    struct lcrt_serial_tm *tserial;
    /* port baud_rate databit parity stopbit software_control hardware_control*/
    char s_port[USERNAME_LEN];
    int s_baud_rate,s_databit,s_parity,s_stopbit,s_software,s_hardware;
    debug_where();
    if (lterminal == NULL)
       return -EINVAL;

    tserial = (struct lcrt_serial_tm *)calloc(1, sizeof(struct lcrt_serial_tm));
    if (tserial == NULL)
        return -ENOMEM;

    user = lterminal->user;
    sscanf(user->password, "%s %d %d %d %d %d %d", 
            s_port,
            &s_baud_rate,
            &s_databit,
            &s_parity,
            &s_stopbit,
            &s_software,
            &s_hardware);
    int fd ;
    fd = lcrt_serial_config(s_port, s_baud_rate,s_databit,
                            s_parity,s_stopbit,s_software,s_hardware);
    if (fd <= 0) {
        lcrt_message_error(lterminal->parent->parent->window, 
                lterminal->parent->config.value[LCRT_TM_SERIAL_ERROR], s_port, strerror(-fd));
        free(tserial);
        return fd;
    }
    tserial->fd = fd;
    lterminal->private_data = tserial;
    tserial->input = gtk_input_add_full(fd, GDK_INPUT_READ, 
            (GdkInputFunction)lcrt_serial_read, NULL, lterminal, NULL);
    tserial->commit = g_signal_connect(lterminal->terminal, "commit", 
                     G_CALLBACK(lcrt_serial_write), lterminal);
    lcrt_statusbar_set_user(lterminal->parent->parent->w_statusbar, lterminal->user);
    lcrt_terminal_set_connected_status(lterminal);
    return LCRTE_OK;
}
Exemplo n.º 22
0
gboolean lcrt_terminal_on_button_press_event(GtkWidget *widget,
            GdkEventButton  *event, gpointer user_data)
{
    struct lcrt_terminal *lterminal = (struct lcrt_terminal *)user_data;
    debug_where();
    if (event->type == GDK_BUTTON_PRESS && event->button == BUTTON_RIGHT && 
        lterminal->connected == LCRT_TERMINAL_CONNECTED) {
        struct lcrt_edit *ledit = lcrt_edit_create_menuitem(lterminal->parent->parent->w_menubar, TRUE);
        g_signal_connect ((gpointer) ledit->e_menuitem, "deactivate",
                    G_CALLBACK(lcrt_edit_on_popup_menu_deactivate),
                    ledit);
		gtk_menu_popup (GTK_MENU(ledit->e_menuitem),
			     NULL, NULL, NULL, NULL,
			     event->button, event->time);

        debug_print("Create popup menu for terminal = %p\n", ledit);

    }
    return FALSE;
}
Exemplo n.º 23
0
/*
 * 初始化文件浏览和文件传输控制主数据结构
 */
boolean afthread_init(struct afthread_struct *afthread,
                      struct afview_struct *afview,
                      struct atthread_struct *atthread)
{
	            
        if (!afthread || !afview || !atthread) {
		debug_where();
                print_error(ESYSERR,"错误");
                return FALSE;
        }   
	linuxarms_thread_init(&afthread->thread);
	afthread->afview = afview;
	afthread->atthread = atthread;
	afthread->permit = FALSE;
	
	afthread->set_protocol = afthread_set_protocol;
        afthread->send = afthread_send;
	afthread->recv = afthread_recv;
	afthread_trans_init(&afthread->trans);
	anet_init(&afthread->socket, get_localhost_ip(), get_armserver_port());
	return TRUE;

}
Exemplo n.º 24
0
void lcrt_terminal_set_connected_status(struct lcrt_terminal *lterminal)
{
    struct lcrt_window *lwindow = lterminal->parent->parent;
    debug_print("Login success\n");
    lterminal->connected =TRUE;
    debug_where();
    lcrt_terminal_set_status(lterminal, NULL, LCRT_TERMINAL_CONNECTED);
    if (lterminal->signal_connected) {
        gtk_signal_disconnect_by_func(GTK_OBJECT(lterminal->terminal),
                                      G_CALLBACK(lcrt_terminal_on_key_press_event),
                                      lterminal);
        lterminal->signal_connected = FALSE;
    }
    gtk_window_set_focus(GTK_WINDOW(lwindow->window),
             GTK_WIDGET(lterminal->terminal));
    if (lterminal->save_passwd) {
        lcrt_user_save_one(&lwindow->u_config, lwindow->current_user);
    }
    if (strlen(lterminal->user->command) != 0) {
        vte_terminal_feed_child(lterminal->terminal, lterminal->user->command, strlen(lterminal->user->command));
        vte_terminal_feed_child(lterminal->terminal, "\n", 1);
    }
}
Exemplo n.º 25
0
/*
 * 读取配置文件所在路径,如果正确读取,则返回TRUE
 */
static boolean login_config_set_path(struct login_config_struct *config)
{
	char *p;

	debug_where();
	login_config_error(config);

	p = get_user_home();
	if (!p) {
		print_error(ESYSERR, "读取环境变量错误");
		config->inited = FALSE;
		return FALSE;
	}
	if (!login_config_create()) {
		config->inited = FALSE;
		return TRUE;
	}
	snprintf(config->path, CONFIG_FILE_PATH_LEN, 
		 "%s/."USER_CONFIG_DIR_NAME"/config", p);
	add_file_directory(config->path);
	config->inited = TRUE;
	return TRUE;
}
Exemplo n.º 26
0
Arquivo: cedit.c Projeto: reyesr/lcrt
void lcrt_edit_on_menuitem_activate(GtkMenuItem *menuitem, gpointer user_data)
{
    struct lcrt_window *lwindow = (struct lcrt_window *)user_data;
    struct lcrt_edit *ledit = lwindow->w_menubar->m_edit;
    struct lcrt_terminal *lterminal = lwindow->w_notebook->current_terminal;
    gboolean has_selection, has_terminal;

    has_selection = lcrt_terminal_has_selection(lwindow);
    has_terminal = (lterminal != NULL);
    debug_where();

    gtk_widget_set_sensitive (ledit->e_copy, has_selection);
    gtk_widget_set_sensitive (ledit->e_paste, 
            has_terminal && lterminal->connected == LCRT_TERMINAL_CONNECTED);
    gtk_widget_set_sensitive (ledit->e_copy_and_paste, has_selection);
    
    gtk_widget_set_sensitive (ledit->e_find, has_terminal);

    gtk_widget_set_sensitive (ledit->e_select_all, has_terminal);
    gtk_widget_set_sensitive (ledit->e_clear_scrollback, has_terminal);
    gtk_widget_set_sensitive (ledit->e_clear_screen, has_terminal);
    gtk_widget_set_sensitive (ledit->e_clear_screen_and_scrollback, has_terminal);
    gtk_widget_set_sensitive (ledit->e_reset, has_terminal);
}
Exemplo n.º 27
0
/*
 * 写配置文件
 */
boolean login_config_write(struct login_struct *login)
{
	struct login_config_struct *config = &login->config;
	struct user_struct *suser = &login->user;
	FILE *fp;
	char *config_file;
	int i, ret;
	struct list_ip *ip;
	struct list_user *user;
	
	debug_where();
	config_file = find_file("user.conf");
	debug_print("配置文件:%s\n",config_file);
	if (!config_file) {
		print_error(ESYSERR, "没有配置文件");
		return FALSE;
	}
	if ((fp = fopen(config_file, "w")) == NULL) {
		print_error(ESYSERR, "打开配置文件错误");
		return FALSE;
	}
	debug_where();
	ip = config->ip_list.next;
	for (i = 0;i < config->ip_num; i++) {
		if (strcmp(ip->ip, suser->ip) == 0) 
			break;
		ip = ip->next;
	}
	if (i == config->ip_num) {
		ret = fprintf(fp, "SERVERIP %d\n",config->ip_num + 1);
		ret = fprintf(fp, "%s\n",suser->ip);
	} else
		ret = fprintf(fp, "SERVERIP %d\n",config->ip_num);
	debug_where();
	debug_print("i = %d  %d\n", i ,config->ip_num);
	ip = config->ip_list.next;
	for (i = 0; i < config->ip_num; i++) {
		ret = fprintf(fp, "%s\n",ip->ip);
		ip = ip->next;
	}
	debug_where();
	user = config->user_list.next;
	for (i = 0; i < config->user_num; i++) {
		if (strcmp(user->user_name, suser->name) == 0)
			break;
		user = user->next;
	}
	if (i == config->user_num) {
		ret = fprintf(fp, "USER %d\n",config->user_num + 1);
		ret = fprintf(fp, "%s %d ",suser->name, login->remember);
		if (login->remember)
			ret = fprintf(fp, "%s\n",suser->passwd);
		else
			ret = fprintf(fp, "\n");
	} else {
		ret = fprintf(fp, "USER %d\n",config->user_num);
		user->remember = login->remember;
	}
	user = config->user_list.next;
	for (i = 0; i < config->user_num; i++) {
		ret = fprintf(fp, "%s %d",user->user_name, user->remember);
		if (user->remember) 
			ret = fprintf(fp, " %s\n",user->passwd);
		else
			ret = fprintf(fp, "\n");
		user = user->next;
	}

	fclose(fp);
	debug_where();
	return TRUE;
}
Exemplo n.º 28
0
Arquivo: serial.c Projeto: reyesr/lcrt
static struct lcrtc_user *lcrt_serial_create(struct lcrt_qconnect *lqconnect)
{
    lcrt_protocol_t protocol = lqconnect->nproto;
    struct lcrt_window *lwindow = lqconnect->parent;
    struct lcrt_serial_if *lserial = (struct lcrt_serial_if *)lqconnect->private_data;
    struct lcrt_serial_map serial_buad_rate[] = {LCRT_SERIAL_BAUD_RATE_TABLE};
    struct lcrt_serial_map serial_databit[] = {LCRT_SERIAL_DATA_BITS_TABLE};
    struct lcrtc_user *user;
    char password[PASSWORD_LEN];
    char s_port[USERNAME_LEN];
    char name[HOSTNAME_LEN];
    char hostname[HOSTNAME_LEN];
#define get_text(widget) (gtk_combo_box_get_active_text(GTK_COMBO_BOX(lserial->widget)))
#define get_active(widget) (gtk_combo_box_get_active(GTK_COMBO_BOX(lserial->widget)))
    snprintf(s_port, USERNAME_LEN, "%s", get_text(port));
    debug_where();
    if (access(s_port, F_OK|R_OK|W_OK) == -1) {
        switch (errno) {
        case ENOENT:
            debug_print("device %s is not exist.\n", s_port);
            break;
        case EPERM:
            debug_print("you have no permition to open %s.\n", s_port);
            break;
        case EIO:
            debug_print("device %s is not ready.\n", s_port);
            break;
        default:
            debug_print("unknown error,error code is %d\n", errno);
            break;
        }
        return NULL;
    }
    int baud_rate,s_baud_rate;
    baud_rate = get_active(baud_rate);
    s_baud_rate = serial_buad_rate[baud_rate].data;
    debug_where();

    int databit, s_databit;
    databit = atoi(get_text(data_bits));
    databit = get_active(data_bits);
    s_databit = serial_databit[databit].data;
    debug_where();
    
    int s_parity;
    s_parity = get_active(parity);
    debug_where();

    int s_stopbits;
    s_stopbits = get_active(stop_bits);
    debug_where();

    int s_software, s_hardware;
    s_software = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lserial->software));
    s_hardware = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lserial->hardware));
    /* port baud_rate databit parity stopbit software_control hardware_control*/
    snprintf(password, PASSWORD_LEN, "%s %d %d %d %d %d %d", 
            s_port,
            s_baud_rate,
            s_databit,
            s_parity,
            s_stopbits,
            s_software,
            s_hardware);
    strcpy(hostname, basename(s_port));
    if (lqconnect->flag != LCRT_QCONNECT_SESSION_OPTION) {
        if ((user = lcrtc_user_create()) == NULL) {
            /* 
             * FIXME: There is no more memory, how can 
             * we handle this exception ?
             */
            return NULL;
        }

        lcrt_user_find_unused_label(lwindow, hostname, name);

        lcrtc_user_set_data(
           user,
           name,
           hostname,
           protocol,
           NULL,
           password,
           gtk_entry_get_text(GTK_ENTRY(lqconnect->q_et_default_command)),
           0,
           TRUE,
           lqconnect->folder,
           0
        );
        lcrtc_user_ref(user);
        lcrt_user_add(&lwindow->u_config, user);
        lcrt_window_set_current_user(lwindow, user);
        if (lqconnect->flag == LCRT_QCONNECT_IN_TAB) {
            lcrt_create_terminal(lwindow->w_notebook);
        }
    } else {
        if ((user = lcrt_user_find_by_name(&lwindow->u_config, lqconnect->uname)) != NULL) {
            lcrtc_user_set_data(
               user,
               lqconnect->uname,
               hostname,
               protocol,
               NULL,
               password,
               gtk_entry_get_text(GTK_ENTRY(lqconnect->q_et_default_command)),
               0,
               TRUE,
               NULL,
               -1
            );
        }
    }
    lcrtc_user_dump(user, __func__);
    return user;
#undef get_text
#undef get_active
}
Exemplo n.º 29
0
Arquivo: serial.c Projeto: reyesr/lcrt
static void lcrt_serial_show(struct lcrt_qconnect *lqconnect)
{
    GtkWidget *vbox;
    GtkWidget *vbox_spec;
    GtkWidget *hbox1;
    GtkWidget *label_port;
    GtkWidget *combobox_port;
    GtkWidget *label_baud_rate;
    GtkWidget *combobox_baud_rate;
    GtkWidget *label_data_bits;
    GtkWidget *combobox_data_bits;
    GtkWidget *label_parity;
    GtkWidget *combobox_parity;
    GtkWidget *label_stop_bits;
    GtkWidget *combobox_stop_bits;
    GtkWidget *frame;
    GtkWidget *alignment;
    GtkWidget *hbox_frame;
    GtkWidget *checkbutton_software;
    GtkWidget *checkbutton_hardware;
    GtkWidget *label_flow_control;
    int i;
    const char *sport[LCRT_SERIAL_PORT_NUMBER] = {LCRT_SERIAL_PORT};
    const struct lcrt_serial_map sbaud_rate[LCRT_SERIAL_BAUD_RATE_NUMBER] = {LCRT_SERIAL_BAUD_RATE_TABLE};
    const struct lcrt_serial_map sdata_bits[LCRT_SERIAL_DATA_BITS_NUMBER] = {LCRT_SERIAL_DATA_BITS_TABLE};
    const struct lcrt_serial_map sparity[LCRT_SERIAL_PARITY_NUMBER] = {LCRT_SERIAL_PARITY_TABLE};
    const struct lcrt_serial_map sstop_bits[LCRT_SERIAL_STOP_BITS_NUMBER] = {LCRT_SERIAL_STOP_BITS_TABLE};
    const struct lcrt_serial_map flow_control[LCRT_SEROAL_FLOW_CONTROL_NUMBER] = {LCRT_SEROAL_FLOW_CONTROL_TABLE};
    static struct lcrt_serial_if slserial, *lserial = &slserial;
    struct lcrtc_user *user = NULL;
    char s_port[USERNAME_LEN];
    boolean f_option = FALSE;
    int s_baud_rate,s_databit,s_parity,s_stopbit,s_software,s_hardware;
    if (lqconnect->flag == LCRT_QCONNECT_SESSION_OPTION &&
        (user = lcrt_user_find_by_name(&lqconnect->parent->u_config, lqconnect->uname)) != NULL) {
        sscanf(user->password, "%s %d %d %d %d %d %d", 
                s_port,
                &s_baud_rate,
                &s_databit,
                &s_parity,
                &s_stopbit,
                &s_software,
                &s_hardware);
        debug_print("SERIAL PORT: %s %d %d %d %d %d %d\n", 
                s_port,
                s_baud_rate,
                s_databit,
                s_parity,
                s_stopbit,
                s_software,
                s_hardware);

        f_option = TRUE;
    }

    memset(lserial, 0, sizeof(struct lcrt_serial_if));
    lqconnect->private_data = lserial;

    vbox = GTK_DIALOG (lqconnect->q_connect)->vbox;
    debug_where();
    vbox_spec = gtk_vbox_new (FALSE, 0);
    lqconnect->q_vbox_spec = vbox_spec;
    gtk_widget_show (vbox_spec);
    gtk_box_pack_start (GTK_BOX (vbox), vbox_spec, TRUE, TRUE, 0);
    gtk_box_reorder_child (GTK_BOX (vbox), vbox_spec, 1);
    gtk_widget_set_size_request (vbox_spec, -1, 210);

    hbox1 = gtk_hbox_new (FALSE, 0);
    gtk_widget_show (hbox1);
    gtk_box_pack_start (GTK_BOX (vbox_spec), hbox1, TRUE, TRUE, 0);
    gtk_widget_set_size_request (hbox1, -1, 25);

    label_port = gtk_label_new (lqconnect->config.value[LCRT_Q_SPORT]);
    gtk_widget_show (label_port);
    gtk_box_pack_start (GTK_BOX (hbox1), label_port, FALSE, FALSE, 0);
    gtk_widget_set_size_request (label_port, 90, 25);
    gtk_misc_set_alignment (GTK_MISC (label_port), 0, 0.5);

    combobox_port = gtk_combo_box_entry_new_text ();
    lserial->port = combobox_port;
    gtk_widget_show (combobox_port);
    gtk_box_pack_start (GTK_BOX (hbox1), combobox_port, FALSE, TRUE, 0);
    gtk_widget_set_size_request (combobox_port, SERIAL_COMBOBOX_WIDTH, 25);
    
    for (i = 0; i < LCRT_SERIAL_PORT_NUMBER; i++) {
        gtk_combo_box_append_text (GTK_COMBO_BOX (combobox_port), sport[i]);
        if (f_option && strcmp(s_port, sport[i]) == 0)
            gtk_combo_box_set_active(GTK_COMBO_BOX(combobox_port), i);

    }
    debug_where();
    //gtk_entry_set_editable(GTK_ENTRY(GTK_BIN(combobox_port)->child), FALSE);

    hbox1 = gtk_hbox_new (FALSE, 0);
    gtk_widget_show (hbox1);
    gtk_box_pack_start (GTK_BOX (vbox_spec), hbox1, TRUE, TRUE, 0);
    gtk_widget_set_size_request (hbox1, -1, 25);

    label_baud_rate = gtk_label_new (lqconnect->config.value[LCRT_Q_SBAUD_RATE]);
    gtk_widget_show (label_baud_rate);
    gtk_box_pack_start (GTK_BOX (hbox1), label_baud_rate, FALSE, FALSE, 0);
    gtk_widget_set_size_request (label_baud_rate, 90, 25);
    gtk_misc_set_alignment (GTK_MISC (label_baud_rate), 0, 0.5);

    combobox_baud_rate = gtk_combo_box_entry_new_text ();
    lserial->baud_rate = combobox_baud_rate;
    gtk_widget_show (combobox_baud_rate);
    gtk_box_pack_start (GTK_BOX (hbox1), combobox_baud_rate, FALSE, TRUE, 0);
    gtk_widget_set_size_request (combobox_baud_rate, SERIAL_COMBOBOX_WIDTH, 25);
    
    for (i = 0; i < LCRT_SERIAL_BAUD_RATE_NUMBER; i++) {
        gtk_combo_box_append_text (GTK_COMBO_BOX (combobox_baud_rate), sbaud_rate[i].name);
        if (f_option && s_baud_rate == sbaud_rate[i].data)
            gtk_combo_box_set_active(GTK_COMBO_BOX(combobox_baud_rate), i);
    }
    debug_where();
    gtk_entry_set_editable(GTK_ENTRY(GTK_BIN(combobox_baud_rate)->child), FALSE);

    hbox1 = gtk_hbox_new (FALSE, 0);
    gtk_widget_show (hbox1);
    gtk_box_pack_start (GTK_BOX (vbox_spec), hbox1, TRUE, TRUE, 0);
    gtk_widget_set_size_request (hbox1, -1, 25);

    label_data_bits = gtk_label_new (lqconnect->config.value[LCRT_Q_SDATA_BITS]);
    gtk_widget_show (label_data_bits);
    gtk_box_pack_start (GTK_BOX (hbox1), label_data_bits, FALSE, FALSE, 0);
    gtk_widget_set_size_request (label_data_bits, 90, 25);
    gtk_misc_set_alignment (GTK_MISC (label_data_bits), 0, 0.5);

    combobox_data_bits = gtk_combo_box_entry_new_text ();
    lserial->data_bits = combobox_data_bits;
    gtk_widget_show (combobox_data_bits);
    gtk_box_pack_start (GTK_BOX (hbox1), combobox_data_bits, FALSE, TRUE, 0);
    gtk_widget_set_size_request (combobox_data_bits, SERIAL_COMBOBOX_WIDTH, 25);
    
    for (i = 0; i < LCRT_SERIAL_DATA_BITS_NUMBER; i++) {
        gtk_combo_box_append_text (GTK_COMBO_BOX (combobox_data_bits), sdata_bits[i].name);
        if (f_option && s_databit == sdata_bits[i].data)
            gtk_combo_box_set_active(GTK_COMBO_BOX(combobox_data_bits), i);
    }
    debug_where();
    gtk_entry_set_editable(GTK_ENTRY(GTK_BIN(combobox_data_bits)->child), FALSE);

    hbox1 = gtk_hbox_new (FALSE, 0);
    gtk_widget_show (hbox1);
    gtk_box_pack_start (GTK_BOX (vbox_spec), hbox1, TRUE, TRUE, 0);
    gtk_widget_set_size_request (hbox1, -1, 25);

    label_parity = gtk_label_new (lqconnect->config.value[LCRT_Q_SPARITY]);
    gtk_widget_show (label_parity);
    gtk_box_pack_start (GTK_BOX (hbox1), label_parity, FALSE, FALSE, 0);
    gtk_widget_set_size_request (label_parity, 90, 25);
    gtk_misc_set_alignment (GTK_MISC (label_parity), 0, 0.5);

    combobox_parity = gtk_combo_box_entry_new_text ();
    lserial->parity = combobox_parity;
    gtk_widget_show (combobox_parity);
    gtk_box_pack_start (GTK_BOX (hbox1), combobox_parity, FALSE, TRUE, 0);
    gtk_widget_set_size_request (combobox_parity, SERIAL_COMBOBOX_WIDTH, 25);
    
    for (i = 0; i < LCRT_SERIAL_PARITY_NUMBER; i++) {
        gtk_combo_box_append_text (GTK_COMBO_BOX (combobox_parity), sparity[i].name);
    }
    if (f_option)
        gtk_combo_box_set_active(GTK_COMBO_BOX(combobox_parity), s_parity);
    debug_where();
    gtk_entry_set_editable(GTK_ENTRY(GTK_BIN(combobox_parity)->child), FALSE);

    hbox1 = gtk_hbox_new (FALSE, 0);
    gtk_widget_show (hbox1);
    gtk_box_pack_start (GTK_BOX (vbox_spec), hbox1, TRUE, TRUE, 0);
    gtk_widget_set_size_request (hbox1, -1, 25);

    label_stop_bits = gtk_label_new (lqconnect->config.value[LCRT_Q_SSTOP_BITS]);
    gtk_widget_show (label_stop_bits);
    gtk_box_pack_start (GTK_BOX (hbox1), label_stop_bits, FALSE, FALSE, 0);
    gtk_widget_set_size_request (label_stop_bits, 90, 25);
    gtk_misc_set_alignment (GTK_MISC (label_stop_bits), 0, 0.5);

    combobox_stop_bits = gtk_combo_box_entry_new_text ();
    lserial->stop_bits = combobox_stop_bits;
    gtk_widget_show (combobox_stop_bits);
    gtk_box_pack_start (GTK_BOX (hbox1), combobox_stop_bits, FALSE, TRUE, 0);
    gtk_widget_set_size_request (combobox_stop_bits, SERIAL_COMBOBOX_WIDTH, 25);
    
    for (i = 0; i < LCRT_SERIAL_STOP_BITS_NUMBER; i++) {
        gtk_combo_box_append_text (GTK_COMBO_BOX (combobox_stop_bits), sstop_bits[i].name);
    }
    if (f_option)
        gtk_combo_box_set_active(GTK_COMBO_BOX(combobox_stop_bits), s_stopbit);
    debug_where();
    gtk_entry_set_editable(GTK_ENTRY(GTK_BIN(combobox_stop_bits)->child), FALSE);

    frame = gtk_frame_new (NULL);
    gtk_widget_show (frame);
    gtk_widget_set_size_request (frame, -1, 40);
    gtk_box_pack_start (GTK_BOX (vbox_spec), frame, TRUE, TRUE, 0);
    gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_OUT);

    alignment = gtk_alignment_new (0.5, 0.5, 1, 1);
    gtk_widget_show (alignment);
    gtk_container_add (GTK_CONTAINER (frame), alignment);
    gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 0, 0, 12, 0);

    hbox_frame = gtk_hbox_new (FALSE, 0);
    gtk_widget_show (hbox_frame);
    gtk_container_add (GTK_CONTAINER (alignment), hbox_frame);

    checkbutton_software = gtk_check_button_new_with_mnemonic (flow_control[0].name);
    lserial->software = checkbutton_software;
    gtk_widget_show (checkbutton_software);
    gtk_box_pack_start (GTK_BOX (hbox_frame), checkbutton_software, FALSE, FALSE, 0);
    gtk_widget_set_size_request (checkbutton_software, 150, -1);

    if (f_option)
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbutton_software), s_software);

    checkbutton_hardware = gtk_check_button_new_with_mnemonic (flow_control[1].name);
    lserial->hardware = checkbutton_hardware;
    gtk_widget_show (checkbutton_hardware);
    gtk_box_pack_start (GTK_BOX (hbox_frame), checkbutton_hardware, FALSE, FALSE, 0);
    gtk_widget_set_size_request (checkbutton_hardware, 150, -1);

    if (f_option)
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbutton_hardware), s_hardware);

    label_flow_control = gtk_label_new (lqconnect->config.value[LCRT_Q_SFLOW_CONTROL]);
    gtk_widget_show (label_flow_control);
    gtk_frame_set_label_widget (GTK_FRAME (frame), label_flow_control);
    gtk_label_set_use_markup (GTK_LABEL (label_flow_control), TRUE);

    if (!f_option) {
        gtk_combo_box_set_active(GTK_COMBO_BOX(combobox_port), 1); //ttyS0
        gtk_combo_box_set_active(GTK_COMBO_BOX(combobox_baud_rate), 10); //115200
        gtk_combo_box_set_active(GTK_COMBO_BOX(combobox_data_bits), 3); //8
        gtk_combo_box_set_active(GTK_COMBO_BOX(combobox_parity), 0); //None
        gtk_combo_box_set_active(GTK_COMBO_BOX(combobox_stop_bits), 0); //1
        debug_print("active = %d\n", gtk_combo_box_get_active(GTK_COMBO_BOX(combobox_baud_rate)));
    }
    gtk_widget_set_sensitive(lqconnect->q_bt_connect, TRUE);

}
Exemplo n.º 30
0
void lcrt_terminal_on_emulation_changed(VteTerminal *vteterminal, gpointer user_data)
{
    debug_print("emulation_changed\n");
    debug_where();
}