Esempio n. 1
0
int msg_analyse(int cnt_fd, const char * xml_msg, int msg_len)
{
	//char		n = 0;				//子节点计数器
	xmlDocPtr	xml_fd = NULL;		//xml描述符
	xmlNodePtr	xml_root = NULL,	//xml的root节点
				curNode = NULL;		//xml的子节点

	xmlKeepBlanksDefault(0);//忽视xml中的空格,避免读出node = text的空节点

	/*读取msg内容*/
	xml_fd = xmlParseMemory(xml_msg, msg_len);
	if(xml_fd == NULL)
	{
		printf("read file error\n");
		return ERRX_READ_FILE;
	}

	/*获取msg中的root元素*/
	xml_root = xmlDocGetRootElement(xml_fd);
	if(xml_root == NULL)
	{
		printf("get element error\n");
		return ERRX_GET_ELEMENT;
	}


	/* 匹配xml的根结点
	 *		login
	 *		signin
	 *		upload
	 *		download
	 * */
	if( !xmlStrcmp(xml_root->name, BAD_CAST "login") )
	{	//root == "login"
		printf("login user: %s\nlogin pwd: %s\n", 
					xmlNodeGetContent(xml_root->xmlChildrenNode), 
					xmlNodeGetContent(xml_root->xmlChildrenNode->next));
	}
	else if( !xmlStrcmp(xml_root->name, BAD_CAST "signin") )
	{	//root == "signin"
		//获取用户名和密码
		printf("signin user: %s\nsignin pwd: %s\n", 
					xmlNodeGetContent(xml_root->xmlChildrenNode), 
					xmlNodeGetContent(xml_root->xmlChildrenNode->next));
	}
	else if( !xmlStrcmp(xml_root->name, BAD_CAST "upload") )
	{	//root == "upload"
		recv_files(cnt_fd);
	}
	else if( !xmlStrcmp(xml_root->name, BAD_CAST "download") )
	{	//root == "download"
		//send_files();
	}
	else
	{	return ERRX_TAG_NOT_MATCH;}
	
	xmlFreeDoc(xml_fd);
	xmlCleanupParser();

	return 0;
}
Esempio n. 2
0
//process recv's command thread
int processer()
{
    command *current_com;
    unsigned int mode, opt;
    
    while (1) {
        sem_wait(&msg_empty);
        pthread_mutex_lock(&msg_lock);
        current_com = mlist.com_head;
        mlist.com_head = current_com->next;
        pthread_mutex_unlock(&msg_lock);

        if (current_com == NULL) {
            continue;
        }

        mode = GET_MODE(current_com->com_num);
        opt = GET_OPT(current_com->com_num);
        switch (mode) {
            case IPMSG_BR_ENTRY:
                send_recventry(current_com);
                pthread_mutex_lock(&user_lock);
                add_user(current_com);
                pthread_mutex_unlock(&user_lock);
                free(current_com);
                break;
            case IPMSG_BR_EXIT:
                pthread_mutex_lock(&user_lock);
                del_user(current_com);
                pthread_mutex_unlock(&user_lock);
                free(current_com);
                break;
            case IPMSG_ANSENTRY:
                pthread_mutex_lock(&user_lock);
                add_user(current_com);
                pthread_mutex_unlock(&user_lock);
                free(current_com);
                break;
            case IPMSG_SENDMSG:
                if (opt & IPMSG_SENDCHECKOPT) {
                    send_check(current_com);
                }
                if (opt & IPMSG_FILEATTACHOPT) {
                    printf("IN PRO SENDMSG: receive file.\n");
                    recv_files(current_com);
                }else {
                    putout_msg(current_com);
                    free(current_com);
                }
                break;
            case IPMSG_RECVMSG:
                free(current_com);
                break;
            case IPMSG_GETFILEDATA:
                free(current_com);
                break;
            case IPMSG_GETDIRFILES:
                free(current_com);
                break;
            case IPMSG_RELEASEFILES:
                free(current_com);
                break;
            default:
                free(current_com);
                break;
        }
    }

    return 0;
}
Esempio n. 3
0
File: main.c Progetto: OPSF/uClinux
static int do_recv(int f_in,int f_out,struct file_list *flist,char *local_name)
{
	int pid;
	int status = 0;
	int error_pipe[2];

	/* The receiving side mustn't obey this, or an existing symlink that
	 * points to an identical file won't be replaced by the referent. */
	copy_links = 0;

	if (preserve_hard_links)
		init_hard_links();

	if (fd_pair(error_pipe) < 0) {
		rsyserr(FERROR, errno, "pipe failed in do_recv");
		exit_cleanup(RERR_IPC);
	}

	io_flush(NORMAL_FLUSH);

	if ((pid = do_fork()) == -1) {
		rsyserr(FERROR, errno, "fork failed in do_recv");
		exit_cleanup(RERR_IPC);
	}

	if (pid == 0) {
		close(error_pipe[0]);
		if (f_in != f_out)
			close(f_out);

		/* we can't let two processes write to the socket at one time */
		close_multiplexing_out();

		/* set place to send errors */
		set_msg_fd_out(error_pipe[1]);

		recv_files(f_in, flist, local_name);
		io_flush(FULL_FLUSH);
		handle_stats(f_in);

		send_msg(MSG_DONE, "", 0);
		io_flush(FULL_FLUSH);

		/* Handle any keep-alive packets from the post-processing work
		 * that the generator does. */
		if (protocol_version >= 29) {
			kluge_around_eof = -1;

			/* This should only get stopped via a USR2 signal. */
			while (read_int(f_in) == flist->count
			    && read_shortint(f_in) == ITEM_IS_NEW) {}

			rprintf(FERROR, "Invalid packet at end of run [%s]\n",
				who_am_i());
			exit_cleanup(RERR_PROTOCOL);
		}

		/* Finally, we go to sleep until our parent kills us with a
		 * USR2 signal.  We sleep for a short time, as on some OSes
		 * a signal won't interrupt a sleep! */
		while (1)
			msleep(20);
	}

	am_generator = 1;
	close_multiplexing_in();
	if (write_batch && !am_server)
		stop_write_batch();

	close(error_pipe[1]);
	if (f_in != f_out)
		close(f_in);

	io_start_buffering_out();

	set_msg_fd_in(error_pipe[0]);

	generate_files(f_out, flist, local_name);

	handle_stats(-1);
	io_flush(FULL_FLUSH);
	if (protocol_version >= 24) {
		/* send a final goodbye message */
		write_int(f_out, -1);
	}
	io_flush(FULL_FLUSH);

	set_msg_fd_in(-1);
	kill(pid, SIGUSR2);
	wait_process(pid, &status);
	return status;
}