int login()//return 1 success
{
	USER usr;
	int i=usr.userid;

	printf("a login request\n");

	c_lseek(user_list_fd,i*USR_LEN,SEEK_SET);
	c_read(user_list_fd,&usr,USR_LEN);
	int check;
	check= strcmp(usr.password,user_temp_p.password);
	if(check==0)//验证成功,将status置为1,写回文件。可以考虑建一个在线用户的数据结构;
	{
		usr.status=1;
		c_lseek(user_list_fd,-USR_LEN,SEEK_CUR);
		c_write(user_list_fd,&usr,USR_LEN);
		c_send(sockfd,(USER*)usr,USR_LEN,0);
		return 1;
	}
	else
	{
		printf("user:%d login error\n",usr.userid);
		usr.status=0;
		c_send(sockfd,(USER*)usr,USR_LEN,0);
        return 0;
	}
	
}
Ejemplo n.º 2
0
int
send(long sd, const void *buf, long len, long flags)
{
    int ret;

    OS_mutex_lock(g_main_mutex, &mtx_key);
    ret = c_send(sd, buf, len, flags);
    OS_mutex_unlock(g_main_mutex, mtx_key);

    return(ret);
}
int chis_transations()
{
	int i=chis_temp_p.count;
	int max;
	CHIS chis;
	memset(&chis,0,HSTR_LEN);
	c_lseek(recordfd,-HSTR_LEN,SEEK_END);
	c_read(recordfd,&chis,HSTR_LEN);
	max=chis.count;//get the count of all the history msg
	//send the message from i to the latest msg to cli
	for(i++;i<=max;i++)
	{
		c_lseek(recordfd,HSTR_LEN*i,SEEK_SET);
		c_read(recordfd,&chis,HSTR_LEN);
		c_send(conn,&chis,HSTR_LEN,0);//send to conn,conn is the socket for r/w
	}
	return 0;
}