Exemplo n.º 1
0
int main(int argc, char *argv[])
{
    int rval;

    pre_initialize();
    process_args(argc, argv);
    initialize();
    rval = send_files();
    return rval ? 0 : 1;
}
Exemplo n.º 2
0
// interacter thread
int interacter()
{
    char input;
    char tmp[100];
    
    printf(HELPINFO);

    while (1) {
        printf("ipmsg~> ");
/*        if (fflush(stdin) != 0) {
            gets(stdin);
        }
*/
        fgets(tmp, 100, stdin);
        input = *tmp;
        switch(input) {
            case 'h':
                printf(HELPINFO);
                break;
            case 'l':
                pthread_mutex_lock(&user_lock);
                list_users();
                pthread_mutex_unlock(&user_lock);
                break;
            case 'r':
                login();
                pthread_mutex_lock(&user_lock);
                list_users();
                pthread_mutex_unlock(&user_lock);
                break;
            case 't':
                talkto_user();
                break;
            case 's':
                send_files();
                break;
            case 'q':
                logout();
                printf("Bye!!!\n");
                exit(0);
            case 10:
                break;
            default:
                printf("Input error command, please input again.\n");
                break;
        }
    }

    return 0;
}
Exemplo n.º 3
0
static inline void send_code_files(int s, const struct sockaddr *cli,
					   int cli_len, const char *filename,
					   __u32 num_blocks, __u16 padding,
					   unsigned int fr)
{
	int num_dropped = send_files(s, cli, cli_len, filename,
				     "m", num_blocks,
				     CODE_FILES_PER_BLOCK, padding, 0, fr);

	if (num_dropped == -1)
		return;

	fprintf(stderr, "Dropped %d code packets out of %d (%.1f%%)\n",
		num_dropped, CODE_FILES_PER_BLOCK * num_blocks,
		100 * (float)num_dropped / (CODE_FILES_PER_BLOCK * num_blocks));
}
Exemplo n.º 4
0
int main (int argc, char **argv)
{
	GOptionContext *context;
	GError *error = NULL;
	NautilusSendto *nst;
	int ret = 0;

	setlocale (LC_ALL, "");
	bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
	textdomain (GETTEXT_PACKAGE);

	context = g_option_context_new ("");
	g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
	if (g_option_context_parse (context, &argc, &argv, &error) == FALSE) {
		g_print (_("Could not parse command-line options: %s\n"), error->message);
		g_error_free (error);
		return 1;
	}

        if (show_version) {
		g_print ("%s %s\n", PACKAGE_NAME, PACKAGE_VERSION);
		return 0;
	}

	nst = g_new0 (NautilusSendto, 1);
	nautilus_sendto_init (nst);
	if (!init_mailer (nst)) {
		g_print (_("No mail client installed, not sending files\n"));
		goto out;
	}


	if (nst->file_list == NULL) {
		g_print (_("Expects URIs or filenames to be passed as options\n"));
		ret = 1;
		goto out;
	}

	send_files (nst);

out:
	g_free (nst);

	return ret;
}
Exemplo n.º 5
0
int main(int argc, char **argv)
{
	char	str[MAX_PATH+1];
	char	fname[MAX_PATH+1];
	char	ini_fname[MAX_PATH+1];
	char*	p;
	char*	arg;
	int 	i;
	int		retval;
	uint	fnames=0;
	FILE*	fp;
	BOOL	tcp_nodelay;
	char	compiler[32];
	str_list_t fname_list;

	fname_list=strListInit();

	DESCRIBE_COMPILER(compiler);

	errfp=stderr;
#ifdef __unix__
	statfp=stderr;
#else
	statfp=stdout;
#endif

	sscanf("$Revision: 1.77 $", "%*s %s", revision);

	fprintf(statfp,"\nSynchronet External X/Y/Zmodem  v%s-%s"
		"  Copyright %s Rob Swindell\n\n"
		,revision
		,PLATFORM_DESC
		,__DATE__+7
		);

	xmodem_init(&xm,NULL,&mode,lputs,xmodem_progress,send_byte,recv_byte,is_connected,NULL);
	zmodem_init(&zm,NULL,lputs,zmodem_progress,send_byte,recv_byte,is_connected,NULL,data_waiting);

	/* Generate path/sexyz[.host].ini from path/sexyz[.exe] */
	SAFECOPY(str,argv[0]);
	p=getfname(str);
	SAFECOPY(fname,p);
	*p=0;
	if((p=getfext(fname))!=NULL) 
		*p=0;
	strcat(fname,".ini");
	
	iniFileName(ini_fname,sizeof(ini_fname),str,fname);
	if((fp=fopen(ini_fname,"r"))!=NULL)
		fprintf(statfp,"Reading %s\n",ini_fname);

	tcp_nodelay				=iniReadBool(fp,ROOT_SECTION,"TCP_NODELAY",TRUE);

	telnet					=iniReadBool(fp,ROOT_SECTION,"Telnet",TRUE);
	debug_tx				=iniReadBool(fp,ROOT_SECTION,"DebugTx",FALSE);
	debug_rx				=iniReadBool(fp,ROOT_SECTION,"DebugRx",FALSE);
	debug_telnet			=iniReadBool(fp,ROOT_SECTION,"DebugTelnet",FALSE);

	pause_on_exit			=iniReadBool(fp,ROOT_SECTION,"PauseOnExit",FALSE);
	pause_on_abend			=iniReadBool(fp,ROOT_SECTION,"PauseOnAbend",FALSE);

	log_level				=iniReadLogLevel(fp,ROOT_SECTION,"LogLevel",log_level);

	outbuf.highwater_mark	=iniReadInteger(fp,ROOT_SECTION,"OutbufHighwaterMark",1100);
	outbuf_drain_timeout	=iniReadInteger(fp,ROOT_SECTION,"OutbufDrainTimeout",10);
	outbuf_size				=iniReadInteger(fp,ROOT_SECTION,"OutbufSize",16*1024);

	progress_interval		=iniReadInteger(fp,ROOT_SECTION,"ProgressInterval",1);

	if(iniReadBool(fp,ROOT_SECTION,"Debug",FALSE))
		log_level=LOG_DEBUG;

	xm.send_timeout			=iniReadInteger(fp,"Xmodem","SendTimeout",xm.send_timeout);	/* seconds */
	xm.recv_timeout			=iniReadInteger(fp,"Xmodem","RecvTimeout",xm.recv_timeout);	/* seconds */
	xm.byte_timeout			=iniReadInteger(fp,"Xmodem","ByteTimeout",xm.byte_timeout);	/* seconds */
	xm.ack_timeout			=iniReadInteger(fp,"Xmodem","AckTimeout",xm.ack_timeout);	/* seconds */
	xm.block_size			=iniReadInteger(fp,"Xmodem","BlockSize",xm.block_size);		/* 128 or 1024 */
	xm.max_errors			=iniReadInteger(fp,"Xmodem","MaxErrors",xm.max_errors);
	xm.g_delay				=iniReadInteger(fp,"Xmodem","G_Delay",xm.g_delay);

	zm.init_timeout			=iniReadInteger(fp,"Zmodem","InitTimeout",zm.init_timeout);	/* seconds */
	zm.send_timeout			=iniReadInteger(fp,"Zmodem","SendTimeout",zm.send_timeout);	/* seconds */
	zm.recv_timeout			=iniReadInteger(fp,"Zmodem","RecvTimeout",zm.recv_timeout);	/* seconds */
	zm.crc_timeout			=iniReadInteger(fp,"Zmodem","CrcTimeout",zm.crc_timeout);	/* seconds */
	zm.block_size			=iniReadInteger(fp,"Zmodem","BlockSize",zm.block_size);			/* 1024  */
	zm.max_block_size		=iniReadInteger(fp,"Zmodem","MaxBlockSize",zm.max_block_size);	/* 1024 or 8192 */
	zm.max_errors			=iniReadInteger(fp,"Zmodem","MaxErrors",zm.max_errors);
	zm.recv_bufsize			=iniReadInteger(fp,"Zmodem","RecvBufSize",0);
	zm.no_streaming			=!iniReadBool(fp,"Zmodem","Streaming",TRUE);
	zm.want_fcs_16			=!iniReadBool(fp,"Zmodem","CRC32",TRUE);
	zm.escape_telnet_iac	=iniReadBool(fp,"Zmodem","EscapeTelnetIAC",TRUE);
	zm.escape_8th_bit		=iniReadBool(fp,"Zmodem","Escape8thBit",FALSE);
	zm.escape_ctrl_chars	=iniReadBool(fp,"Zmodem","EscapeCtrlChars",FALSE);

	dszlog_path				=iniReadBool(fp,"DSZLOG","Path",TRUE);
	dszlog_short			=iniReadBool(fp,"DSZLOG","Short",FALSE);
	dszlog_quotes			=iniReadBool(fp,"DSZLOG","Quotes",FALSE);

	if(fp!=NULL)
		fclose(fp);

	if(zm.recv_bufsize > 0xffff)
		zm.recv_bufsize = 0xffff;

	if(outbuf_size < MIN_OUTBUF_SIZE)
		outbuf_size = MIN_OUTBUF_SIZE;
	else if(outbuf_size > MAX_OUTBUF_SIZE)
		outbuf_size = MAX_OUTBUF_SIZE;
	
	fprintf(statfp,"Output buffer size: %u\n", outbuf_size);
	RingBufInit(&outbuf, outbuf_size);

#if !defined(RINGBUF_EVENT)
	outbuf_empty=CreateEvent(NULL,/* ManualReset */TRUE, /*InitialState */TRUE,NULL);
#endif

#if 0
	if(argc>1) {
		fprintf(statfp,"Command line: ");
		for(i=1;i<argc;i++)
			fprintf(statfp,"%s ",argv[i]);
		fprintf(statfp,"\n",statfp);
	}
#endif


	for(i=1;i<argc;i++) {

		if(sock==INVALID_SOCKET && isdigit(argv[i][0])) {
			sock=atoi(argv[i]);
			continue;
		}

		if(!(mode&(SEND|RECV))) {
			if(toupper(argv[i][0])=='S' || toupper(argv[i][0])=='R') { /* cmd */
				if(toupper(argv[i][0])=='R')
					mode|=RECV;
				else
					mode|=SEND;

				switch(argv[i][1]) {
					case 'c':
					case 'C':
						mode|=XMODEM|CRC;
						break;
					case 'x':
						xm.block_size=128;
					case 'X':
						mode|=XMODEM;
						break;
					case 'b':	/* sz/rz compatible */
					case 'B':
					case 'y':
						xm.block_size=128;
					case 'Y':
						mode|=(YMODEM|CRC);
						break;
					case 'g':
					case 'G':
						mode|=(YMODEM|CRC|GMODE);
						break;
					case 'z':
					case 'Z':
						mode|=(ZMODEM|CRC);
						break;
					default:
						fprintf(statfp,"Unrecognized command '%s'\n\n",argv[i]);
						fprintf(statfp,usage);
						bail(1); 
				} 
				continue;
			}

			if(toupper(argv[i][0])=='V') {

				fprintf(statfp,"%-8s %s\n",getfname(__FILE__)		,revision);
				fprintf(statfp,"%-8s %s\n",getfname(xmodem_source()),xmodem_ver(str));
				fprintf(statfp,"%-8s %s\n",getfname(zmodem_source()),zmodem_ver(str));
#ifdef _DEBUG
				fprintf(statfp,"Debug\n");
#endif
				fprintf(statfp,"Compiled %s %.5s with %s\n",__DATE__,__TIME__,compiler);
				fprintf(statfp,"%s\n",os_version(str));
				bail(0);
			}

			arg=argv[i];
			if(*arg=='-') {
				while(*arg=='-')
					arg++;
				if(stricmp(arg,"telnet")==0) {
					telnet=TRUE;
					continue;
				}
				if(stricmp(arg,"rlogin")==0 || stricmp(arg,"ssh")==0 || stricmp(arg,"raw")==0) {
					telnet=FALSE;
					continue;
				}
				if(stricmp(arg,"debug")==0) {
					log_level=LOG_DEBUG;
					continue;
				}
				if(stricmp(arg,"quotes")==0) {
					dszlog_quotes=TRUE;
					continue;
				}
				switch(toupper(*arg)) {
					case 'K':	/* sz/rz compatible */
						xm.block_size=1024;
						break;
					case 'C':	/* sz/rz compatible */
						mode|=CRC;
						break;
					case '2':
						zm.max_block_size=2048;
						break;
					case '4':
						zm.max_block_size=4096;
						break;
					case '8':	/* ZedZap */
						zm.max_block_size=8192;
						break;
					case 'O':	/* disable Zmodem CRC-32 */
						zm.want_fcs_16=TRUE;
						break;
					case 'S':	/* disable Zmodem streaming */
						zm.no_streaming=TRUE;
						break;
					case 'G':	/* Ymodem-G */
						mode|=GMODE;
						break;
					case 'Y':
						mode|=OVERWRITE;
						break;
					case '!':
						pause_on_abend=TRUE;
						break;
				}
			}
		}

		else if((argv[i][0]=='+' || argv[i][0]=='@') && fexist(argv[i]+1)) {
			if(mode&RECVDIR) {
				fprintf(statfp,"!Cannot specify both directory and filename\n");
				bail(1); 
			}
			sprintf(str,"%s",argv[i]+1);
			if((fp=fopen(str,"r"))==NULL) {
				fprintf(statfp,"!Error %d opening filelist: %s\n",errno,str);
				bail(1); 
			}
			while(!feof(fp) && !ferror(fp)) {
				if(!fgets(str,sizeof(str),fp))
					break;
				truncsp(str);
				strListAppend(&fname_list,strdup(str),fnames++);
			}
			fclose(fp); 
		}

		else if(mode&(SEND|RECV)){
			if(isdir(argv[i])) { /* is a directory */
				if(mode&RECVDIR) {
					fprintf(statfp,"!Only one directory can be specified\n");
					bail(1); 
				}
				if(fnames) {
					fprintf(statfp,"!Cannot specify both directory and filename\n");
					bail(1); 
				}
				if(mode&SEND) {
					fprintf(statfp,"!Cannot send directory '%s'\n",argv[i]);
					bail(1);
				}
				mode|=RECVDIR; 
			}
			strListAppend(&fname_list,argv[i],fnames++);
		} 
	}

	if(!telnet)
		zm.escape_telnet_iac = FALSE;

	if(sock==INVALID_SOCKET || sock<1) {
#ifdef __unix__
		if(STDOUT_FILENO > STDIN_FILENO)
			sock=STDOUT_FILENO;
		else
			sock=STDIN_FILENO;
		stdio=TRUE;
		
		fprintf(statfp,"No socket descriptor specified, using STDIO\n");
		telnet=FALSE;
#else
		fprintf(statfp,"!No socket descriptor specified\n\n");
		fprintf(errfp,usage);
		bail(1);
#endif
	}
#ifdef __unix__
	else
		statfp=stdout;
#endif

	if(!(mode&(SEND|RECV))) {
		fprintf(statfp,"!No command specified\n\n");
		fprintf(statfp,usage);
		bail(1); 
	}

	if(mode&(SEND|XMODEM) && !fnames) { /* Sending with any or recv w/Xmodem */
		fprintf(statfp,"!Must specify filename or filelist\n\n");
		fprintf(statfp,usage);
		bail(1); 
	}

#ifdef __unix__
	if(stdio) {
		struct termios term;
		memset(&term,0,sizeof(term));
		cfsetispeed(&term,B19200);
		cfsetospeed(&term,B19200);
		term.c_iflag &= ~(IMAXBEL|IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON);
		term.c_oflag &= ~OPOST;
		term.c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);
		term.c_cflag &= ~(CSIZE|PARENB);
		term.c_cflag |= CS8;
		atexit(resetterm);
		tcgetattr(STDOUT_FILENO, &origterm);
		tcsetattr(STDOUT_FILENO, TCSADRAIN, &term);
	}
