Example #1
0
int main(object me, string arg)
{
	string target, item;
	object obj, dest, *inv, obj2;
	int i, amount;

	if(!arg) return notify_fail("��Ҫ��ʲ�ᶫ���Ž����\n");

	if( sscanf(arg, "%s in %s", item, target)!=2 )
		return notify_fail("��Ҫ��˭ʲ�ᶫ����\n");

	dest = present(target, me);
	if( !dest || living(dest) ) dest = present(target, environment(me));
	if( !dest || living(dest) )
		return notify_fail("����û������������\n");

	if(sscanf(item, "%d %s", amount, item)==2) {
		if( !objectp(obj = present(item, me)) )
			return notify_fail("������û������������\n");
		if( !obj->query_amount() )
			return notify_fail( obj->name() + "���ܱ��ֿ���\n");
		if( amount < 1 )
			return notify_fail("����������������һ����\n");
		if( amount > obj->query_amount() )
			return notify_fail("��û��������" + obj->name() + "��\n");
		else if( amount == (int)obj->query_amount() )
			return do_put(me, obj, dest);
		else {
				obj2 = new(base_name(obj));
				obj2->set_amount(amount);
							obj2->set_name(obj->query("name"),obj->parse_command_id_list());
			obj2->set("long",obj->query("long"));
			obj2->set("unit",obj->query("unit"));

				if (do_put(me, obj2, dest))
				{
					obj->set_amount( (int)obj->query_amount() - amount );
					return 1;
				}		
				if (obj2) destruct(obj2);
				return 0;
		}
	}

	if(item=="all") {
		inv = all_inventory(me);
		for(i=0; i<sizeof(inv); i++)
			if( inv[i] != dest  && !inv[i]->query("no_drop")) 
			do_put(me, inv[i], dest);
		write("Ok.\n");
		return 1;
	}

	if(!objectp(obj = present(item, me)))
		return notify_fail("������û������������\n");
	return do_put(me, obj, dest);
}
Example #2
0
int main(object me, string arg)
{
        string target, item;
        object obj, dest, *inv, obj2;
        int i, amount;

        if(!arg) return notify_fail("你要将什么东西放进哪里?\n");

        if( sscanf(arg, "%s in %s", item, target)!=2 )
                return notify_fail("你要给谁什么东西?\n");

        dest = present(target, me);
        if( !dest || living(dest) ) dest = present(target, environment(me));
        if( !dest || living(dest) )
                return notify_fail("这里没有这样东西。\n");

        if(sscanf(item, "%d %s", amount, item)==2) {
                if( !objectp(obj = present(item, me)) )
                        return notify_fail("你身上没有这样东西。\n");
                if( obj->query("no_put") )
                        return notify_fail("这东西不能丢。\n");
                if( !obj->query_amount() )
                        return notify_fail( obj->name() + "不能被分开。\n");
                if( amount < 1 )
                        return notify_fail("东西的数量至少是一个。\n");
                if( amount > obj->query_amount() )
                        return notify_fail("你没有那么多的" + obj->name() + "。\n");
                else if( amount == (int)obj->query_amount() )
                        return do_put(me, obj, dest);
                else {
                        obj->set_amount( (int)obj->query_amount() - amount );
                        obj2 = new(base_name(obj));
                        obj2->set_amount(amount);
                        return do_put(me, obj2, dest);
                }
        }

        if(item=="all") {
                inv = all_inventory(me);
                for(i=0; i<sizeof(inv); i++) {
                if (inv[i]->query("no_put"))
                        return notify_fail("这东西不能丢。\n");
                        if( inv[i] != dest ) do_put(me, inv[i], dest);
                }
                write("Ok.\n");
                return 1;
        }

        if(!objectp(obj = present(item, me)))
                return notify_fail("你身上没有这样东西。\n");
        if( obj->query("no_put") )
                return notify_fail("这东西不能丢。\n");
        return do_put(me, obj, dest);
}
Example #3
0
static void
server_callback (SoupServer *server, SoupMessage *msg,
		 const char *path, GHashTable *query,
		 SoupClientContext *context, gpointer data)
{
	char *file_path;
	SoupMessageHeadersIter iter;
	const char *name, *value;

	g_print ("%s %s HTTP/1.%d\n", msg->method, path,
		 soup_message_get_http_version (msg));
	soup_message_headers_iter_init (&iter, msg->request_headers);
	while (soup_message_headers_iter_next (&iter, &name, &value))
		g_print ("%s: %s\n", name, value);
	if (msg->request_body->length)
		g_print ("%s\n", msg->request_body->data);

	file_path = g_strdup_printf (".%s", path);

	if (msg->method == SOUP_METHOD_GET || msg->method == SOUP_METHOD_HEAD)
		do_get (server, msg, file_path);
	else if (msg->method == SOUP_METHOD_PUT)
		do_put (server, msg, file_path);
	else
		soup_message_set_status (msg, SOUP_STATUS_NOT_IMPLEMENTED);

	g_free (file_path);
	g_print ("  -> %d %s\n\n", msg->status_code, msg->reason_phrase);
}
Example #4
0
num_put<Pt::Char, ostreambuf_iterator<Pt::Char> >::iter_type
num_put<Pt::Char, ostreambuf_iterator<Pt::Char> >::do_put(iter_type s, ios_base& f, char_type fill, bool val) const
{
    if( 0 == (f.flags() & ios_base::boolalpha) )
        return do_put(s, f, fill, static_cast<long>(val));
    
    typedef Pt::Char char_type;
    const numpunct<char_type>& np = use_facet< numpunct<char_type> >( f.getloc() );
 
    Pt::String str = val ? np.truename() : np.falsename();
 
    streamsize width = f.width(0);
   
    if( str.size() >= static_cast<std::size_t>(width) )
    {
        return std::copy(str.begin(), str.end(), s);
    }

    streamsize pad = width - str.size();
    ios_base::fmtflags dir = f.flags() & ios_base::adjustfield;

    if (dir == ios_base::left) 
    {
       std::copy(str.begin(), str.end(), s);
       std::fill_n(s, pad, fill);
       return s;
    }

    // right/internal padding 
    std::fill_n(s, pad, fill);
    return std::copy(str.begin(), str.end(), s);
}
Example #5
0
void* func_msg(void* arg)
{
	struct thread_info* args = arg;
//	struct sockaddr_in client;
	int sock = args->sock;
	int read_n, errcnt = 0;
	ftp_rqt request;


//	printf("in thread\n");
//	fprintf(stderr, "sock: %d\n", sock);
	while (true) {

		memset(&request, 0, RQT_LEN);
		read_n = recv(sock, (char*)&request, RQT_LEN, 0);

		if (read_n < 0) {
			errcnt ++;
			if (errcnt > 10)
				break ;
			continue ;
		}
		if (read_n == 0) {
			fprintf(stderr, "quit");
			break ; 
		}

	//	printf("msg: %d; read_n: %d\n", request.type, read_n);

		if (request.type == CMD_CLOSE)
			break;

		else if (request.type == CMD_CD) 
			do_chdir(&request, sock);

		else if (request.type == CMD_MKDIR)
			do_mkdir(&request, sock);

		else if (request.type == CMD_RMDIR)
			do_rmdir(&request, sock);

		else if (request.type == CMD_LS)
			do_lsdir(&request, sock);

		else if (request.type == CMD_GET) {
			do_get(&request, sock);
			break;
		}

		else if (request.type == CMD_PUT) {
			printf("put\n");
			do_put(&request, sock);
			break;
		}

//		send(sock, CONFIRM, strlen(CONFIRM)+1, 0);
	}

	thread_end(args);
}
Example #6
0
_OutputIter
time_put<_Ch,_OutputIter>::put(_OutputIter __s, ios_base& __f, _Ch __fill,
			       const tm* __tmb,
			       const _Ch* __pat, const _Ch* __pat_end) const 
{
  //  locale __loc = __f.getloc();
  //  const ctype<_Ch>& _Ct = use_facet<ctype<_Ch> >(__loc); 
  const ctype<_Ch>& _Ct = *(ctype<_Ch>*)__f._M_ctype_facet(); 
  while (__pat != __pat_end) {
    char __c = _Ct.narrow(*__pat, 0);
    if (__c == '%') {
      char __mod = 0;
      ++__pat;
      __c = _Ct.narrow(*__pat++, 0);
      if(__c == '#') { // MS extension
        __mod = __c;
        __c = _Ct.narrow(*__pat++, 0);
      }
      __s = do_put(__s, __f, __fill, __tmb, __c, __mod);
    }
    else
      *__s++ = *__pat++;
  }
  return __s;
}
    void put_1d_data_helper<MV,S>::do_put(const Teuchos::Ptr<MV>& mv,
					  const Teuchos::ArrayView<S>& data,
					  const size_t ldx)
    {
      const Teuchos::RCP<const Tpetra::Map<typename MV::local_ordinal_t,
	typename MV::global_ordinal_t,
	typename MV::node_t> > map
	= mv->getMap();
      do_put(mv, data, ldx, Teuchos::ptrInArg(*map));
    }
