예제 #1
0
파일: users.c 프로젝트: holyhope/System
void delete_user(unsigned short ID){
	int num;

	if( -1 != (num=search_user(ID))){
		swap_user(&connected[num],&connected[numberOfUsers-1]);
		free_all_follow(&connected[numberOfUsers-1].following);
		free(connected[numberOfUsers-1].login);
		numberOfUsers--;
	} 
}
예제 #2
0
void search_user(xmlNode * a_node, char *login, char *password,char *id)
{
	xmlNode *cur_node = NULL;

	for (cur_node = a_node; cur_node; cur_node = cur_node->next) {
		if (cur_node->type == XML_ELEMENT_NODE) {
			if((!xmlStrcmp(cur_node->name,(const xmlChar *)"user")))
			{
				if((!xmlStrcmp(xmlGetProp(cur_node,"login"),(const xmlChar *)login)))
				{
					if((!xmlStrcmp(xmlGetProp(cur_node,"password"),(const xmlChar *)password)))
						if((!xmlStrcmp(xmlGetProp(cur_node,"stat"),(const xmlChar *)"ff")))
						{
							strcpy(id,xmlGetProp(cur_node,"id"));//strcpu
							return;
						}
				}
			}
	    }
	        search_user(cur_node->children,login,password,id);
	}
}
예제 #3
0
void login_func(int newsockfd,char * log)
{
	char login[256];
	char password[256];
	int n;
	char id[256];

	xmlDoc         *doc = NULL;
	xmlNode        *root_element = NULL;
	const char     *Filename = "users.xml";
	doc = xmlReadFile(Filename, NULL, 0);

	n = write(newsockfd,"Hello, print you login and password\n",36);
	bzero(login,256);
	bzero(password,256);
	n = read( newsockfd,login,255 );
	if (n < 0)
	{
		perror("ERROR reading from socket");
		exit(1);
	}
	n=write(newsockfd,"OK",2);
	n = read( newsockfd,password,255 );
	if (n < 0)
	{
		perror("ERROR reading from socket");
		exit(1);
	}

	if (doc == NULL)
	{
		printf("error: could not parse file %s\n", Filename);
	}
	else
	{
		if(!strncmp(login,"exit",4))
			exit(1);

		root_element = xmlDocGetRootElement(doc);
		bzero(id,256);
		login[strlen(login)-1] = 0;
		//login[strlen(login)-1] = 0;
		//password[strlen(password)-1] = 0;
		password[strlen(password)-1] = 0;
	    search_user(root_element,login,password,id);
	    if(id[0] == 0)
	    {
	    	printf("Invalid login --%s-- and password --%s-- \n Retry write you login and password\n",login,password);
	    	write(newsockfd,"OK",5);
	    	login_func(newsockfd,login);
	    }
	    else
	    {
	    	write(newsockfd,"next",5);
	    	search_new_topics(login,newsockfd);
	    	root_element = xmlDocGetRootElement(doc);
	    	on_off_user(root_element,login,1);
	    	xmlSaveFile(Filename,doc);
	    	strcpy(log,login);
	    	write(newsockfd,"next",5);
	    }

	    xmlFreeDoc(doc);
	}

	xmlCleanupParser();

	return;
}