#endif

	/* Code disabled.  Why?  ToDo */
/*	if(mode&RECVDIR)
		backslash(fname[0]); */

	if(!winsock_startup())
		bail(-1);

	/* Enable the Nagle Algorithm */
#ifdef __unix__
	if(!stdio) {
#endif
		lprintf(LOG_DEBUG,"Setting TCP_NODELAY to %d",tcp_nodelay);
		setsockopt(sock,IPPROTO_TCP,TCP_NODELAY,(char*)&tcp_nodelay,sizeof(tcp_nodelay));
#ifdef __unix__
	}
#endif

	if(!socket_check(sock, NULL, NULL, 0)) {
		lprintf(LOG_WARNING,"No socket connection");
		bail(-1); 
	}

	if((dszlog=getenv("DSZLOG"))!=NULL) {
		if((logfp=fopen(dszlog,"w"))==NULL) {
			lprintf(LOG_WARNING,"Error %d opening DSZLOG file: %s",errno,dszlog);
			bail(-1); 
		}
	}

	/* Install Ctrl-C/Break signal handler here */
#if defined(_WIN32)
	SetConsoleCtrlHandler(ControlHandler, TRUE /* Add */);
#elif defined(__unix__)
	signal(SIGQUIT,break_handler);
	signal(SIGINT,break_handler);
	signal(SIGTERM,break_handler);

	signal(SIGHUP,SIG_IGN);

	/* Don't die on SIGPIPE  */
	signal(SIGPIPE,SIG_IGN);