Example #8
0
// Common function to handle all system calls -
// decode the system call type and call an appropriate handler function.
// Be sure to handle undefined system calls appropriately.
void
syscall(trapframe *tf)
{
	// EAX register holds system call command/flags
	uint32_t cmd = tf->regs.eax;
	switch (cmd & SYS_TYPE) {
  	case SYS_CPUTS:	return do_cputs(tf, cmd);
  	case SYS_PUT: return do_put(tf, cmd);
  	case SYS_GET: return do_get(tf, cmd);
  	case SYS_RET: return do_ret(tf, cmd);
  	default:	return;		// handle as a regular trap
	}
}
Example #9
0
int main (int argc, char *argv[]) {
    if (argc < 2) {
        print_doc(argv[0]);
        return EINVAL;
    }

    if (strncmp(argv[1],"put",3) == 0) {
        if (argc < 4) {
            print_doc(argv[0]);
            return EINVAL;
        }
        const char *key = argv[2];
        const char *src = argv[3];
        return do_put(key, src);
    } else if (strncmp(argv[1], "get", 3) == 0) {
        if (argc < 4) {
            print_doc(argv[0]);
            return EINVAL;
        }
        const char *key = argv[2];
        const char *outpath = argv[3];
        return do_get(key, outpath);
    } else if (strncmp(argv[1], "remove", 6) == 0) {
        if (argc < 3) {
            print_doc(argv[0]);
            return EINVAL;
        }
        const char *key = argv[2];
        return do_remove(key);
    } else if (strncmp(argv[1], "search", 6) == 0) {
        if (argc < 4) {
            print_doc(argv[0]);
            return EINVAL;
        }
        const char *key = argv[2];
        const char *outpath = argv[3];
        return do_search(key, outpath);
    } else if (strncmp(argv[1], "stat", 4) == 0) {
        if (argc < 3) {
            print_doc(argv[0]);
            return EINVAL;
        }
        const char *key = argv[2];
        return do_stat(key);
    } else {
        print_doc(argv[0]);
        return EINVAL;
    }

    return 0;
}
Example #10
0
/**
 * Process the next incoming request
 *
 * @return status response
 */