#endif

#if !SINGLE_THREADED
	_beginthread(output_thread,0,NULL);
#endif

	if(mode&RECV)
		retval=receive_files(fname_list, fnames);
	else
		retval=send_files(fname_list, fnames);

#if !SINGLE_THREADED
	lprintf(LOG_DEBUG,"Waiting for output buffer to empty... ");
	if(WaitForEvent(outbuf_empty,5000)!=WAIT_OBJECT_0)
		lprintf(LOG_DEBUG,"FAILURE");
#endif

	terminate=TRUE;	/* stop output thread */
	/* Code disabled.  Why?  ToDo */
/*	sem_post(outbuf.sem);
	sem_post(outbuf.highwater_sem); */

	fprintf(statfp,"Exiting - Error level: %d, flows: %u, select_errors=%u"
		,retval, flows, select_errors);
	fprintf(statfp,"\n");

	bail(retval);
}
Exemplo n.º 6
0
int diff (int argc, char **argv)
{
    char tmp[50];
    int c, err = 0;
    int local = 0;
    int which;
    int option_index;

    is_rcs = (strcmp (command_name, "rcsfile") == 0);

    if (argc == -1)
        usage (diff_usage);

    have_rev1_label = have_rev2_label = 0;

    /*
     * Note that we catch all the valid arguments here, so that we can
     * intercept the -r arguments for doing revision diffs; and -l/-R for a
     * non-recursive/recursive diff.
     */

    /* Clean out our global variables (multiroot can call us multiple
       times and the server can too, if the client sends several
       diff commands).  */
    if (opts == NULL)
    {
        opts_allocated = 1;
        opts = (char*)xmalloc (opts_allocated);
    }
    opts[0] = '\0';
    diff_rev1 = NULL;
    diff_rev2 = NULL;
    diff_date1 = NULL;
    diff_date2 = NULL;

    optind = 0;
    while ((c = getopt_long (argc, argv,
                             "+abcdefhilnpstuwy0123456789BHNRTC:D:F:I:L:U:V:W:k:r:",
                             longopts, &option_index)) != -1)
    {
        switch (c)
        {
        case 'a':
        case 'b':
        case 'c':
        case 'd':
        case 'e':
        case 'f':
        case 'h':
        case 'i':
        case 'n':
        case 'p':
        case 's':
        case 't':
        case 'u':
        case 'w':
        case 'y':
        case '0':
        case '1':
        case '2':
        case '3':
        case '4':
        case '5':
        case '6':
        case '7':
        case '8':
        case '9':
        case 'B':
        case 'H':
        case 'T':
            (void) sprintf (tmp, " -%c", (char) c);
            allocate_and_strcat (&opts, &opts_allocated, tmp);
            break;
        case 'L':
            if (have_rev1_label++)
                if (have_rev2_label++)
                {
                    error (0, 0, "extra -L arguments ignored");
                    break;
                }

            allocate_and_strcat (&opts, &opts_allocated, " -L");
            allocate_and_strcat (&opts, &opts_allocated, optarg);
            break;
        case 'C':
        case 'F':
        case 'I':
        case 'U':
        case 'V':
        case 'W':
            (void) sprintf (tmp, " -%c", (char) c);
            allocate_and_strcat (&opts, &opts_allocated, tmp);
            allocate_and_strcat (&opts, &opts_allocated, optarg);
            break;
        case 131:
            /* --ifdef.  */
            allocate_and_strcat (&opts, &opts_allocated, " --ifdef=");
            allocate_and_strcat (&opts, &opts_allocated, optarg);
            break;
        case 129:
        case 130:
        case 132:
        case 133:
        case 134:
        case 135:
        case 136:
        case 137:
        case 138:
        case 139:
        case 140:
        case 141:
        case 142:
        case 143:
        case 144:
        case 145:
        case 146:
            allocate_and_strcat (&opts, &opts_allocated, " --");
            allocate_and_strcat (&opts, &opts_allocated,
                                 longopts[option_index].name);
            if (longopts[option_index].has_arg == 1
                    || (longopts[option_index].has_arg == 2
                        && optarg != NULL))
            {
                allocate_and_strcat (&opts, &opts_allocated, "=");
                allocate_and_strcat (&opts, &opts_allocated, optarg);
            }
            break;
        case 'R':
            local = 0;
            break;
        case 'l':
            local = 1;
            break;
        case 'k':
            if (options)
                xfree (options);
            options = RCS_check_kflag (optarg,true,true);
            break;
        case 'r':
            if (diff_rev2 != NULL || diff_date2 != NULL)
                error (1, 0,
                       "no more than two revisions/dates can be specified");
            if (diff_rev1 != NULL || diff_date1 != NULL)
                diff_rev2 = optarg;
            else
                diff_rev1 = optarg;
            break;
        case 'D':
            if (diff_rev2 != NULL || diff_date2 != NULL)
                error (1, 0,
                       "no more than two revisions/dates can be specified");
            if (diff_rev1 != NULL || diff_date1 != NULL)
                diff_date2 = Make_Date (optarg);
            else
                diff_date1 = Make_Date (optarg);
            break;
        case 'N':
            empty_files = 1;
            break;
        case '?':
        default:
            usage (diff_usage);
            break;
        }
    }
    argc -= optind;
    argv += optind;

    /* make sure options is non-null */
    if (!options)
        options = xstrdup ("");

    if (!is_rcs && current_parsed_root->isremote)
    {
        if (local)
            send_arg("-l");
        if (empty_files)
            send_arg("-N");
        send_option_string (opts);
        if (options[0] != '\0')
            option_with_arg ("-k", options);
        if (diff_rev1)
            option_with_arg ("-r", diff_rev1);
        if (diff_date1)
            client_senddate (diff_date1);
        if (diff_rev2)
            option_with_arg ("-r", diff_rev2);
        if (diff_date2)
            client_senddate (diff_date2);

        send_arg("--");
        /* Send the current files unless diffing two revs from the archive */
        if (diff_rev2 == NULL && diff_date2 == NULL)
            send_files (argc, argv, local, 0, 0);
        else
            send_files (argc, argv, local, 0, SEND_NO_CONTENTS);

        send_file_names (argc, argv, SEND_EXPAND_WILD);

        send_to_server ("diff\n", 0);
        err = get_responses_and_close ();
        xfree (options);
        options = NULL;
        return (err);
    }

    if(is_rcs)
    {
        int n;

        if(!argc)
            usage(diff_usage);

        for(n=0; n<argc; n++)
        {
            struct file_info finfo = {0};
            const char *name;
            char *tmp = find_rcs_filename(argv[n]);

            if(!tmp)
                error(1,ENOENT,"%s",argv[n]);

            finfo.fullname=fullpathname(tmp, &name);
            finfo.file = xstrdup(name);
            char *ff = xstrdup(finfo.fullname);
            finfo.update_dir = ff;
            ff[(name-finfo.fullname)-1]='\0';

            finfo.rcs = RCS_fopen(finfo.fullname);
            if(finfo.rcs)
            {
                ff = (char*)finfo.fullname;
                ff[strlen(finfo.fullname)-2]='\0';
                ff = (char*)finfo.file;
                ff[strlen(finfo.file)-2]='\0';
                err+=diff_fileproc(NULL,&finfo);
                freercsnode(&finfo.rcs);
            }
            else
            {
                error(1,ENOENT,"%s",tmp);
                err++;
            }
            xfree(finfo.fullname);
            xfree(finfo.file);
            xfree(finfo.update_dir);
            xfree(tmp);
        }
    }
    else
    {
        if (diff_rev1 != NULL)
            tag_check_valid (diff_rev1, argc, argv, local, 0, "");
        if (diff_rev2 != NULL)
            tag_check_valid (diff_rev2, argc, argv, local, 0, "");

        which = W_LOCAL;
        if (diff_rev1 != NULL || diff_date1 != NULL)
            which |= W_REPOS;

        /* start the recursion processor */
        err = start_recursion (diff_fileproc, diff_filesdoneproc, (PREDIRENTPROC) NULL, diff_dirproc,
                               diff_dirleaveproc, NULL, argc, argv, local,
                               which, 0, 1, (char *) NULL, NULL, 1, verify_read, diff_rev1);
    }

    /* clean up */
    xfree (options);
    options = NULL;

    if (diff_date1 != NULL)
        xfree (diff_date1);
    if (diff_date2 != NULL)
        xfree (diff_date2);

    return (err);
}
Exemplo n.º 7
0
void xfer(serial_h com, configuration_t *config)
{
  FILE *log = NULL ;
  int ch ;
  int linelen ;
  char buffer[MAXLINELEN] ;

  do {
    bbc_status_t result = BBC_OK ;

    printf("\f\n\n"
           "     (R)eceive files from BBC          (S)end files to BBC\n"
           "     (*)-command on BBC                (D)o command on PC\n"
           "     (T)erminal emulation              (G)et disc image from BBC\n"
           "     (L)og BBC OSCLI output %s      (C)d to directory\n"
           "     (P)C file CRC                     (B)BC file CRC\n"
           "     (Q)uit\n\n"
           "Enter command: ", log ? "(on) " : "(off)") ;

    do {
      ch = toupper(keyboard_char()) ;
    } while ( strchr("RS*DTGLCQPB", ch) == NULL ) ;

    putchar(ch) ;

    switch ( ch ) {
    case 'L':
      putchar('\n') ;
      if ( log ) {
        fclose(log) ;
        log = NULL ;
        puts("Logging turned off") ;
      } else {
        printf("Log OSCLI output to file: ") ;
        linelen = keyboard_line(buffer, MAXLINELEN) ;

        if ( linelen == 0 )
          puts("No log file specified, not logging\n") ;
        else if ( (log = fopen(buffer, "w+")) == NULL )
          printf("Problem opening log file %s, not logging\n", buffer) ;
      }

      break ;
    case 'R':
      putchar('\n') ;
      result = retrieve_files(com, config->wildcards, config->directories) ;
      break ;
    case 'S':
      putchar('\n') ;
      result = send_files(com, config->wildcards, config->directories) ;
      break ;
    case 'P':
      putchar('\n') ;
      result = local_crc() ;
      break ;
    case 'B':
      putchar('\n') ;
      result = remote_crc(com, config->wildcards, config->directories) ;
      break ;
    case '*':
      result = oscli(com, log) ;
      break ;
    case 'G':
      putchar('\n') ;
      result = retrieve_disc(com) ;
      break ;
    case 'D':
      (void)getcwd(buffer, MAXLINELEN) ;
      printf("\n%s> ", buffer) ;
      linelen = keyboard_line(buffer, MAXLINELEN) ;

      fflush(stdout) ;
      fflush(stdin) ;

      if ( linelen > 0 ) {
        keyboard_close() ;
        system(buffer) ;
        keyboard_open() ;
      }

      break ;
    case 'C':
      printf("\nDirectory: ") ;
      linelen = keyboard_line(buffer, MAXLINELEN) ;

      if ( chdir(buffer) != 0 )
        printf("Problem changing directory to %s, ignoring\n", buffer) ;

      break ;
    case 'T':
      putchar('\n') ;
      result = terminal(com) ;
      break ;
    }

    while ( result == BBC_ERROR ) {
      serial_printf(com, ERR_TXT) ;
      if ( (result = bbc_readline(com, buffer, MAXLINELEN)) == BBC_OK &&
           (result = bbc_readline(com, buffer, MAXLINELEN)) == BBC_OK )
        printf("BBC Error: %s\n", buffer) ;
    }
  } while ( ch != 'Q' ) ;

  putchar('\n') ;

  serial_printf(com, "Q") ;

  if ( log )
    fclose(log) ;
}
Exemplo n.º 8
0
int cvsstatus (int argc, char **argv)
{
    int c;
    int err = 0;

	supress_extra_fields = compat[compat_level].hide_extended_status;

    if (argc == -1)
	usage (status_usage);

    optind = 0;
    while ((c = getopt (argc, argv, "+vlRqxX")) != -1)
    {
	switch (c)
	{
	    case 'v':
		long_format = 1;
		break;
	    case 'l':
		local = 1;
		break;
	    case 'R':
		local = 0;
		break;
		case 'q':
		quick++;
		break;
		case 'x':
			supress_extra_fields = 0;
			break;
		case 'X':
			supress_extra_fields = 1;
			break;
	    case '?':
	    default:
		usage (status_usage);
		break;
	}
    }
    argc -= optind;
    argv += optind;

    if (current_parsed_root->isremote)
    {
	if (long_format)
	    send_arg("-v");
	if (local)
	    send_arg("-l");
	if (supress_extra_fields)
		send_arg("-X");
	for(c=0; c<quick; c++)
		send_arg("-q");
	send_arg("--");

	/* For a while, we tried setting SEND_NO_CONTENTS here so this
	   could be a fast operation.  That prevents the
	   server from updating our timestamp if the timestamp is
	   changed but the file is unmodified.  Worse, it is user-visible
	   (shows "locally modified" instead of "up to date" if
	   timestamp is changed but file is not).  And there is no good
	   workaround (you might not want to run "cvs update"; "cvs -n
	   update" doesn't update CVS/Entries; "cvs diff --brief" or
	   something perhaps could be made to work but somehow that
	   seems nonintuitive to me even if so).  Given that timestamps
	   seem to have the potential to get munged for any number of
	   reasons, it seems better to not rely too much on them.  */

	send_files (argc, argv, local, 0, 0);

	send_file_names (argc, argv, SEND_EXPAND_WILD);

	send_to_server ("status\n", 0);
	err = get_responses_and_close ();

	return err;
    }

    /* start the recursion processor */
    err = start_recursion (status_fileproc, (FILESDONEPROC) NULL,
			   (PREDIRENTPROC) NULL, status_dirproc, (DIRLEAVEPROC) NULL, NULL,
			   argc, argv, local,
			   W_LOCAL, 0, 1, (char *) NULL, NULL, 1, verify_read);

    return (err);
}
Exemplo n.º 9
0
int lsacl (int argc, char **argv)
{
	int c;
	int err = 0;
	int local = 1;
	int directories_only = 0;

	is_rlsacl = !strcmp(command_name,"rlsacl");

	if (argc == -1)
		usage (is_rlsacl?rlsacl_usage:lsacl_usage);

	optind = 0;
	while ((c = getopt(argc, argv, "+dR")) != -1)
	{
		switch (c)
		{
		case 'd':
			directories_only = 1;
			break;
		case 'R':
			local = 0;
			break;
		case '?':
		default:
		usage (lsacl_usage);
		break;
		}
	}
	argc -= optind;
	argv += optind;

	if (argc < 0)
		usage (is_rlsacl?rlsacl_usage:lsacl_usage);

	if (current_parsed_root->isremote)
	{
		if(is_rlsacl)
		{
			if (!supported_request ("rlsacl"))
				error (1, 0, "server does not support rlsacl");
		}
		else
		{
			if (!supported_request ("lsacl"))
				error (1, 0, "server does not support lsacl");
		}

		if(!local)
			send_arg("-R");

		if(directories_only)
			send_arg("-d");

		send_arg("--");
		if (is_rlsacl)
		{
			int i;
			for (i = 0; i < argc; i++)
			send_arg (argv[i]);
			send_to_server ("rlsacl\n", 0);
		}
		else
		{
			send_file_names (argc, argv, SEND_EXPAND_WILD);
			send_files (argc, argv, local, 0, SEND_NO_CONTENTS);
			send_to_server ("lsacl\n", 0);
		}
		return get_responses_and_close ();
   }

	if(!acl_mode)
		error(1,0,"Access control is disabled on this repository.");
    
	if (is_rlsacl)
	{
		DBM *db;
		int i;
		db = open_module ();
		if(!argc)
		{
				err += do_module (db, ".", MISC, "Listing", rlsacl_proc,
						(char *) NULL, 0, local, 0, 0, (char *) NULL);
		}
		else
		{
			for (i = 0; i < argc; i++)
			{
				err += do_module (db, argv[i], MISC, "Listing", rlsacl_proc,
						(char *) NULL, 0, local, 0, 0, (char *) NULL);
			}
		}
		close_module (db);
	}
	else
	{
		/* start the recursion processor */
		err = start_recursion (directories_only?NULL:lsacl_fileproc, (FILESDONEPROC) NULL,
					(PREDIRENTPROC) NULL, lsacl_dirproc, (DIRLEAVEPROC) NULL, NULL,
					argc, argv, local,
					W_LOCAL, 0, 1, (char *) NULL, NULL, 1, NULL);
	}

    return (err);

}
Exemplo n.º 10
0
int
ls (int argc, char **argv)
{
    int c;
    int err = 0;

    is_rls = strcmp (cvs_cmd_name, "rls") == 0;

    if (argc == -1)
	usage (ls_usage);

    entries_format = false;
    long_format = false;
    show_tag = NULL;
    show_date = NULL;
    tag_validated = false;
    recurse = false;
    ls_prune_dirs = false;
    show_dead_revs = false;

    getoptreset ();

    while ((c = getopt (argc, argv,
#ifdef SERVER_SUPPORT
           server_active ? "qdelr:D:PR" :
#endif /* SERVER_SUPPORT */
           "delr:D:RP"
           )) != -1)
    {
	switch (c)
	{
#ifdef SERVER_SUPPORT
	    case 'q':
		if (server_active)
		{
		    error (0, 0,
"`%s ls -q' is deprecated.  Please use the global `-q' option instead.",
                           program_name);
		    quiet = true;
		}
		else
		    usage (ls_usage);
		break;
#endif /* SERVER_SUPPORT */
	    case 'd':
		show_dead_revs = true;
		break;
	    case 'e':
		entries_format = true;
		break;
	    case 'l':
		long_format = true;
		break;
	    case 'r':
		parse_tagdate (&show_tag, &show_date, optarg);
		break;
	    case 'D':
		if (show_date) free (show_date);
		show_date = Make_Date (optarg);
		break;
	    case 'P':
		ls_prune_dirs = true;
		break;
	    case 'R':
		recurse = true;
		break;
	    case '?':
	    default:
		usage (ls_usage);
		break;
	}
    }
    argc -= optind;
    argv += optind;

    if (entries_format && long_format)
    {
        error (0, 0, "`-e' & `-l' are mutually exclusive.");
        usage (ls_usage);
    }

    wrap_setup ();

#ifdef CLIENT_SUPPORT
    if (current_parsed_root->isremote)
    {
	/* We're the local client.  Fire up the remote server.	*/
	start_server ();

	ign_setup ();

	if (is_rls ? !(supported_request ("rlist") || supported_request ("ls"))
                   : !supported_request ("list"))
	    error (1, 0, "server does not support %s", cvs_cmd_name);

	if (quiet && !supported_request ("global-list-quiet"))
	    send_arg ("-q");
	if (entries_format)
	    send_arg ("-e");
	if (long_format)
	    send_arg ("-l");
	if (ls_prune_dirs)
	    send_arg ("-P");
	if (recurse)
	    send_arg ("-R");
	if (show_dead_revs)
	    send_arg ("-d");
	if (show_tag)
	    option_with_arg ("-r", show_tag);
	if (show_date)
	    client_senddate (show_date);

	send_arg ("--");

	if (is_rls)
	{
	    int i;
	    for (i = 0; i < argc; i++)
		send_arg (argv[i]);
            if (supported_request ("rlist"))
		send_to_server ("rlist\012", 0);
	    else
		/* For backwards compatibility with CVSNT...  */
		send_to_server ("ls\012", 0);
	}
	else
	{
	    /* Setting this means, I think, that any empty directories created
	     * by the server will be deleted by the client.  Since any dirs
	     * created at all by ls should remain empty, this should cause any
	     * dirs created by the server for the ls command to be deleted.
	     */
	    client_prune_dirs = 1;

	    /* I explicitly decide not to send contents here.  We *could* let
	     * the user pull status information with this command, but why
	     * don't they just use update or status?
	     */
	    send_files (argc, argv, !recurse, 0, SEND_NO_CONTENTS);
	    send_file_names (argc, argv, SEND_EXPAND_WILD);
	    send_to_server ("list\012", 0);
	}

	err = get_responses_and_close ();
	return err;
    }
#endif

    if (is_rls)
    {
	DBM *db;
	int i;
	db = open_module ();
	if (argc)
	{
	    for (i = 0; i < argc; i++)
	    {
		char *mod = xstrdup (argv[i]);
		char *p;

		for (p=strchr (mod,'\\'); p; p=strchr (p,'\\'))
		    *p='/';

		p = strrchr (mod,'/');
		if (p && (strchr (p,'?') || strchr (p,'*')))
		{
		    *p='\0';
		    regexp_match = p+1;
		}
		else
		    regexp_match = NULL;

		/* Frontends like to do 'ls -q /', so we support it explicitly.
                 */
		if (!strcmp (mod,"/"))
		{
		    *mod='\0';
		}

		err += do_module (db, mod, MISC, "Listing",
				  ls_proc, NULL, 0, 0, 0, 0, NULL);

		free (mod);
	    }
	}
	else
	{
	    /* should be ".", but do_recursion() 
	       fails this: assert ( strstr ( repository, "/./" ) == NULL ); */
	    char *topmod = xstrdup ("");
	    err += do_module (db, topmod, MISC, "Listing",
			      ls_proc, NULL, 0, 0, 0, 0, NULL);
	    free (topmod);
	}
	close_module (db);
    }
    else
	ls_proc (argc + 1, argv - 1, NULL, NULL, NULL, 0, 0, NULL, NULL);

    return err;
}
Exemplo n.º 11
0
Arquivo: chacl.cpp Projeto: acml/cvsnt
int chacl (int argc, char **argv)
{
	int c;
	int local = 1;
	int err = 0;
	int is_rchacl = !strcmp(command_name,"rchacl");

	if (argc == 1 || argc == -1)
		usage (is_rchacl?rchacl_usage:chacl_usage);

	memset(&parms,0,sizeof(parms));
	optind = 0;
	while ((c = getopt (argc, argv, "+a:dnRr:u:m:j:p:")) != -1)
	{
		switch (c)
		{
		case 'a':
			if(parms.del)
				error(1,0,"Cannot combine -a and -d");
			parms.access = xstrdup(optarg);
			break;
		case 'd':
			if(parms.access)
				error(1,0,"Cannot combine -a and -d");
			parms.del = 1;
			break;
		case 'j':
			parms.merge=xstrdup(optarg);
			break;
		case 'm':
			parms.message=xstrdup(optarg);
			break;
		case 'n':
			parms.noinherit=1;
			break;
		case 'p':
			parms.priority=xstrdup(optarg);
			break;
		case 'r':
			if(parms.branch)
				error(1,0,"Cannot have multiple -r options");
			parms.branch = xstrdup(optarg);
			break;
		case 'R':
			local = 0;
			break;
		case 'u':
			if(parms.user)
				error(1,0,"Cannot have multiple -u options");
			parms.user = xstrdup(optarg);
			break;
		case '?':
		default:
			usage (chacl_usage);
			break;
		}
	}
	argc -= optind;
	argv += optind;

	if (argc < 0)
		usage (is_rchacl?rchacl_usage:chacl_usage);

	if (current_parsed_root->isremote)
	{
		if(is_rchacl)
		{
			if (!supported_request ("rchacl2"))
				error (1, 0, "server does not support rchacl");
		}
		else
		{
			if (!supported_request ("chacl2"))
				error (1, 0, "server does not support v2 chacl");
		}

		if(parms.branch)
		{
			send_arg("-r");
			send_arg(parms.branch);
		}
		if(parms.user)
		{
			send_arg("-u");
			send_arg(parms.user);
		}
		if(parms.del)
			send_arg("-d");
		if(parms.noinherit)
			send_arg("-n");
		if(parms.access)
		{
			send_arg("-a");
			send_arg(parms.access);
		}
		if(parms.message)
		{
			send_arg("-m");
			send_arg(parms.message);
		}
		if(parms.merge)
		{
			send_arg("-j");
			send_arg(parms.merge);
		}
		if(parms.priority)
		{
			send_arg("-p");
			send_arg(parms.priority);
		}
		if(!local)
		{
			send_arg("-R");
		}
		send_arg("--");
		if (is_rchacl)
		{
			int i;
			for (i = 0; i < argc; i++)
			send_arg (argv[i]);
			send_to_server ("rchacl2\n", 0);
		}
		else
		{
			send_file_names (argc, argv, SEND_EXPAND_WILD);
			send_files (argc, argv, local, 0, SEND_NO_CONTENTS);
			send_to_server ("chacl2\n", 0);
		}
		return get_responses_and_close ();
	}

	if(!acl_mode)
		error(1,0,"Access control is disabled on this repository.");

	if (is_rchacl)
	{
		DBM *db;
		int i;
		db = open_module ();
		for (i = 0; i < argc; i++)
		{
			err += do_module (db, argv[i], MISC, "Changing", rchacl_proc,
					(char *) NULL, 0, local, 0, 0, (char *) NULL);
		}
		close_module (db);
	}
	else
	{
		current_date = date_from_time_t(global_session_time_t);
		err = start_recursion(chacl_fileproc, NULL, (PREDIRENTPROC) NULL, chacl_dirproc, chacl_dirleaveproc, (void*)NULL,
			argc, argv, local, W_LOCAL, 0, 0, (char*)NULL, NULL, 1, verify_control, parms.branch);
		xfree(current_date);
	}

	return (err);
}
Exemplo n.º 12
0
int cvsremove (int argc, char **argv)
{
    int c, err;

    if (argc == -1)
	usage (remove_usage);

    optind = 0;
    while ((c = getopt (argc, argv, "+flR")) != -1)
    {
	switch (c)
	{
	    case 'f':
		force = 1;
		break;
	    case 'l':
		local = 1;
		break;
	    case 'R':
		local = 0;
		break;
	    case '?':
	    default:
		usage (remove_usage);
		break;
	}
    }
    argc -= optind;
    argv += optind;

    if (current_parsed_root->isremote) {
	/* Call expand_wild so that the local removal of files will
           work.  It's ok to do it always because we have to send the
           file names expanded anyway.  */
	expand_wild (argc, argv, &argc, &argv);
	
	if (force)
	{
	    if (!noexec)
	    {
		start_recursion (remove_force_fileproc, (FILESDONEPROC) NULL,
				 (PREDIRENTPROC) NULL, (DIRENTPROC) NULL, (DIRLEAVEPROC) NULL,
				 (void *) NULL, argc, argv, local, W_LOCAL,
				 0, 0, (char *) NULL, NULL, 0, NULL, NULL);
	    }
	    /* else FIXME should probably act as if the file doesn't exist
	       in doing the following checks.  */
	}

	if (local)
	    send_arg("-l");
	send_arg("--");
	/* FIXME: Can't we set SEND_NO_CONTENTS here?  Needs investigation.  */
	send_files (argc, argv, local, 0, 0);
	send_file_names (argc, argv, 0);
	free_names (&argc, argv);
	send_to_server ("remove\n", 0);
        return get_responses_and_close ();
    }

    /* start the recursion processor */
    err = start_recursion (remove_fileproc, (FILESDONEPROC) NULL,
                           (PREDIRENTPROC) NULL, remove_dirproc, (DIRLEAVEPROC) NULL, NULL,
			   argc, argv,
                           local, W_LOCAL, 0, 1, (char *) NULL, NULL, 1,
			   verify_create, NULL);

    if (removed_files && !really_quiet)
		error (0, 0, "use '%s commit' to remove %s permanently", program_name,
	       (removed_files == 1) ? "this file" : "these files");

    if (existing_files)
	{
		error (0, 0,
	       ((existing_files == 1) ? "%d file exists; remove it first" :	"%d files exist; remove them first"),
	       existing_files);
		err=1;
	}

	if(bad_files)
		err=1;

    return (err);
}
Exemplo n.º 13
0
Arquivo: main.c Projeto: vocho/openqnx
int
main( int argc, char *argv[] ) {
	int		opt, file_count = 0;

	pname = basename(argv[0]);
	if ( argc < 2 ) {
		Puterr( "insufficient arguments\n" );
		exit(1);
		}

	prefix[0] = '\0';	/* No prefix and forced file name off by default	*/
	logfile[0] = '\0';	/* No activity log file by default */
	force = newer = relaxed = today = verbose = quiet = qterm = FALSE;
	make_dir = TRUE;
	onesec = ONESEC;
	retry_limit = RETRY_MAX;

	if (optind==0) /* 16-bit */
		++optind;		/* Skip over command name	*/

	if ( *argv[optind] == '/' ) { 	/*-- Check for a device over-ride ----*/
		if ( ( mdm = open( argv[1], O_RDWR ) ) == -1 ) {
			Puterr( "unable to open device '%s'\n", argv[1] );
			exit( 1 );
			}
		++optind;		/* Skip over specified device name	*/
		}
	else { 	/*-- No device override so use stdin/stdout to communicate ----*/
		struct stat statbuf;

		strcpy( device, ttyname( 0 ) );
		if( fstat( 0, &statbuf ) != -1 && S_ISSOCK(statbuf.st_mode) ) {
			socket = 1;
			mdm = 0;
		    }
		else if ( ( mdm = open( device, O_RDWR ) ) == -1 ) {
			Puterr( "unable to open stdin as r/w\n" );
			exit( 1 );
			}
		use_stdin = TRUE;
		}

	signal( SIGALRM, (void *)&timeout );

	init_mdm();			/* Setup the selected modem port and initialize		*/
						/*	any variables associated with the protocol.		*/

	if		( ( *argv[optind] | ' ' ) == 'r')					sending = FALSE;
	else if ( ( *argv[optind] | ' ' ) == 's'  &&  argc > 2 )	sending = TRUE;
	else {
		Puterr( "Invalid argument '%s' (must be 'se' or 're')\n", argv[optind] );
		exit( 1 );
		}
	++optind;

	/*---- Ready for command line options ----*/
	while( ( opt = getopt( argc, argv, "FmnqrtuvVQf:l:p:s:" ) ) != -1 ) {
		switch( opt ) {
			case 'F':		flashfile = TRUE;			break;
			case 'f':		strcpy( prefix, optarg );
							force = TRUE;				break;
			case 'l':		strcpy( logfile, optarg );	break;
			case 'm':		make_dir = FALSE;			break;
			case 'n':		newer = TRUE;				break;
			case 'r':		relaxed = TRUE;
							onesec <<= 2;		/* Timeouts 4 times larger	*/
							retry_limit <<= 1;	/* Twice as many retries	*/
							break;
			case 's':		sub_packet_size = atoi( optarg );
							sub_packet_size >>= 3;	/* Divide by 8 for sub_packet	*/
							if ( !sub_packet_size ) {
								Puterr( "packet size too small\n" );
								exit( 1 );
								}
							if ( sub_packet_size > MAXSIZE ) {
								Puterr( "packet size too large (max %d)\n",
											MAXSIZE*8);
								exit( 1 );
								}
							break;
			case 't':		today = TRUE;					break;
			case 'u':		unlink_file = TRUE;				break;
			case 'V':
			case 'v':		verbose = TRUE;					break;
			case 'q':		quiet = TRUE;					break;
			case 'Q':		qterm = TRUE;					break;
			case 'p':		strcpy( prefix, optarg );		break;
			case '?': 		if ( !extra_option( (char *)&optopt ) ) {
								Puterr( "unknown option '%s'\n", optopt );
								exit( 1 );
								}
							break;
			default: 		++file_count;		/* Count filenames		*/
							continue;			/*	but don't null them	*/
			}
		}

	if ( file_count > 1 ) multi_send_check();	/* Check if multi-send OK	*/

	final_init();						/* Last changes before starting		*/

#ifndef __QNXNTO__
	if ( !use_stdin ) dev_mode( 0, 0, _DEV_MODES );		/* Raw console input for abort requests	*/
#endif
	if ( sending )	send_files(		argc - optind, (signed char **)(argv + optind) );
	else	 		receive_files(	argc - optind, (signed char **)(argv + optind) );

	done( 0 );				/* Protocol dependant termination routine		*/
        return 0;
	}
Exemplo n.º 14
0
/*
 * Main method
 */
int main(int argc, char **argv) {
    unsigned char **files = (unsigned char **) malloc(sizeof(unsigned char *));
    int c, files_count = 0;
    char *host = NULL;
    while (1) {
        static struct option long_options[] = {
                {"listen",    no_argument,       0, 'l'},
                {"connect",   required_argument, 0, 'c'},
                {"version",   no_argument,       0, 'v'},
                {"help",      no_argument,       0, 'h'},
                {"port",      required_argument, 0, 'p'},
                {"file",      required_argument, 0, 'f'},
                {"buffer",    required_argument, 0, 'b'},
                {"directory", required_argument, 0, 'd'},
                {0, 0,                           0, 0}
        };
        /** getopt_long stores the option index here **/
        int option_index = 0;
        c = getopt_long(argc, argv, "lc:vhp:f:b:d:", long_options, &option_index);
        /** Detect the end of the options **/
        if (c == -1)
            break;
        switch (c) {
            case 0:
                /** If this option set a flag, do nothing else now **/
                if (long_options[option_index].flag != 0)
                    break;
                printf("option %s", long_options[option_index].name);
                if (optarg)
                    printf(" with arg %s", optarg);
                printf("\n");
                break;
            case 'l':
                host = NULL;
                break;
            case 'v':
                printf("Siphon - Utility to send files via direct connection, written in C\nTomClaw Software\nVersion 1.0\n");
                break;
            case 'h':
                show_help();
                break;
            case 'c':
                host = optarg;
                break;
            case 'p':
                port = *(int *) optarg;
                break;
            case 'f':
                files[files_count] = (unsigned char *) optarg;
                files_count += 1;
                break;
            case 'b':
                buffer_size = *(int *) optarg;
                break;
            case 'd':
                directory = optarg;
                break;
            case '?':
                /** getopt_long already printed an error message **/
                break;
            default:
                show_help();
        }
    }
    /** On incorrect case **/
    if (optind < argc) {
        printf("You must specify mode.\n");
        show_help();
    } else {
        /** Checking for files queue **/
        if (files_count > 0) {
            /** Sending all the files **/
            send_files(files, files_count, host);
        } else {
            /** Loading files only **/
            load_file(directory, host);
        }
    }
    return EXIT_SUCCESS;
}
Exemplo n.º 15
0
Arquivo: main.c Projeto: OPSF/uClinux
/*
 * This is called once the connection has been negotiated.  It is used
 * for rsyncd, remote-shell, and local connections.
 */