status_t process_req() {
    msg_t *msg = malloc(sizeof(msg_t));
    resp_t *resp = NULL;

    if (!EREADDATA(*msg)) {
        debug("Disconnected!\n");
        return DISCON;
    }

    msg->buf[sizeof(msg->buf)-1] = '\0';

    switch (msg->type) {
    case MKDIR:
        resp = do_mkdir(msg);
        break;
    case LIST:
        resp = do_list(msg);
        break;
    case PUT:
        resp = do_put(msg);
        break;
    case GET:
        resp = do_get(msg);
        break;
    case RM:
        resp = do_rm(msg);
        break;
    case RMDIR:
        resp = do_rmdir(msg);
        break;
    case QUIT:
        return EXIT;
    default:
        return ERR;
    }

    if (!resp)
        return ERR;

    ESENDDATA(*resp);

    if (last)
        free(last);

    last = (char *)resp;

    return OK;
}
    void put_1d_data_helper<MV,S>::do_put(const Teuchos::Ptr<MV>& mv,
					  const Teuchos::ArrayView<S>& data,
					  const size_t ldx,
					  EDistribution distribution,  typename MV::global_ordinal_t indexBase)
    {
      typedef typename MV::local_ordinal_t lo_t;
      typedef typename MV::global_ordinal_t go_t;
      typedef typename MV::global_size_t gs_t;
      typedef typename MV::node_t node_t;
      
      const Teuchos::RCP<const Tpetra::Map<lo_t,go_t,node_t> > map
	= Amesos2::Util::getDistributionMap<lo_t,go_t,gs_t,node_t>(distribution,
								   mv->getGlobalLength(),
								   mv->getComm(), indexBase);
      do_put(mv, data, ldx, Teuchos::ptrInArg(*map));
    }
Example #12
0
File: file.c Project: 50wu/gpdb
Datum
utl_file_put_line(PG_FUNCTION_ARGS)
{
	FILE   *f;
	bool	autoflush;

	f = do_put(fcinfo);

	autoflush = PG_GETARG_IF_EXISTS(2, BOOL, false);

	do_new_line(f, 1);

	if (autoflush)
		do_flush(f);

	PG_RETURN_BOOL(true);
}
Example #13
0
static void
server_callback (SoupServer *server, SoupMessage *msg,
		 const char *path, GHashTable *query,
		 SoupClientContext *context, gpointer data)
{
	SoupMessageHeadersIter iter;

	soup_message_headers_iter_init (&iter, msg->request_headers);


	if (msg->method == SOUP_METHOD_GET || msg->method == SOUP_METHOD_HEAD)
		do_get (server, msg, path);
	else if (msg->method == SOUP_METHOD_PUT)
		do_put (server, msg, path);
	else
		soup_message_set_status (msg, SOUP_STATUS_NOT_IMPLEMENTED);
}
Example #14
0
int init (int argc, char *argv[])
{
    char    *p;
    int     rc = 0, oldmode;
    url_t   u;
    int     x0=-1, y0=-1, r=-1, c=-1;
    struct hostent     *remote;
    char    buffer[MAX_PATH];

    if (action == ACTION_TESTONLY) exit (0);
    if (action == ACTION_BADAGS)
    {
        usage ();
        exit (1);
    }

    if (options.keep_winsize)
    {
        r = cfg_get_integer (CONFIG_NFTP, fl_opt.platform_nick, "rows");
        c = cfg_get_integer (CONFIG_NFTP, fl_opt.platform_nick, "cols");
        if (r == 0 && c == 0) r = -1, c = -1;
    }

    if (options.keep_winpos)
    {
        x0 = cfg_get_integer (CONFIG_NFTP, fl_opt.platform_nick, "x0");
        y0 = cfg_get_integer (CONFIG_NFTP, fl_opt.platform_nick, "y0");
        if (x0 == 0 || y0 == 0) x0 = -1, y0 = -1;
    }

    p = cfg_get_string (CONFIG_NFTP, fl_opt.platform_nick, "font");
    if (p[0] == '\0') p = NULL;

    fly_init (x0, y0, r, c, p);
    if (options.show_hw_cursor) video_cursor_state (1);
    fly_mouse (options.mouse);
    wintitle = get_window_name ();

    if (fl_opt.platform == PLATFORM_OS2_VIO)
    {
        strcpy (buffer, paths.system_libpath);
        str_cats (buffer, "nftp.ico");
        if (access (buffer, R_OK) == 0)
            set_icon (buffer);
    }

    if (main_menu != NULL)
    {
        menu_activate (main_menu);
        adjust_menu_status ();
    }
    
    display.dir_mode = options.defaultdirmode;
    display.view_mode = VIEW_CONTROL;
    
    display.rshift = 0;
    display.lshift = 0;
    display.tabsize = 8;
    if (options.slowlink)
        set_view_mode (VIEW_REMOTE);
    else
        set_view_mode (VIEW_CONTROL);
    site.maxndir = 1024;
    site.dir = malloc (sizeof(directory)*site.maxndir);

    // ignore "broken PIPE" signals
    signal (SIGPIPE, SIG_IGN);

    set_window_name ("NFTP%s(C) Copyright Sergey Ayukov", NFTP_VERSION);

    local.dir.files = NULL;
    local.sortmode = abs (options.default_localsort);
    if (options.default_localsort >= 0)
        local.sortdirection = 1;
    else
        local.sortdirection = -1;
    build_local_filelist (NULL);

    site.batch_mode = FALSE;
    site.chunks = NULL;

    PutLineIntoResp2 ("NFTP Version%s(%s, %s) -- %s", NFTP_VERSION, __DATE__, __TIME__, fl_opt.platform_name);
    PutLineIntoResp1 ("Copyright (C) 1994-2003 Sergey Ayukov <*****@*****.**>");
    PutLineIntoResp1 ("Portions Copyright (C) Eric Young <*****@*****.**>");
    //PutLineIntoResp1 ("Portions Copyright (C) Martin Nicolay <*****@*****.**>");
    status.usage_interval = 0;
    if (!fl_opt.has_osmenu)
        PutLineIntoResp1 (M("Press F9 or Ctrl-F for menu"));
    update (1);

    if (options.firewall_type != 0)
    {
        if (options.fire_server[0] == '\0')
        {
            fly_ask_ok (ASK_WARN, M("Firewall proxy host isn't specified in NFTP.INI"));
            options.firewall_type = 0;
        }
        else
        {
            if (strspn (options.fire_server, " .0123456789") == strlen (options.fire_server))
            {
                firewall.fwip = inet_addr (options.fire_server);
            }
            else
            {
                PutLineIntoResp2 (M("Looking up '%s'"), options.fire_server);
                remote = gethostbyname (options.fire_server);
                if (remote == NULL)
                {
                    PutLineIntoResp2 (M("Cannot find '%s'"), options.fire_server);
                    options.firewall_type = 0;
                }
                else
                {
                    firewall.fwip = *((unsigned long *)(remote->h_addr));
                    PutLineIntoResp2 (M("Found '%s'"), remote->h_name);
                }
            }
        }
    }

    // read password cache
    psw_read ();
        
    // analyze arguments
    switch (action)
    {
    case 0:
        if (options.download_path != NULL)
        {
            set_local_path (options.download_path);
        }
        else
        {
            p = cfg_get_string (CONFIG_NFTP, "", "local-directory");
            if (p[0] != '\0')
                set_local_path (p);
        }
        build_local_filelist (NULL);
        switch (options.start_prompt)
        {
        case 1:  return FMSG_BASE_MENU + KEY_GEN_LOGIN;
        case 2:  return FMSG_BASE_MENU + KEY_GEN_BOOKMARKS;
        case 3:  return FMSG_BASE_MENU + KEY_GEN_HISTORY;
        case 5:  return FMSG_BASE_MENU + KEY_MENU;
        }
        return 0;
        
    case ACTION_DOWNLOAD:
    case ACTION_UPLOAD:
        oldmode = site.batch_mode;
        site.batch_mode = TRUE;
        if (action == ACTION_DOWNLOAD) rc = do_get (optarg1);
        if (action == ACTION_UPLOAD) rc = do_put (optarg1);
        //set_view_mode (VIEW_CONTROL);
        //update (1);
        if (rc && !cmdline.batchmode)
            fly_ask_ok (0, M("Transfer of '%s' has failed"), optarg1);
        if ((disc_after && rc == 0) || cmdline.batchmode)
        {
            Logoff ();
            terminate ();
            exit (0);
        }
        site.batch_mode = oldmode;
        return 0;

    case ACTION_CMDLIST:
        rc = runscript (optarg1);
        return 0;

    case ACTION_NICK_BOOK:
    case ACTION_NICK_HIST:
        if (action == ACTION_NICK_BOOK && bookmark_nickname (optarg1, &u) == 0) return 0;
        if (action == ACTION_NICK_HIST && history_nickname (optarg1, &u) == 0) return 0;
        rc = Login (&u);
        if (rc) return 0;
        if (options.login_bell) Bell (3);
        return 0;

    case ACTION_OPEN_BOOKMARKS:
        return FMSG_BASE_MENU + KEY_GEN_BOOKMARKS;
        
    case ACTION_OPEN_HISTORY:
        return FMSG_BASE_MENU + KEY_GEN_HISTORY;

    case ACTION_LOGIN:
        // if download_path was specified in nftp.ini, set it now
        if (options.download_path != NULL)
            set_local_path (options.download_path);
        build_local_filelist (NULL);
        parse_url (optarg1, &u);
        rc = Login (&u);
        // attempt to download file if chdir failed
        /*if (site.set_up && strcmp (site.u.pathname, RCURDIR.name) != 0)
        {
            rc = do_get (optarg1);
        }
        if (rc) return 0;
        */
        if (options.login_bell) Bell (3);
        return 0;

    case ACTION_TESTONLY:
        terminate ();
        exit (0);
    }
    fly_error ("internal error in init()");
    return 0;
}
 /// Store an item.
 void put(std::shared_ptr<const Base> item) override { do_put(*item); }