int client_run(int f_in, int f_out, pid_t pid, int argc, char *argv[])
{
	struct file_list *flist = NULL;
	int status = 0, status2 = 0;
	char *local_name = NULL;

	cleanup_child_pid = pid;
	if (!read_batch) {
		set_nonblocking(f_in);
		set_nonblocking(f_out);
	}

	io_set_sock_fds(f_in, f_out);
	setup_protocol(f_out,f_in);

	if (protocol_version >= 23 && !read_batch)
		io_start_multiplex_in();

	/* We set our stderr file handle to blocking because ssh might have
	 * set it to non-blocking.  This can be particularly troublesome if
	 * stderr is a clone of stdout, because ssh would have set our stdout
	 * to non-blocking at the same time (which can easily cause us to lose
	 * output from our print statements).  This kluge shouldn't cause ssh
	 * any problems for how we use it.  Note also that we delayed setting
	 * this until after the above protocol setup so that we know for sure
	 * that ssh is done twiddling its file descriptors.  */
	set_blocking(STDERR_FILENO);

	if (am_sender) {
		keep_dirlinks = 0; /* Must be disabled on the sender. */
		io_start_buffering_out();
		if (!filesfrom_host)
			set_msg_fd_in(f_in);
		send_filter_list(f_out);
		if (filesfrom_host)
			filesfrom_fd = f_in;

		if (write_batch && !am_server)
			start_write_batch(f_out);
		flist = send_file_list(f_out, argc, argv);
		set_msg_fd_in(-1);
		if (verbose > 3)
			rprintf(FINFO,"file list sent\n");
		the_file_list = flist;

		io_flush(NORMAL_FLUSH);
		send_files(flist,f_out,f_in);
		io_flush(FULL_FLUSH);
		handle_stats(-1);
		if (protocol_version >= 24)
			read_final_goodbye(f_in, f_out);
		if (pid != -1) {
			if (verbose > 3)
				rprintf(FINFO,"client_run waiting on %d\n", (int) pid);
			io_flush(FULL_FLUSH);
			wait_process(pid, &status);
		}
		output_summary();
		io_flush(FULL_FLUSH);
		exit_cleanup(status);
	}

	if (need_messages_from_generator && !read_batch)
		io_start_multiplex_out();

	if (argc == 0)
		list_only |= 1;

	send_filter_list(read_batch ? -1 : f_out);

	if (filesfrom_fd >= 0) {
		io_set_filesfrom_fds(filesfrom_fd, f_out);
		filesfrom_fd = -1;
	}

	if (write_batch && !am_server)
		start_write_batch(f_in);
	flist = recv_file_list(f_in);
	the_file_list = flist;

	if (flist && flist->count > 0) {
		local_name = get_local_name(flist, argv[0]);

		status2 = do_recv(f_in, f_out, flist, local_name);
	} else {
		handle_stats(-1);
		output_summary();
	}

	if (pid != -1) {
		if (verbose > 3)
			rprintf(FINFO,"client_run2 waiting on %d\n", (int) pid);
		io_flush(FULL_FLUSH);
		wait_process(pid, &status);
	}

	return MAX(status, status2);
}
Exemplo n.º 16
0
Arquivo: main.c Projeto: OPSF/uClinux
static void do_server_sender(int f_in, int f_out, int argc,char *argv[])
{
	int i;
	struct file_list *flist;
	char *dir = argv[0];

	if (verbose > 2) {
		rprintf(FINFO, "server_sender starting pid=%ld\n",
			(long)getpid());
	}

	if (am_daemon && lp_write_only(module_id)) {
		rprintf(FERROR, "ERROR: module is write only\n");
		exit_cleanup(RERR_SYNTAX);
		return;
	}
	if (am_daemon && lp_read_only(module_id) && remove_sent_files) {
		rprintf(FERROR,
		    "ERROR: --remove-sent-files cannot be used with a read-only module\n");
		exit_cleanup(RERR_SYNTAX);
		return;
	}

	if (!relative_paths && !push_dir(dir)) {
		rsyserr(FERROR, errno, "push_dir#3 %s failed",
			full_fname(dir));
		exit_cleanup(RERR_FILESELECT);
	}
	argc--;
	argv++;

	if (strcmp(dir,".")) {
		int l = strlen(dir);
		if (strcmp(dir,"/") == 0)
			l = 0;
		for (i = 0; i < argc; i++)
			argv[i] += l+1;
	}

	if (argc == 0 && (recurse || list_only)) {
		argc = 1;
		argv--;
		argv[0] = ".";
	}

	flist = send_file_list(f_out,argc,argv);
	if (!flist || flist->count == 0) {
		exit_cleanup(0);
	}
	the_file_list = flist;

	io_start_buffering_in();
	io_start_buffering_out();

	send_files(flist,f_out,f_in);
	io_flush(FULL_FLUSH);
	handle_stats(f_out);
	if (protocol_version >= 24)
		read_final_goodbye(f_in, f_out);
	io_flush(FULL_FLUSH);
	exit_cleanup(0);
}