Example #16
0
 virtual Out do_put(Out const i, IB & io, Ch const fill, long long const v) const
 { return io.flags() & IB::basefield ? base::do_put(i, io, fill, v) : do_put(i, io, fill, I(v)); }
Example #17
0
 virtual Out do_put(Out const i, IB & io, Ch const fill, long const v) const
 {
   unsigned long const w = v;
   return io.flags() & IB::basefield ? base::do_put(i, io, fill, v) : do_put(i, io, fill, w);
 }
Example #18
0
int
main (int argc, char **argv)
{
	MsOle *ole;
	int lp, exit = 0, interact = 0;
	char *buffer = g_new (char, 1024) ;

	if (argc<2)
		syntax_error(0);

	if (!g_strcasecmp (argv [1], "regression")) {
		do_regression_tests ();
		return 0;
	}

	printf ("Ole file '%s'\n", argv[1]);
	if (ms_ole_open_vfs (&ole, argv[1], TRUE, NULL)
	    != MS_OLE_ERR_OK) {
		printf ("Creating new file '%s'\n", argv[1]);
		if (ms_ole_create_vfs (&ole, argv[1], TRUE, NULL)
		    != MS_OLE_ERR_OK)
			syntax_error ("Can't open file or create new one");
	}

	if (argc<=2)
		syntax_error ("Need command or -i");

	if (argc>2 && argv[argc-1][0]=='-'
	    && argv[argc-1][1]=='i') 
		interact=1;
	else {
		char *str=g_strdup(argv[2]) ;
		for (lp=3;lp<argc;lp++)
			str = g_strconcat(str," ",argv[lp],NULL); /* FIXME Mega leak :-) */
		buffer = str; /* and again */
	}

	cur_dir = g_strdup ("/");

	do
	{
		char *ptr;

		if (interact) {
			fprintf (stdout,"> ");
			fflush (stdout);
			fgets (buffer, 1023, stdin);
		}

		arg_data = g_strsplit (g_strchomp (buffer), delim, -1);
		arg_cur  = 0;
		if (!arg_data && interact) continue;
		if (!interact)
			printf ("Command : '%s'\n", arg_data[0]);
		ptr = arg_data[arg_cur++];
		if (!ptr)
			continue;

		if (g_strcasecmp (ptr, "ls") == 0)
			list_files (ole);
		else if (g_strcasecmp (ptr, "cd") == 0)
			enter_dir (ole);
		else if (g_strcasecmp (ptr, "dump") == 0)
			do_dump (ole);
		else if (g_strcasecmp (ptr, "biff") == 0)
			do_biff (ole);
		else if (g_strcasecmp (ptr, "biffraw") == 0)
			do_biff_raw (ole);
		else if (g_strcasecmp (ptr, "get") == 0)
			do_get (ole);
		else if (g_strcasecmp (ptr, "put") == 0)
			do_put (ole);
		else if (g_strcasecmp (ptr, "copyin") == 0)
			do_copyin (ole);
		else if (g_strcasecmp (ptr, "copyout") == 0)
			do_copyout (ole);
		else if (g_strcasecmp (ptr, "summary") == 0)
			do_summary (ole);
		else if (g_strcasecmp (ptr, "docsummary") == 0)
			do_docsummary (ole);
		else if (g_strcasecmp (ptr, "debug") == 0)
			ms_ole_debug (ole, 1);
		else if (g_strcasecmp (ptr, "tree") == 0)
			ms_ole_debug (ole, 2);
		else if (g_strcasecmp (ptr, "vba") == 0)
			dump_vba (ole);
		else if (g_strcasecmp (ptr, "help") == 0 ||
			 g_strcasecmp (ptr, "?") == 0 ||
			 g_strcasecmp (ptr, "info") == 0 ||
			 g_strcasecmp (ptr, "man") == 0)
			list_commands ();
		else if (g_strcasecmp (ptr, "exit") == 0 ||
			 g_strcasecmp (ptr, "quit") == 0 ||
			 g_strcasecmp (ptr, "q") == 0 ||
			 g_strcasecmp (ptr, "bye") == 0)
			exit = 1;
	}
	while (!exit && interact);

	ms_ole_destroy (&ole);
	return 0;
}
Example #19
0
int init (int argc, char *argv[])
{
    char    *p;
    int     rc = 0, oldmode, i;
    url_t   u;
    int     x0=-1, y0=-1, r=-1, c=-1;
    struct hostent     *remote;
    char    buffer[MAX_PATH];

    if (action == ACTION_TESTONLY) exit (0);
    if (action == ACTION_BADARGS)
    {
        usage ();
        exit (1);
    }

    if (options.keep_winsize)
    {
        r = cfg_get_integer (CONFIG_NFTP, fl_opt.platform_nick, "rows");
        c = cfg_get_integer (CONFIG_NFTP, fl_opt.platform_nick, "cols");
        if (r == 0 && c == 0) r = -1, c = -1;
    }

    if (options.keep_winpos)
    {
        x0 = cfg_get_integer (CONFIG_NFTP, fl_opt.platform_nick, "x0");
        y0 = cfg_get_integer (CONFIG_NFTP, fl_opt.platform_nick, "y0");
        if (x0 == 0 || y0 == 0) x0 = -1, y0 = -1;
    }

    p = cfg_get_string (CONFIG_NFTP, fl_opt.platform_nick, "font");
    if (p[0] == '\0') p = NULL;

    fly_init (x0, y0, r, c, p);
    fly_mouse (options.mouse);
    wintitle = get_window_name ();

    if (fl_opt.platform == PLATFORM_OS2_VIO)
    {
        strcpy (buffer, paths.system_libpath);
        str_cats (buffer, "nftp.ico");
        if (access (buffer, R_OK) == 0)
            set_icon (buffer);
    }

    if (main_menu != NULL)
    {
        menu_activate (main_menu);
    }

    display.rshift = 0;
    display.lshift = 0;
    display.tabsize = 8;
    display.view[V_LEFT] = -1;
    display.view[V_RIGHT] = -1;
    display.cursor = V_LEFT;
    display.parsed = TRUE;

    for (i=0; i<MAX_SITE; i++)
    {
        site[i].set_up = FALSE;
        site[i].CC.na = 0;
        site[i].CC.n = 0;
    }

    // ignore "broken PIPE" signals
    signal (SIGPIPE, SIG_IGN);

    set_window_name ("NFTP%s(C) Copyright Sergey Ayukov", NFTP_VERSION);

    lcache.lda = 0;
    lcache.ld  = 0;
    lcache.L   = NULL;

    local[V_LEFT].dir.name = NULL;
    local[V_LEFT].dir.files = NULL;
    local[V_LEFT].dir.nfiles = 0;
    local[V_LEFT].sortmode = abs (options.default_localsort);
    if (options.default_localsort >= 0)
        local[V_LEFT].sortdirection = 1;
    else
        local[V_LEFT].sortdirection = -1;
    l_chdir (V_LEFT, NULL);

    local[V_RIGHT].dir.name = NULL;
    local[V_RIGHT].dir.files = NULL;
    local[V_RIGHT].dir.nfiles = 0;
    local[V_RIGHT].sortmode = abs (options.default_localsort);
    if (options.default_localsort >= 0)
        local[V_RIGHT].sortdirection = 1;
    else
        local[V_RIGHT].sortdirection = -1;
    l_chdir (V_RIGHT, NULL);


    PutLineIntoResp (RT_COMM, 0, "NFTP Version%s(%s, %s) -- %s", NFTP_VERSION, __DATE__, __TIME__, fl_opt.platform_name);
    PutLineIntoResp (RT_RESP, 0, "Copyright (C) 1994--2000 Sergey Ayukov <*****@*****.**>");
    PutLineIntoResp (RT_RESP, 0, "Portions Copyright (C) Eric Young <*****@*****.**>");
    status.usage_interval = 0;
    if (!fl_opt.has_osmenu)
        PutLineIntoResp (RT_RESP, 0, MSG(M_RESP_F9_FOR_MENU));
    update (1);

    if (options.firewall_type != 0)
    {
        if (options.fire_server[0] == '\0')
        {
            fly_ask_ok (ASK_WARN, MSG(M_PROXY_ISNT_SPECIFIED));
            options.firewall_type = 0;
        }
        else
        {
            if (strspn (options.fire_server, " .0123456789") == strlen (options.fire_server))
            {
                firewall.fwip = inet_addr (options.fire_server);
            }
            else
            {
                PutLineIntoResp (RT_COMM, 0, MSG(M_RESP_LOOKING_UP), options.fire_server);
                remote = gethostbyname (options.fire_server);
                if (remote == NULL)
                {
                    PutLineIntoResp (RT_COMM, 0, MSG(M_RESP_CANNOT_RESOLVE), options.fire_server);
                    options.firewall_type = 0;
                }
                else
                {
                    firewall.fwip = *((unsigned long *)(remote->h_addr));
                    PutLineIntoResp (RT_COMM,0, MSG(M_RESP_FOUND), remote->h_name);
                }
            }
        }
    }

    // read password cache
    psw_read ();

    // analyze arguments
    switch (action)
    {
    case ACTION_NONE:
        if (options.download_path != NULL)
        {
            l_chdir (V_RIGHT, options.download_path);
        }
        else
        {
            p = cfg_get_string (CONFIG_NFTP, "", "local-directory-left");
            if (p[0] != '\0')
            {
                l_chdir (V_LEFT, p);
            }
            p = cfg_get_string (CONFIG_NFTP, "", "local-directory-right");
            if (p[0] != '\0')
            {
                l_chdir (V_RIGHT, p);
            }
        }
        switch (options.start_prompt)
        {
        case 1:  return FMSG_BASE_MENU + KEY_GEN_LOGIN;
        case 2:  return FMSG_BASE_MENU + KEY_GEN_BOOKMARKS;
        case 3:  return FMSG_BASE_MENU + KEY_GEN_HISTORY;
        case 5:  return FMSG_BASE_MENU + KEY_MENU;
        }
        return 0;

    case ACTION_DOWNLOAD:
    case ACTION_UPLOAD:
        oldmode = status.batch_mode;
        status.batch_mode = TRUE;
        if (action == ACTION_DOWNLOAD) rc = do_get (optarg1);
        if (action == ACTION_UPLOAD) rc = do_put (optarg1);
        //set_view_mode (VIEW_CONTROL);
        //update (1);
        if (rc && !cmdline.batchmode) fly_ask_ok (0, MSG(M_TRANSFER_FAILED), optarg1);
        if ((disc_after && rc == 0) || cmdline.batchmode)
        {
            Logoff (0);
            terminate ();
            exit (0);
        }
        status.batch_mode = oldmode;
        return 0;

    //case ACTION_CMDLIST:
    //    rc = runscript (optarg1);
    //    return 0;

    case ACTION_NICK_BOOK:
    case ACTION_NICK_HIST:
        if (action == ACTION_NICK_BOOK && bookmark_nickname (optarg1, &u) == 0) return 0;
        if (action == ACTION_NICK_HIST && history_nickname (optarg1, &u) == 0) return 0;
        rc = Login (-1, &u, V_LEFT);
        if (rc) return 0;
        if ((action == ACTION_NICK_BOOK && MAX_SITE > 1 && optarg2 != NULL &&
             bookmark_nickname (optarg2, &u) == 1) ||
            (action == ACTION_NICK_HIST && MAX_SITE > 1 && optarg2 != NULL &&
             history_nickname (optarg2, &u) == 1))
        {
            rc = Login (-1, &u, V_RIGHT);
        }
        if (options.login_bell) Bell (3);
        return 0;

    case ACTION_OPEN_BOOKMARKS:
        return FMSG_BASE_MENU + KEY_GEN_BOOKMARKS;

    case ACTION_OPEN_HISTORY:
        return FMSG_BASE_MENU + KEY_GEN_HISTORY;

    case ACTION_LOGIN:
        // if download_path was specified in nftp.ini, set it now
        if (options.download_path != NULL)
        {
            l_chdir (V_LEFT, options.download_path);
            l_chdir (V_RIGHT, options.download_path);
        }
        dmsg ("optarg1 is [%s]\n", optarg1);
        parse_url (optarg1, &u);
        rc = Login (-1, &u, V_LEFT);
        if (MAX_SITE > 1 && optarg2 != NULL)
        {
            parse_url (optarg2, &u);
            rc = Login (-1, &u, V_RIGHT);
        }
        // attempt to download file if chdir failed
        /*if (site.set_up && strcmp (site.u.pathname, RCURDIR.name) != 0)
        {
            rc = do_get (optarg1);
        }
        if (rc) return 0;
        */
        if (options.login_bell) Bell (3);
        return 0;

    case ACTION_TESTONLY:
        terminate ();
        exit (0);
    }
    fly_error ("internal error in init()");
    return 0;
}
Example #20
0
int do_put1(char *argv[])
{
    char *args2[] = {argv[0], argv[0]};
    return do_put(args2);
}
Example #21
0
int main(int argc,char *argv[])
{
    char cline[COMMAND_LINE];
    struct command_line command;
    int sock_fd;
    struct sockaddr_in sin;
    printf("myftp$: ");
    fflush(stdout);

    while (fgets(cline,MAX_LINE,stdin) != NULL)
    {
        if (cline[0] == '\n')
        {
            printf("myftp$: ");
            continue;
        }

        if (split(&command,cline) == -1)
        {
            exit(1);
        }

        if (strcasecmp(command.name,"get") == 0)
        {
            if (do_get(command.argv[1],command.argv[2],sock_fd) == -1)
            {
                exit(1);
            }
        } else if (strcasecmp(command.name,"put") == 0)
        {
            if (do_put(command.argv[1],command.argv[2],sock_fd) == -1)
            {
                exit(1);
            }
        } else if (strcasecmp(command.name,"cd") == 0)
        {
            if (do_cd(command.argv[1]) == -1)
            {
                exit(1);
            }
        } else if (strcasecmp(command.name,"!cd") == 0)
        {
            if (do_serv_cd(command.argv[1],sock_fd) == -1)
            {
                exit(1);
            }
        } else if (strcasecmp(command.name,"ls") == 0)
        {
            if (do_ls(command.argv[1]) == -1)
            {
                exit(1);
            }
        } else if (strcasecmp(command.name,"!ls") == 0)
        {
            if (do_serv_ls(command.argv[1],sock_fd) == -1)
            {
                exit(1);
            }
        } else if (strcasecmp(command.name,"connect") == 0)
        {
            if (do_connect(command.argv[1],&sin,&sock_fd) == -1)
            {
                exit(1);
            }
        } else if (strcasecmp(command.name,"bye") == 0)
        {
            if (do_bye(sock_fd) == -1)
            {
                exit(1);
            }
            break;
        } else
        {
            printf("wrong command\n");
            printf("usage: command arg1 arg2 ... argn\n");
        }
        printf("myftp$: ");
        fflush(stdout);
    }

    if (close(sock_fd) == -1)
    {
        perror("fail to close");
        exit(1);
    }

    return 0;
}
Example #22
0
int op_entry(request req, char *str, char *database, char *entry) {
  int sock;			/* Socket */
  char tmpstr[DATALEN] = "";
  char *p;
  char db[TABLENAMELEN];
  int status;

  if (strncmp(database, DBPREFIX, strlen(DBPREFIX)) != 0 &&
      strcmp(database, MANAGEMENT) != 0 &&
      strcmp(database, NSDB) != 0) {
    debug_out(2, "Bogus database '%s'\n", database);
    return FALSE;
  }

  if (strcmp(database, MANAGEMENT) != 0 &&
      strcmp(database, NSDB) != 0) { /* Not management or nameserver */
    char *q;			/* temporary pointer */

    p = q = database + strlen(DBPREFIX);

    while (*p && *p >= '0' && *p <= '9') p++;

    /* 12 characters are needed for a text representation of a 32-bit integer */

    /* If a (non-null) character at p, or no digits detected, or name too long */
    if (*p || p == q || strlen(database) > (TABLENAMELEN - 12)) {
      debug_out(2, "Bogus database *'%s'\n", database);
      return FALSE;
    }
  }

  if (strcmp(database, NSDB) != 0) {
    sprintf(db, "%d%s", getuid(), database);
  } else {
    sprintf(db, "%s", database);
  }

  if (io_delay) {
    debug_out(0, "Sleeping for %d seconds\n", io_delay);
    sleep(io_delay); /* Go to sleep for a while */
  }

  sock = setup_port(0, UDP, FALSE);
  if (sock < 0) {
    debug_out(2, "Failed to open port.\n");
    exit(1);
  }
  switch (req) {
  case GET:
    status = do_get(sock, db, entry, tmpstr, NULL);
    if (status == EXISTS) {
      strncpy(str, tmpstr, ARG_SIZE);
      str[ARG_SIZE - 1] = 0;
      close(sock);
      return TRUE;
    }
    break;
  case DEL:
    status = do_del(sock, db, entry, tmpstr, NULL);
    if (status == EXISTS) {
      strncpy(str, tmpstr, ARG_SIZE);
      str[ARG_SIZE - 1] = 0;
      close(sock);
      return TRUE;
    }
    break;
  case PUT:
    strncpy(tmpstr, str, ARG_SIZE);
    status = do_put(sock, db, entry, tmpstr, NULL);
    if (status == NONEXISTENT) {
      strncpy(str, tmpstr, ARG_SIZE);
      str[ARG_SIZE - 1] = 0;
      close(sock);
      return TRUE;
    }
    break;
  case RPL:
    strncpy(tmpstr, str, ARG_SIZE);
    status = do_rpl(sock, db, entry, tmpstr, NULL);
    if (status == REPLACED) {
      strncpy(str, tmpstr, ARG_SIZE);
      str[ARG_SIZE - 1] = 0;
      close(sock);
      return TRUE;
    }
    break;
  }
  close(sock);
  return FALSE;
}
Example #23
0
/* 
   This is a put for char * keys.
   It first strdups the key...
 */
hent_t hash_put(hash_t self, void *vkey)
{
	char *key = vkey;
	return do_put(self, strdup(key));
}
Example #24
0
/* The :insert, :append and :change command */
void do_ins_chg(PTR start, char *arg, int mode)
{
    int base;
    off_t buffer = BUFFER;
    off_t count = 0L;
    size_t len;
    long    val;
    char *tempbuf = NULL;
    char *poi, *epoi;
    if((mode == U_EDIT) && (current - mem >= filesize)) {
        beep();
        return;
    }
    len = strlen(arg);
    if(!strncmp("ascii", arg, len) && CMDLNG(5, 1)) {
        base = 1;
    } else if(!strncmp("binary", arg, len) && CMDLNG(6, 1)) {
        base = 2;
    } else if(!strncmp("octal", arg, len) && CMDLNG(5, 1)) {
        base = 8;
    } else if(!strncmp("decimal", arg, len) && CMDLNG(7, 1)) {
        base = 10;
    } else if(!strncmp("hexadecimal", arg, len) && CMDLNG(11, 1)) {
        base = 16;
    } else {
        emsg("No such option");
        return;
    }
    addch('\n');
    if(getcmdstr(cmdstr, 0) == 1) {
        repaint();
        return;
    }
    if(alloc_buf(buffer, &tempbuf) == 0L) {
        return;
    }
    while(strcmp(cmdstr, ".")) {
        poi = cmdstr;
        if(base == 1) {            /* ASCII */
            while(*poi != '\0') {
                if(*poi == '\\') {
                    switch(*(++poi)) {
                        case 'n':
                            val = '\n';
                            break;
                        case 'r':
                            val = '\r';
                            break;
                        case 't':
                            val = '\t';
                            break;
                        case '0':
                            val = '\0';
                            break;
                        case '\\':
                            val = '\\';
                            break;
                        default :
                            val = '\\';
                            poi--;
                    }
                    poi++;
                } else {
                    val = *poi++;
                }
                *(tempbuf + count++) = val;
            }
        } else {
            while(isspace(cmdstr[strlen(cmdstr) - 1])) {
                cmdstr[strlen(cmdstr) - 1] = '\0';
            }
            while(*poi != '\0') {
                val = strtol(poi, &epoi, base);
                if(val > 255 || val < 0 || poi == epoi) {
                    repaint();
                    emsg("Invalid value");
                    goto mfree;
                }
                poi = epoi;
                *(tempbuf + count++) = val;
            }
        }
        addch('\n');
        if(getcmdstr(cmdstr, 0) == 1) {
            repaint();
            goto mfree;
        }
    }
    if(count == 0) {
        repaint();
        goto mfree;
    }
    switch(mode) {
        case U_INSERT:
            do_put(start, count, tempbuf);
            break;
        case U_EDIT:
            do_over(start, count, tempbuf);
            break;
        case U_APPEND:
            if((undo_count = alloc_buf(count, &undo_buf)) == 0L) {
                repaint();
                goto mfree;
            }
            do_append((off_t)count, tempbuf);
            memcpy(undo_buf, tempbuf, count);
            repaint();
            break;
    }
mfree:
#if defined(__MSDOS__) && !defined(DJGPP)
    farfree(tempbuf);
#else
    free(tempbuf);
#endif
}
Example #25
0
File: file.c Project: 50wu/gpdb
Datum
utl_file_put(PG_FUNCTION_ARGS)
{
	do_put(fcinfo);
	PG_RETURN_BOOL(true);
}
Example #26
0
static void
run_test (struct sockaddr_in *addr)
{
    CLIENT *clnt;
    char value_val1[] = "Hello, world.";
    char value_val2[] = "Goodbye, world.";
    bamboo_put_args put_args;
    bamboo_get_args get_args;
    bamboo_get_res  *get_result;
    int first;

    memset (&put_args, 0, sizeof (put_args));
    memset (&get_args, 0, sizeof (get_args));

    srand (1);

    clnt = connect_to_server (addr);
    do_null_call (clnt);

    // Do a first put.

    random_key (put_args.key, sizeof (put_args.key));
    put_args.value.bamboo_value_val = value_val1;
    put_args.value.bamboo_value_len = sizeof (value_val1);
    do_put (clnt, &put_args);

    // Check that the data's there.

    memcpy (get_args.key, put_args.key, sizeof (get_args.key));
    get_result = do_get (clnt, &get_args);

    if (get_result->values.values_len != 1) {
        printf ("Get failed: returned %d values.\n", 
                get_result->values.values_len);
        exit (1);
    }
    if (compare_values (&(get_result->values.values_val [0]),
             value_val1, sizeof (value_val1)) != 0) {
        printf ("Get failed: values don't match: %s vs %s\n", 
                value_val1,
                get_result->values.values_val [0].bamboo_value_val);
        exit (1);
    }
    printf ("Get successful.\n");

    // Do a second put with the same key.

    put_args.value.bamboo_value_val = value_val2;
    put_args.value.bamboo_value_len = sizeof (value_val2);
    do_put (clnt, &put_args);

    // Check that both values are there.

    get_result = do_get (clnt, &get_args); 
    if (get_result->values.values_len != 1) {
        printf ("Get failed: returned %d values.\n", 
                get_result->values.values_len);
        exit (1);
    }

    printf ("Get returned value %s.\n", 
            get_result->values.values_val [0].bamboo_value_val);

    if (compare_values (&(get_result->values.values_val [0]),
             value_val1, sizeof (value_val1)) == 0) {
        printf ("Get returned first value.\n");
        first = TRUE;
    }
    else if (compare_values (&(get_result->values.values_val [0]),
                    value_val2, sizeof (value_val2)) == 0) {
        printf ("Get second first value.\n");
        first = FALSE;
    }
    else {
        printf ("Get failed: returned neither value.\n");
        exit (1);
    }

    get_args.placemark.bamboo_placemark_val = 
        get_result->placemark.bamboo_placemark_val;
    get_args.placemark.bamboo_placemark_len = 
        get_result->placemark.bamboo_placemark_len;

    get_result = do_get (clnt, &get_args); 
    if (get_result->values.values_len != 1) {
        printf ("Get failed: returned %d values.\n", 
                get_result->values.values_len);
        exit (1);
    }

    printf ("Get returned value %s.\n", 
            get_result->values.values_val [0].bamboo_value_val);

    if (first) {
        if (compare_values (&(get_result->values.values_val [0]),
                value_val2, sizeof (value_val2)) != 0) {
        printf ("Get failed: second value doesn't match: %s vs %s\n", 
                value_val2,
                get_result->values.values_val [0].bamboo_value_val);
        exit (1);
        }
    }
    else if (compare_values (&(get_result->values.values_val [0]),
                value_val1, sizeof (value_val1)) != 0) {
        printf ("Get failed: second value doesn't match: %s vs %s\n", 
                value_val1,
                get_result->values.values_val [0].bamboo_value_val);
        exit (1);
    }

    printf ("Get successful.\n");

    // Do a put with a different key.

    random_key (put_args.key, sizeof (put_args.key));
    do_put (clnt, &put_args);

    // Check that the data's there.

    memcpy (get_args.key, put_args.key, sizeof (get_args.key));
    get_args.placemark.bamboo_placemark_val = NULL;
    get_args.placemark.bamboo_placemark_len = 0;
    get_result = do_get (clnt, &get_args);

    if (get_result->values.values_len != 1) {
        printf ("Get failed: returned %d values.\n", 
                get_result->values.values_len);
        exit (1);
    }
    if (compare_values (&(get_result->values.values_val [0]),
             value_val2, sizeof (value_val2)) != 0) {
        printf ("Get failed: values don't match: %s vs %s\n", 
                value_val2,
                get_result->values.values_val [0].bamboo_value_val);
        exit (1);
    }
    printf ("Get successful.\n");

    clnt_destroy (clnt);
}